import numpy as np

from scipy.sparse import *



U = 10**5

N = int(eval(input()))

XY = np.array([input().split() for _ in range(N)], dtype=np.int32)



graph = csr_matrix(([1]*N, (XY[:,0], U + XY[:,1])), (2*U+1, 2*U+1))

_, component = csgraph.connected_components(graph)



X_cnt = np.bincount(component[:U+1], minlength = 2*U+2)

Y_cnt = np.bincount(component[U+1:], minlength = 2*U+2)

pts_cnt = np.bincount(component[XY[:,0]], minlength = 2*U+2)

answer = (X_cnt * Y_cnt - pts_cnt).sum()

print(answer)

import numpy as np

from scipy.sparse import *

import sys

input = sys.stdin.readline



U = 10**5

N = int(eval(input()))

XY = np.array([input().split() for _ in range(N)], dtype=np.int32)



graph = csr_matrix((np.ones(N,dtype=np.bool), (XY[:,0], U + XY[:,1])), (2*U+1, 2*U+1))

_, component = csgraph.connected_components(graph)



X_cnt = np.bincount(component[:U+1], minlength = 2*U+2)

Y_cnt = np.bincount(component[U+1:], minlength = 2*U+2)

pts_cnt = np.bincount(component[XY[:,0]], minlength = 2*U+2)

answer = (X_cnt * Y_cnt - pts_cnt).sum()

print(answer)

import numpy as np
from scipy.sparse import *

U = 10**5
N = int(eval(input()))
XY = np.array([input().split() for _ in range(N)], dtype=np.int32)
graph = csr_matrix(([1] * N, (XY[:, 0], U + XY[:, 1])), (2 * U + 1, 2 * U + 1))
_, component = csgraph.connected_components(graph)
X_cnt = np.bincount(component[: U + 1], minlength=2 * U + 2)
Y_cnt = np.bincount(component[U + 1 :], minlength=2 * U + 2)
pts_cnt = np.bincount(component[XY[:, 0]], minlength=2 * U + 2)
answer = (X_cnt * Y_cnt - pts_cnt).sum()
print(answer)

import numpy as np
from scipy.sparse import *
import sys

input = sys.stdin.readline
U = 10**5
N = int(eval(input()))
XY = np.array([input().split() for _ in range(N)], dtype=np.int32)
graph = csr_matrix(
    (np.ones(N, dtype=np.bool), (XY[:, 0], U + XY[:, 1])), (2 * U + 1, 2 * U + 1)
)
_, component = csgraph.connected_components(graph)
X_cnt = np.bincount(component[: U + 1], minlength=2 * U + 2)
Y_cnt = np.bincount(component[U + 1 :], minlength=2 * U + 2)
pts_cnt = np.bincount(component[XY[:, 0]], minlength=2 * U + 2)
answer = (X_cnt * Y_cnt - pts_cnt).sum()
print(answer)

+import sys +input = sys.stdin.readline -graph = csr_matrix(([1] * N, (XY[:, 0], U + XY[:, 1])), (2 * U + 1, 2 * U + 1)) +graph = csr_matrix( +    (np.ones(N, dtype=np.bool), (XY[:, 0], U + XY[:, 1])), (2 * U + 1, 2 * U + 1) +)