#C13389. Counting Rectangles in a 2D Plane
Counting Rectangles in a 2D Plane
Counting Rectangles in a 2D Plane
You are given n points in a 2D plane. Your task is to count the number of distinct rectangles that can be formed such that each rectangle's four corners belong to the given points. In this problem, a rectangle is defined as a quadrilateral whose sides are parallel to the coordinate axes. That is, a rectangle is formed by the points \((x_1, y_1)\), \((x_1, y_2)\), \((x_2, y_1)\) and \((x_2, y_2)\) where \(x_1 \neq x_2\) and \(y_1 \neq y_2\).
Input is given via standard input (stdin) and output should be written to standard output (stdout).
Examples:
- If there are no points, the answer is 0.
- If there are only 3 points such as (0, 0), (1, 0) and (0, 1), no rectangle can be formed.
- If the points are (0, 0), (0, 1), (1, 0) and (1, 1), there is exactly 1 rectangle.
inputFormat
The first line of input contains an integer n representing the number of points.
The following n lines each contain two space-separated integers, representing the x and y coordinates of a point.
\(\textbf{Constraints}:\)
- \(0 \leq n \leq 10^5\)
- The coordinates will be integers and may be negative.
outputFormat
Output a single integer, representing the number of rectangles that can be formed using the given points.
## sample0
0
</p>