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 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap



@mt
def slv(N, XY):
    from collections import defaultdict
    g = defaultdict(set)
    yo = 10**6
    V = set()
    for x, y in XY:
        y += yo
        g[x].add(y)
        g[y].add(x)
        V.add(x)
        V.add(y)


    rem = set(v for v in V)
    done = set()
    ans = 0
    while rem:
        u = rem.pop()
        s = [u]
        done.add(u)
        xs = set()
        ys = set()
        if u >= yo:
            ys.add(u)
        else:
            xs.add(u)
        while s:
            u = s.pop()
            if u >= yo:
                ys.add(u)
            else:
                xs.add(u)
            for v in g[u]:
                if v in done:
                    continue
                s.append(v)
                done.add(v)
        rem -= xs
        rem -= ys
        e = 0
        for u in xs:
            e += len(g[u])
        ans += len(xs) * len(ys) - e

    return ans





def main():
    N = read_int()
    XY = [read_int_n() for _ in range(N)]
    print(slv(N, XY))


if __name__ == '__main__':
    main()
