PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000118. Sereja và những hình vuông (Sereja and Squares)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Sereja và những hình vuông (Sereja and Squares)

Sereja and Squares

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Sereja has drawn nn distinct points in the plane, each with integer coordinates (xi,yi)(x_i,y_i).

Count the axis-aligned squares whose four vertices belong to the given point set. Each square must have positive side length and is counted exactly once, regardless of the order in which its vertices are listed.

Squares with rotated (non-axis-aligned) sides must not be counted.

Input

  • The first line contains the integer nn.
  • Each of the next nn lines contains the coordinates xi,yix_i,y_i of a point.
  • All points are distinct.

Output

Print one integer: the number of squares with sides parallel to the coordinate axes.

Subtasks

  • Subtask 1 (10 points): 1≤n≤1001\le n\le100; 0≤xi,yi≤1050\le x_i,y_i\le10^5; all points are distinct.

  • Subtask 2 (20 points): 1≤n≤3 0001\le n\le3\,000; 0≤xi,yi≤1050\le x_i,y_i\le10^5; all points are distinct.

  • Subtask 3 (30 points): 1≤n≤30 0001\le n\le30\,000; 0≤xi,yi≤1050\le x_i,y_i\le10^5; all points are distinct.

  • Subtask 4 (40 points): 1≤n≤1051\le n\le10^5; 0≤xi,yi≤1050\le x_i,y_i\le10^5; all points are distinct.

Examples

Example 1

Input

5
0 0
0 2
2 0
2 2
1 1

Output

1

Explanation

The four points (0,0),(0,2),(2,0),(2,2)(0,0),(0,2),(2,0),(2,2) form one square of side length 22. Point (1,1)(1,1) contributes no further axis-aligned square.

Example 2

Input

9
0 0
1 1
2 2
0 1
1 0
0 2
2 0
1 2
2 1

Output

5

Explanation

The full 3imes33 imes3 grid has four squares of side 1 and one square of side 2, totaling 5.