#abc218d. D - Rectangles

D - Rectangles

Score : 400400 points

问题描述

我们有 NN 个不同的点在二维平面上,编号为 1,2,,N1,2,\ldots,N。第 ii 个点 (1iN)(1 \leq i \leq N) 的坐标为 (xi,yi)(x_i,y_i)

有多少个矩形的顶点是给定的这些点,并且其边与 xx-轴或 yy-轴平行?

以上为通义千问 qwen-max 翻译,仅供参考。

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.

Sample Input 1

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

Sample Output 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.

Sample Input 2

4
0 1
1 2
2 3
3 4

Sample Output 2

0

Sample Input 3

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

Sample Output 3

1

update @ 2024/3/10 09:38:50