There are N dots in a two-dimensional plane. The coordinates of the i-th dot are (x_i, y_i).

We will repeat the following operation as long as possible:

* Choose four integers a, b, c, d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b), (a, d), (c, b) and (c, d), and add a dot at the remaining position.



We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.

Constraints

* 1 \leq N \leq 10^5
* 1 \leq x_i, y_i \leq 10^5
* If i \neq j, x_i \neq x_j or y_i \neq y_j.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N
x_1 y_1
:
x_N y_N


Output

Print the maximum number of times we can do the operation.

Examples

Input

3
1 1
5 1
5 5


Output

1


Input

2
10 10
20 20


Output

0


Input

9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5


Output

16
from collections import deque

N = int(input())

x_list = [0] * N
y_list = [0] * N

for i in range(N):
    x, y = map(int, input().split())
    x_list[i] = x + 1000000
    y_list[i] = y

# graph
G = dict()
for i in range(N):
    x = x_list[i]
    y = y_list[i]
    G[x] = dict()
    G[y] = dict()

for i in range(N):
    x = x_list[i]
    y = y_list[i]
    G[x][y] = 1
    G[y][x] = 1

x_su = list(set(x_list))
Lx = len(x_su)
x_su_ind = dict()
for i in range(Lx):
    x_su_ind[x_su[i]] = i

y_su = list(set(y_list))
Ly = len(y_su)
y_su_ind = dict()
for i in range(Ly):
    y_su_ind[y_su[i]] = i

done_x = [0]*Lx
done_y = [0]*Ly

res = 0

id_0 = 0
while True:
    while done_x[id_0] == 1:
        id_0 += 1
        if id_0 == Lx:
            break
    if id_0 == Lx:
        break
    # BFS
    cx = 1
    cy = 0
    queue = deque([x_su[id_0]])
    done_x[id_0] = 1
    while len(queue) > 0:
        p = queue.popleft()
        for q in G[p].keys():
            if q < 1000000:
                if done_y[y_su_ind[q]] == 0:
                    queue.append(q)
                    done_y[y_su_ind[q]] = 1
                    cy += 1
            else:
                if done_x[x_su_ind[q]] == 0:
                    queue.append(q)
                    done_x[x_su_ind[q]] = 1
                    cx += 1
    res += cx * cy

print(res - N)
