#K75197. Unique Axis-Aligned Right-Angled Triangles

    ID: 34366 Type: Default 1000ms 256MiB

Unique Axis-Aligned Right-Angled Triangles

Unique Axis-Aligned Right-Angled Triangles

You are given n points on a 2D plane. Your task is to count the number of unique right-angled triangles that can be formed such that all three vertices come from the given set of points and the two legs (sides forming the right angle) are parallel to the coordinate axes.

A triangle is right-angled if one of its angles is 90° and, in this problem, the sides adjacent to this angle must be aligned with the x-axis and y-axis respectively. For a given point \((x,y)\), if we define \(n_x(x)\) as the number of points sharing the same x-coordinate and \(n_y(y)\) as the number of points sharing the same y-coordinate, then the number of triangles having \((x,y)\) as the right angle vertex is given by:

[ (n_x(x)-1) \times (n_y(y)-1) ]

The final answer is the sum of the above value over all points.

inputFormat

The first line contains a single integer n, the number of points. Each of the following n lines contains two integers x and y, representing the coordinates of a point.

outputFormat

Output a single integer, the total number of unique right-angled triangles with legs parallel to the coordinate axes that can be formed from the given points.

## sample
4
1 2
2 2
2 3
3 3
2