Geometry
Geometry-09
Geometry-10
Geometry-11
~/algor $ cat problems/katetlari-parallel-uchburchaklar
Triangles with axis-parallel legs
Medium
1000 ms
128 MB
49%
$n$ distinct points are given on the plane. How many right triangles with vertices at these points have legs parallel to the coordinate axes? (A triangle is defined by the set of its vertices.)
Input
The first line contains a positive integer $n$. Each of the next $n$ lines contains two integers: $x_{i}$ and $y_{i}$.
Output
One integer — the number of triangles.
Note
$1 \le n \le 10^{5}$
$-10^{9} \le x_{i}, y_{i} \le 10^{9}$
all points are distinct
Examples
Input #1
5 0 0 0 3 2 0 2 3 5 3
Output #1
6
Input #2
3 0 0 1 1 2 2
Output #2
0