#K95092. Counting Axis-Aligned Rectangles
Counting Axis-Aligned Rectangles
Counting Axis-Aligned Rectangles
Given a set of 2D integer points, your task is to determine the number of rectangles that can be formed with sides parallel to the coordinate axes. A rectangle is defined as a quadrilateral with vertices ((x_1, y_1)), ((x_1, y_2)), ((x_2, y_1)), and ((x_2, y_2)) such that (x_1 < x_2) and (y_1 < y_2). In other words, if the points ((x_1, y_1)) and ((x_2, y_2)) are chosen as diagonal vertices, then the points ((x_1, y_2)) and ((x_2, y_1)) must also exist in the input. Each rectangle should be counted exactly once.
inputFormat
The first line contains an integer (n) ( (1 \le n \le 10^5)) representing the number of points. The next (n) lines each contain two space-separated integers (x) and (y) ((-10^9 \le x, y \le 10^9)), representing the coordinates of a point.
outputFormat
Output a single integer denoting the number of axis-aligned rectangles that can be formed using these points as vertices.## sample
6
1 1
1 4
2 1
2 4
4 1
4 4
3