P25340 [AtCoder] Peace Agreement
提高+
题目描述

Problem Description

In Takahashi World, there are N countries. Currently, all countries are hostile to each other, creating a tense atmosphere. Therefore, the leaders of each country decided to negotiate and establish peace agreements between some countries.

Each country has two parameters: area and population. The area of the i-th country is $A_i$, and the population is $B_i$. For any two countries $x$ and $y$, the product of the difference in area and the difference in population, i.e., $(A_x - A_y) \times (B_x - B_y)$, is defined as the "difference in scale". Note that this value can be negative.

Peace agreements are made between two countries. However, if the difference in scale is too large or too small, the relationship may not work out well. Therefore, agreements are only made between countries with a moderate difference in scale. That is, only when the "difference in scale" is between $S1$ and $S2$ (inclusive) can the two countries establish an agreement. If all possible pairs of countries that can establish agreements actually do so, find the number of agreements that will be made.

Note that there are no two countries with exactly the same area and population.

Input Format

The input is given from the standard input in the following format:

$ N $ $ S1 $ $ S2 $ $ A_1 $ $ B_1 $ $ A_2 $ $ B_2 $ : $ A_N $ $ B_N $

  • The first line contains the number of countries in Takahashi World $N(1 \leq N \leq 50,000)$, the lower and upper limits of the "difference in scale" for establishing agreements $S1, S2(1 \leq S1 \leq S2 \leq 50,000)$, separated by spaces.
  • The next $ N $ lines contain the area $A_i(1 \leq A_i \leq 50,000)$ and population $B_i(1 \leq B_i \leq 50,000)$ of the i-th country, separated by spaces.
  • For $i \neq j$, at least one of $A_i \neq A_j$ and $B_i \neq B_j$ holds.

Output Format

Output the number of agreements that can be made if all possible countries establish agreements, on one line. End the output with a newline.

Sample Input and Output

Sample Input #1

3 1 5
1 1
2 2
4 4

Sample Output #1

2

Sample Input #2

4 1 100
1 1
1 2
2 1
2 2

Sample Output #2

1

Sample Input #3

16 3 14
3 1
4 1
5 9
2 6
5 3
5 8
9 7
9 3
2 3
8 4
6 2
6 4
3 3
8 3
2 7
9 5

Sample Output #3

34

Notes/Hints

Partial Points

This problem has partial points.

  • If you solve the dataset where $1 \leq N \leq 3,000, 1 \leq S1 \leq S2 \leq 3,000, 1 \leq A_i, B_i \leq 3,000$, you will get 10 points.
  • If you solve the dataset where $1 \leq N \leq 50,000, 1 \leq S1 \leq S2 \leq 50,000, 1 \leq A_i, B_i \leq 50,000$, you will get an additional 90 points, totaling 100 points.

Sample Explanation 1

The countries 1 and 2, or 2 and 3 can establish agreements, but countries 1 and 3 cannot because the difference in scale is 9, exceeding the upper limit.

Sample Explanation 2

Only countries 1 and 4 can establish an agreement. Note that the difference in scale for countries 2 and 3 is negative.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 1 5 1 1 2 2 4 4
样例输出
2