import sys



input = sys.stdin.readline

sys.setrecursionlimit(200010)

n = int(eval(input()))

info = [list(map(int, input().split())) for i in range(n)]



v = 100000

graph = [[] for i in range(v*2)]

for i in range(n):

    x = info[i][0] - 1

    y = (info[i][1] - 1) + v

    graph[x].append(y)

    graph[y].append(x)



def dfs(pos):

    if visited[pos]:

        return

    visited[pos] = True

    cnt[pos//v] += 1

    for i in graph[pos]:

        dfs(i)

    return



visited = [False] * (v*2)

cnt = [0]*2

ans = 0

for i in range(v*2):

    cnt[0] = 0

    cnt[1] = 0

    dfs(i)

    ans += cnt[0]*cnt[1]

print((ans - n))





def dfs(v):

    cnt = [0, 0]

    if v < OFFSET:

        cnt[0] += 1

    else:

        cnt[1] += 1

    visited[v] = True

    stack = [v]

    while stack:

        v = stack.pop()

        for nxt_v in graph[v]:

            if visited[nxt_v]:

                continue

            if nxt_v < OFFSET:

                cnt[0] += 1

            else:

                cnt[1] += 1

            visited[nxt_v] = True

            stack.append(nxt_v)

    return cnt[0] * cnt[1]



n = int(eval(input()))

info = [list(map(int, input().split())) for i in range(n)]

OFFSET = 10 ** 5



graph = [[] for i in range(2 * OFFSET)]

for x, y in info:

    x -= 1

    y -= 1

    y += OFFSET

    graph[x].append(y)

    graph[y].append(x)



ans = 0

visited = [False] * (2 * OFFSET)

for v in range(2 * OFFSET):

    if visited[v]:

        continue

    else:

        ans += dfs(v)

print((ans - n))
import sys

input = sys.stdin.readline
sys.setrecursionlimit(200010)
n = int(eval(input()))
info = [list(map(int, input().split())) for i in range(n)]
v = 100000
graph = [[] for i in range(v * 2)]
for i in range(n):
    x = info[i][0] - 1
    y = (info[i][1] - 1) + v
    graph[x].append(y)
    graph[y].append(x)


def dfs(pos):
    if visited[pos]:
        return
    visited[pos] = True
    cnt[pos // v] += 1
    for i in graph[pos]:
        dfs(i)
    return


visited = [False] * (v * 2)
cnt = [0] * 2
ans = 0
for i in range(v * 2):
    cnt[0] = 0
    cnt[1] = 0
    dfs(i)
    ans += cnt[0] * cnt[1]
print((ans - n))

def dfs(v):
    cnt = [0, 0]
    if v < OFFSET:
        cnt[0] += 1
    else:
        cnt[1] += 1
    visited[v] = True
    stack = [v]
    while stack:
        v = stack.pop()
        for nxt_v in graph[v]:
            if visited[nxt_v]:
                continue
            if nxt_v < OFFSET:
                cnt[0] += 1
            else:
                cnt[1] += 1
            visited[nxt_v] = True
            stack.append(nxt_v)
    return cnt[0] * cnt[1]


n = int(eval(input()))
info = [list(map(int, input().split())) for i in range(n)]
OFFSET = 10**5
graph = [[] for i in range(2 * OFFSET)]
for x, y in info:
    x -= 1
    y -= 1
    y += OFFSET
    graph[x].append(y)
    graph[y].append(x)
ans = 0
visited = [False] * (2 * OFFSET)
for v in range(2 * OFFSET):
    if visited[v]:
        continue
    else:
        ans += dfs(v)
print((ans - n))

-import sys +def dfs(v): +    cnt = [0, 0] +    if v < OFFSET: +        cnt[0] += 1 +    else: +        cnt[1] += 1 +    visited[v] = True +    stack = [v] +    while stack: +        v = stack.pop() +        for nxt_v in graph[v]: +            if visited[nxt_v]: +                continue +            if nxt_v < OFFSET: +                cnt[0] += 1 +            else: +                cnt[1] += 1 +            visited[nxt_v] = True +            stack.append(nxt_v) +    return cnt[0] * cnt[1] -input = sys.stdin.readline -sys.setrecursionlimit(200010) + -v = 100000 -graph = [[] for i in range(v * 2)] -for i in range(n): -    x = info[i][0] - 1 -    y = (info[i][1] - 1) + v +OFFSET = 10**5 +graph = [[] for i in range(2 * OFFSET)] +for x, y in info: +    x -= 1 +    y -= 1 +    y += OFFSET - - -def dfs(pos): -    if visited[pos]: -        return -    visited[pos] = True -    cnt[pos // v] += 1 -    for i in graph[pos]: -        dfs(i) -    return - - -visited = [False] * (v * 2) -cnt = [0] * 2 -for i in range(v * 2): -    cnt[0] = 0 -    cnt[1] = 0 -    dfs(i) -    ans += cnt[0] * cnt[1] +visited = [False] * (2 * OFFSET) +for v in range(2 * OFFSET): +    if visited[v]: +        continue +    else: +        ans += dfs(v)