Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/katetlari-parallel-uchburchaklar

Triangles with axis-parallel legs

Medium 1000 ms 128 MB 49%
Share

$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.)

Points on a grid; a triangle with the right angle at one of them and legs parallel to the axes

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

Sign in to submit a solution

Signing up is free and takes a minute.