#C10554. Counting Right-Angled Triangles with the Origin as the Right Angle

    ID: 39772 Type: Default 1000ms 256MiB

Counting Right-Angled Triangles with the Origin as the Right Angle

Counting Right-Angled Triangles with the Origin as the Right Angle

Given a set of points on the Cartesian plane, your task is to count the number of unique right-angled triangles that can be formed such that the right angle is at the origin ( (0,0) ). A triangle is considered valid only if one of its vertices (other than the origin) lies on the positive or negative x-axis (i.e. with ( y=0 ) and ( x\neq0 )) and another lies on the positive or negative y-axis (i.e. with ( x=0 ) and ( y\neq0 )). In other words, if we denote ( X ) as the number of valid points on the x-axis and ( Y ) as the number of valid points on the y-axis, then the total number of triangles is given by: [ \text{Triangles} = X \times Y ] Note that points located at the origin should be ignored. The input guarantees that the points are provided as integer coordinates.

inputFormat

The input is read from standard input. The first line contains an integer ( N ) representing the number of points. Each of the following ( N ) lines contains two integers representing the coordinates ( x ) and ( y ) of a point.

outputFormat

Output a single integer, which is the total number of right-angled triangles with the right angle at the origin that can be formed using the given points. The result is printed to standard output.## sample

5
1 0
0 1
2 0
0 2
1 1
4