Tagy: triedenie
Obtiažnosť: hard

Queens

The Red Queen is having a huge party in Wonderland. The party takes place at an immensely large $10^9 \times 10^9$ chessboard, made specially for this occasion out of large ebony and ivory tiles. $N$ queens were invited to the party. They scattered all over the chessboard and started attacking each other. You are given the coordinates of each of the $N$ queens. Compute the number of pairs of queens that attack each other. Standard chess rules apply - a queen attacks cells in her row, column, and on both diagonals she occupies. In each of the 8 directions, the attacked cells are precisely the cells between the queen’s location and the first occupied cell in that direction, inclusive. (Or, if there is no other queen in some direction, all cells until the end of the board are attacked.)

Input

The first line of the input contains the integer $N \, (1 \leq N \leq 100\,000)$. Each of the next $N$ lines contains two integers $r_i, c_i \, (1 \leq ri, ci \leq 10^9)$ - the row and the column of one of the queens. No two queens share the same cell

Output

Output a single line with the number of attacking pairs.

Príklad

Vstup

Výstup

4
1 7
3 7
7 7
103 107
3

The attacking pairs are 1-2, 2-3, and 2-4. Note that queens 1 and 3 do not attack each other, as queen 2 is in the way.

Ak chceš riešiť túto úlohu, musíš sa najprv prihlásiť.