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
import sys
input = sys.stdin.readline

def find_root(root, size, x):
    y = root[x]
    if y is None:
        root[x] = x
        size[x] = 1
        return x
    if x == y:
        return y
    z = find_root(root, size, y)
    root[x] = z
    return z


def merge(root, size, cnt, x, y):
    rx = find_root(root, size, x)
    ry = find_root(root, size, y)
    if rx == ry:
        return
    sx = size[rx]
    sy = size[ry]
    if sx > sy:
        root[ry] = rx
        size[rx] += sy
        cnt[rx] += cnt[ry]
    else:
        root[rx] = ry
        size[ry] += sx
        cnt[ry] += cnt[rx]
    return


def main():
    N = int(input())
    U = 10 ** 5
    root_x = [None] * (U + 1)
    root_y = [None] * (U + 1)
    size_x = [0] * (U + 1)
    size_y = [0] * (U + 1)
    cnt_x = [0] * (U + 1)
    cnt_y = [0] * (U + 1)
    x_to_y = [None] * (U + 1)
    y_to_x = [None] * (U + 1)

    for _ in range(N):
        x, y = map(int, input().split())
        rx = find_root(root_x, size_x, x)
        ry = find_root(root_y, size_y, y)
        cnt_x[rx] += 1
        cnt_y[ry] += 1
        if x_to_y[rx] is None:
            x_to_y[rx] = ry
        if y_to_x[ry] is None:
            y_to_x[ry] = rx
        merge(root_y, size_y, cnt_y, x_to_y[rx], ry)
        merge(root_x, size_x, cnt_x, y_to_x[ry], rx)
        x_to_y[root_x[rx]] = root_y[ry]
        y_to_x[root_y[ry]] = root_x[rx]

    ans = 0
    for x in range(1, U + 1):
        if root_x[x] is None:
            continue
        rx = find_root(root_x, size_x, x)
        if x != rx:
            continue
        y = x_to_y[x]
        ry = find_root(root_y, size_y, y)
        sx = size_x[rx]
        sy = size_y[ry]
        cnt = cnt_x[rx]
        ans += sx * sy - cnt
    print(ans)


if __name__ == "__main__":
    main()
