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
# coding: utf-8
# Your code here!

class UnionFind:
    def __init__(self, n,xy):
        self.parent = list(range(n))#親ノード
        self.size = [1]*n #グループの要素数
        self.xval = [{x} for x,y in xy]
        self.yval = [{y} for x,y in xy]

    def root(self, x): #root(x): xの根ノードを返す．
        while self.parent[x] != x:
            x, self.parent[x] = self.parent[x], self.parent[self.parent[x]]
        return x 
 
    def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x, y = self.root(x), self.root(y)
        if x == y:
            return False
        if self.size[x] < self.size[y]: 
            self.size[y] += self.size[x] #yの要素数を更新
            self.parent[x] = y #xをyにつなぐ
            self.xval[y].update(self.xval[x])
            self.yval[y].update(self.yval[x])
        else:
            self.size[x] += self.size[y] #xの要素数を更新
            self.parent[y] = x #yをxにつなぐ
            self.xval[x].update(self.xval[y])
            self.yval[x].update(self.yval[y])
        return True
 
    def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)
        
    def size(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]

n = int(input())
xy = [[int(i) for i in input().split()] for j in range(n)] 

UF = UnionFind(n,xy)

xval = dict()
yval = dict()
for i,(x,y) in enumerate(xy):
    if y in yval:
        UF.merge(i,yval[y])
    else:
        yval[y] = i

    if x in xval:
        UF.merge(i,xval[x])
    else:
        xval[x] = i

ans = -n
for i,pi in enumerate(UF.parent):
    if i==pi:
        ans += len(UF.xval[pi]) * len(UF.yval[pi])

#print(xval,yval)

print(ans)




