atcoder#ABC218D. [ABC218D] Rectangles

[ABC218D] Rectangles

Score : 400400 points

Problem Statement

We have NN distinct points on a two-dimensional plane, numbered 1,2,,N1,2,\ldots,N. Point ii (1iN)(1 \leq i \leq N) has the coordinates (xi,yi)(x_i,y_i).

How many rectangles are there whose vertices are among the given points and whose edges are parallel to the xx- or yy-axis?

Constraints

  • 4N20004 \leq N \leq 2000
  • 0xi,yi1090 \leq x_i, y_i \leq 10^9
  • (xi,yi)(xj,yj)(x_i,y_i) \neq (x_j,y_j) (ij)(i \neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

x1x_1 y1y_1

x2x_2 y2y_2

\vdots

xNx_N yNy_N

Output

Print the answer.

6
0 0
0 1
1 0
1 1
2 0
2 1
3

There are three such rectangles:

the rectangle whose vertices are Points 11, 22, 33, 44,

the rectangle whose vertices are Points 11, 22, 55, 66,

and the rectangle whose vertices are Points 33, 44, 55, 66.

4
0 1
1 2
2 3
3 4
0
7
0 1
1 0
2 0
2 1
2 2
3 0
3 2
1