CodeEff/ECCO huggingface dataset:
# Original solution
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
from collections import defaultdict

def main():
    N = II()
    xy = []
    for _ in range(N):
        xy.append(LI())
    xy2g = defaultdict(int)
    g2xy = defaultdict(set)
    for x, y in xy:
        y = -y
        gx = xy2g[x]
        gy = xy2g[y]
        if gx == 0 or gy == 0:
            g = gx or gy or x
            xy2g[x] = xy2g[y] = g
            g2xy[g] |= {x, y}
        elif gx != gy:  # merge
            if len(g2xy[gx]) < len(g2xy[gy]):
                gx, gy = gy, gx
            for xy in g2xy[gy]:
                xy2g[xy] = gx
            g2xy[gx] |= g2xy[gy]
            g2xy[gy].clear()
    ans = -N
    for xys in list(g2xy.values()):
        nx, ny = 0, 0
        for xy in xys:
            if xy > 0:
                nx += 1
            else:
                ny += 1
        ans += nx * ny
    return ans

print((main()))

# Optimized solution
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
from collections import defaultdict

def main():
    N = II()
    xy = []
    for _ in range(N):
        xy.append(LI())
    xy2g = defaultdict(int)
    g2xy = defaultdict(set)
    for x, y in xy:
        y = -y
        gx = xy2g[x]
        gy = xy2g[y]
        if gx != gy and gx != 0 and gy != 0:  # merge
            if len(g2xy[gx]) < len(g2xy[gy]):
                gx, gy = gy, gx
            for xy in g2xy[gy]:
                xy2g[xy] = gx
            g2xy[gx] |= g2xy[gy]
            g2xy[gy].clear()
        else:
            g = gx or gy or x
            xy2g[x] = xy2g[y] = g
            g2xy[g] |= {x, y}
    ans = -N
    for xys in list(g2xy.values()):
        nx = 0
        for xy in xys:
            if xy > 0:
                nx += 1
        ny = len(xys) - nx
        ans += nx * ny
    return ans

print((main()))
# Original solution
from bisect import bisect_left
from collections import defaultdict
N = int(eval(input()))
points = list(tuple(map(int,input().split())) for _ in range(N))

xty = defaultdict(list)
ytx = defaultdict(list)
for x,y in points:
    xty[x].append(y)
    ytx[y].append(x)

area = 0
X = set()
Y = set()

for x,y in points:
    if x in X or y in Y:
        continue

    stack_x = [x]
    stack_y = [y]

    dx = set()
    dy = set()

    while stack_x or stack_y:

        while stack_x:
            x = stack_x.pop()
            dx.add(x)
            for y in xty[x]:
                if y not in dy:
                    stack_y.append(y)

        while stack_y:
            y = stack_y.pop()
            dy.add(y)
            for x in ytx[y]:
                if x not in dx:
                    stack_x.append(x)
    X |= dx
    Y |= dy
    area += len(dx)*len(dy)

print((area-len(points)))

# Optimized solution
from bisect import bisect_left
from collections import defaultdict
N = int(eval(input()))
points = list(tuple(map(int,input().split())) for _ in range(N))

xty = defaultdict(list)
ytx = defaultdict(list)
for x,y in points:
    xty[x].append(y)
    ytx[y].append(x)

area = 0
X = set()
Y = set()

for x,y in points:
    if x in X or y in Y:
        continue

    stack_x = [x]
    stack_y = [y]

    dx = set()
    dy = set()

    while stack_x or stack_y:

        while stack_x:
            x = stack_x.pop()
            if x not in dx:
                dx.add(x)
                for y in xty[x]:
                    if y not in dy:
                        stack_y.append(y)

        while stack_y:
            y = stack_y.pop()
            if y not in dy:
                dy.add(y)
                for x in ytx[y]:
                    if x not in dx:
                        stack_x.append(x)
    X |= dx
    Y |= dy
    area += len(dx)*len(dy)

print((area-len(points)))
# Original solution
import sys
sys.setrecursionlimit(10**6)

def dfs(x, al):
    global cntx, cnty
    if (al, x) in used:
        return
    used.add((al, x))
    if al == 0:
        cntx += 1
    else:
        cnty += 1
    for xy in to[al][x]:
        dfs(xy, 1 - al)
    return

n = int(eval(input()))
to = [{}, {}]
for _ in range(n):
    x, y = list(map(int, input().split()))
    to[0].setdefault(x, [])
    to[1].setdefault(y, [])
    to[0][x] += [y]
    to[1][y] += [x]
used = set()
ans = 0
for x in list(to[0].keys()):
    if (0, x) in used: continue
    cntx = 0
    cnty = 0
    dfs(x, 0)
    ans += cntx * cnty
print((ans - n))


# Optimized solution
def get_group(x):
    g = group[x]
    if g == x:
        return x
    group[g] = re = get_group(g)
    return re

def unite(x, y):
    gx = get_group(x)
    gy = get_group(y)
    if gx != gy:
        dx = depth[gx]
        dy = depth[gy]
        if dy > dx:
            gx, gy = gy, gx
        group[gy] = gx
        if dx == dy:
            depth[gx] += 1

n = int(eval(input()))
group = {}
depth = {}
edge = []
for _ in range(n):
    x, y = list(map(int, input().split()))
    group.setdefault(x, x)
    group.setdefault(-y, -y)
    depth.setdefault(x, 1)
    depth.setdefault(-y, 1)
    edge += [[x, -y]]

for x, y in edge:
    unite(x, y)

cnt = {}
for k in list(group.keys()):
    g = get_group(k)
    cnt.setdefault(g, [0, 0])
    if k > 0:
        cnt[g][0] += 1
    else:
        cnt[g][1] += 1

ans = 0
for cx, cy in list(cnt.values()):
    ans += cx * cy
print((ans - n))
# Original solution
import sys
# DFSの再帰限界を増やす
sys.setrecursionlimit(10**6)

N = int(eval(input()))
nmax = 100001
# nmax = 10
# 第一成分にx,第二成分にyをぶち込んでいく。(二部グラフなので)
xys = [[[] for i in range(nmax)] for j in range(2)]

used = [[0 for i in range(nmax)] for j in range(2)]
# 読み込み
for _ in range(N):
    x, y = list(map(int, input().split()))
    xys[0][x].append(y)
    xys[1][y].append(x)
# print(xys)

# 座標の切り替えをx = 1 or 0と1-xで行うのか、うまい！
# よく考えたらtrue/falseをひっくり返しているだけか。
def dfs(i, el=0):
    # el=0->x, el=1->y
    for i in xys[el][i]:
        if not used[1-el][i]:
            used[1-el][i] = True
            dfs(i, 1-el)
            cnt[1-el] += 1

ans = 0
for i in range(nmax):
    # まだ行ったことがなくて空じゃないところ
    if xys[0][i] != [] and used[0][i] == 0:
        used[0][i] = 1
        cnt = [1,0]
        dfs(i,0)
        ans += cnt[0]*cnt[1]
print((ans-N))


# Optimized solution
from collections import deque

N = int(eval(input()))
nmax = 2*10**5
nhalf = 10**5

G = [[] for i in range(nmax)]
for i in range(N):
    x,y = list(map(int,input().split()))
    G[x-1].append(nhalf+y-1)
    G[nhalf+y-1].append(x-1)

used = [False] * nmax
ans = 0
# 全探索
for i in range(nhalf):
    # 見つかったノードからBFS
    if G[i] != [] and not used[i]:
        cnt_1 = 0  #前半の連結
        cnt_2 = 0  #後半の連結
        q = deque([i])
        used[i] = True # 始めどこから行くか
        while len(q) > 0:
            a = q.popleft()
            if a < nhalf:
                cnt_2 += 1
            else:
                cnt_1 += 1
            Vs = G[a]
            # print(Vs)
            for u in Vs: # 頂点以外の要素がグラフにあるときはここ
                if not used[u]:
                    q.append(u)
                    # なにか処理を書きたいときはここに書く
                    used[u] = True
        ans += cnt_1*cnt_2
print((ans-N))
# Original solution
class UnionFind:
    def __init__(self, n):
        self.v = [-1 for _ in range(n)]

    def find(self, x):
        if self.v[x] < 0:  # (負)は根
            return x
        else:
            self.v[x] = self.find(self.v[x])
            return self.v[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if -self.v[x] < -self.v[y]:
            x, y = y, x
        self.v[x] += self.v[y]
        self.v[y] = x

    def root(self, x):
        return self.v[x] < 0

    def size(self, x):
        return -self.v[self.find(x)]


mx = 10 ** 5 + 10

n = int(eval(input()))

uf = UnionFind(mx * 2)

for _ in range(n):
    x, y = list(map(int, input().split()))
    uf.unite(x, y + mx)

vx = [0] * (mx * 2)
vy = [0] * (mx * 2)

for i in range(mx):
    root = uf.find(i)
    vx[root] += 1

for i in range(mx, mx * 2):
    root = uf.find(i)
    vy[root] += 1

ans = -n
for xx, yy in zip(vx, vy):
    ans += xx * yy
print(ans)


# Optimized solution
# https://drken1215.hatenablog.com/entry/2019/06/23/004700
# https://tjkendev.github.io/procon-library/python/union_find/union_find.html

def main():
    import sys
    input = sys.stdin.readline

    MX = 10 ** 5 + 10
    
    *p, = [r for r in range(MX * 2)]

    def root(x):
        if x == p[x]:
            return x
        p[x] = y = root(p[x])
        return y

    def unite(x, y):
        px = root(x)
        py = root(y)
        if px == py:
            return 0
        if px < py:
            p[py] = px
        else:
            p[px] = py
        return 1

    n = int(eval(input()))
    for _ in range(n):
        x, y = (int(x) - 1 for x in input().split())  # [1,)->[0,)
        unite(x, y + MX)

    xs = [0] * (MX * 2)
    ys = [0] * (MX * 2)

    for r in range(MX):
        xs[root(r)] += 1

    for r in range(MX, MX * 2):
        ys[root(r)] += 1

    ans = -n
    for r in range(MX * 2):
        ans += xs[r] * ys[r]

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
def main():
    from collections import deque
    import sys
    input = sys.stdin.readline

    M = 10 ** 5

    N = int(eval(input()))

    g = tuple(set() for _ in range(M * 2))
    for _ in range(N):
        x, y = (int(x) - 1 for x in input().split())  # 一律に移動
        g[x].add(y + M)
        g[y + M].add(x)

    visited = [0] * (M * 2)
    ans = 0
    for s in range(M * 2):
        if visited[s]: continue
        visited[s] = 1
        dq = deque()
        dq.append(s)

        sz = 0
        x = 0
        e = 0
        while dq:
            v = dq.popleft()
            sz += 1
            if v < M:
                x += 1
            for u in g[v]:
                e += 1
                if visited[u]: continue
                visited[u] = 1
                dq.append(u)
        ans += (sz - x) * x - (e // 2)
        # ans += (sz - x) * x - (sz - 1) # sz-1は木に限られるのでWA

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    from collections import deque
    import sys
    input = sys.stdin.readline

    M = 10 ** 5

    N = int(eval(input()))

    g = tuple(set() for _ in range(M * 2))
    for _ in range(N):
        x, y = (int(x) - 1 for x in input().split())  # 一律に移動
        g[x].add(y + M)
        g[y + M].add(x)

    visited = [0] * (M * 2)
    ans = 0
    for s in range(M * 2):  # xとy+Mのsetの方が確認する数は減る?
        if visited[s]: continue
        visited[s] = 1
        dq = deque()
        dq.append(s)

        sz = 0
        x = 0
        while dq:
            v = dq.popleft()
            sz += 1
            if v < M:
                x += 1
            for u in g[v]:
                if visited[u]: continue
                visited[u] = 1
                dq.append(u)
        ans += (sz - x) * x

    ans -= N

    print(ans)


if __name__ == '__main__':
    main()

# 連結成分ごとに
# x,yの二部グラフを完全二部グラフにする
# cnt(x)*cnt(y)-既存の辺数の総和

# 最後にN引けばよい
# Original solution
def main():
    from collections import deque
    import sys
    input = sys.stdin.readline

    M = 10 ** 5

    N = int(eval(input()))

    g = tuple(set() for _ in range(M * 2))
    for _ in range(N):
        x, y = (int(x) - 1 for x in input().split())  # 一律に移動
        g[x].add(y + M)
        g[y + M].add(x)

    visited = [0] * (M * 2)
    ans = 0
    for s in range(M * 2):  # xとy+Mのsetの方が確認する数は減る?
        if visited[s]: continue
        visited[s] = 1
        dq = deque()
        dq.append(s)

        sz = 0
        x = 0
        while dq:
            v = dq.popleft()
            sz += 1
            if v < M:
                x += 1
            for u in g[v]:
                if visited[u]: continue
                visited[u] = 1
                dq.append(u)
        ans += (sz - x) * x

    ans -= N

    print(ans)


if __name__ == '__main__':
    main()

# 連結成分ごとに
# x,yの二部グラフを完全二部グラフにする
# cnt(x)*cnt(y)-既存の辺数の総和

# 最後にN引けばよい


# Optimized solution
def main():
    from collections import deque
    import sys
    input = sys.stdin.readline

    M = 10 ** 5

    N = int(eval(input()))

    g = tuple(set() for _ in range(M * 2))
    ps = set()
    for _ in range(N):
        x, y = (int(x) - 1 for x in input().split())  # 一律に移動
        g[x].add(y + M)
        g[y + M].add(x)
        ps.add(x)
        ps.add(y + M)

    visited = [0] * (M * 2)
    ans = 0
    for s in ps:
        if visited[s]: continue
        visited[s] = 1
        dq = deque()
        dq.append(s)

        sz = 0
        x = 0
        while dq:
            v = dq.popleft()
            sz += 1
            if v < M:
                x += 1
            for u in g[v]:
                if visited[u]: continue
                visited[u] = 1
                dq.append(u)
        ans += (sz - x) * x

    ans -= N

    print(ans)


if __name__ == '__main__':
    main()

# 連結成分ごとに
# x,yの二部グラフを完全二部グラフにする
# cnt(x)*cnt(y)-既存の辺数の総和

# 最後にN引けばよい
# Original solution
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N = ri()
to = defaultdict(list)
V = 100005
X = []
for i in range(N):
	x, y = rl()
	X.append(x)
	y += V
	to[x].append(y)
	to[y].append(x)

visited = set()
nx, ny = 0, 0
def dfs(n):
	global nx, ny
	if n in visited: return
	visited.add(n)
	if n < V:
		nx += 1
	else:
		ny += 1
	for m in to[n]:
		dfs(m)

ans = 0
for x in X:
	if x in visited: continue
	nx, ny = 0, 0
	dfs(x)
	ans += nx*ny
print((ans-N))



# Optimized solution
import sys, math
from collections import defaultdict, deque, Counter
# from bisect import bisect_left, bisect_right
# from itertools import combinations, permutations, product
# from heapq import heappush, heappop
# from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N = ri()
to = defaultdict(list)
V = 100005
X = []
for i in range(N):
	x, y = rl()
	X.append(x)
	y += V
	to[x].append(y)
	to[y].append(x)

ans = 0
visited = {}
for x in X:
	if x in visited: continue
	nx, ny = 0, 0
	queue = deque()
	queue.append(x)
	visited[x] = 1
	while queue:
		n = queue.pop()
		if n < V:
			nx += 1
		else:
			ny += 1
		for m in to[n]:
			if m in visited:
				continue
			visited[m] = 1
			queue.append(m)
	ans += nx*ny
print((ans-N))
# Original solution
from collections import Counter

class UnionFind:
    def __init__(self, size):
        self.data = [-1] * size

    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)

    def same(self, x, y):
        return (self.find(x) == self.find(y))

    def size(self, x):
        return -self.data[self.find(x)]


MAX = 10 ** 5 + 10
uf = UnionFind(2 * MAX)

N, *XY = list(map(int, open(0).read().split()))

for x, y in zip(*[iter(XY)] * 2):
    uf.union(x, y + MAX)

X = Counter(uf.find(i) for i in range(MAX))
Y = Counter(uf.find(i) for i in range(MAX, MAX * 2))
res = sum(X[i] * Y[i] for i in range(MAX * 2))

print((res - N))


# Optimized solution
from collections import Counter


class UnionFind:
    def __init__(self, size):
        self.data = [-1] * size

    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)

    def same(self, x, y):
        return (self.find(x) == self.find(y))

    def size(self, x):
        return -self.data[self.find(x)]


def main():
    MAX = 10 ** 5 + 1
    uf = UnionFind(2 * MAX)

    N, *XY = list(map(int, open(0).read().split()))

    for x, y in zip(*[iter(XY)] * 2):
        uf.union(x, y + MAX)

    X = Counter(uf.find(i) for i in range(MAX))
    Y = Counter(uf.find(i) for i in range(MAX, MAX * 2))
    res = sum(X[i] * Y[i] for i in range(MAX * 2))

    print((res - N))


if __name__ == '__main__':
    main()
# Original solution
from collections import Counter


def main():
    class UnionFind:
        def __init__(self, size):
            self.data = [-1] * size

        def find(self, x):
            if self.data[x] < 0:
                return x
            else:
                self.data[x] = self.find(self.data[x])
                return self.data[x]

        def union(self, x, y):
            x, y = self.find(x), self.find(y)
            if x != y:
                if self.data[y] < self.data[x]:
                    x, y = y, x
                self.data[x] += self.data[y]
                self.data[y] = x
            return (x != y)

    MAX = 10 ** 5 + 1
    uf = UnionFind(2 * MAX)

    N, *XY = list(map(int, open(0).read().split()))

    for x, y in zip(*[iter(XY)] * 2):
        uf.union(x, y + MAX)

    X = Counter(uf.find(i) for i in range(MAX))
    Y = Counter(uf.find(i) for i in range(MAX, MAX * 2))
    res = sum(X[i] * Y[i] for i in range(MAX * 2))

    print((res - N))


if __name__ == '__main__':
    main()


# Optimized solution
from collections import Counter


def main():
    MAX = 10 ** 5 + 1

    data = [-1] * (2 * MAX)

    def find(x):
        if data[x] < 0:
            return x
        else:
            data[x] = find(data[x])
            return data[x]

    def union(x, y):
        x, y = find(x), find(y)
        if x != y:
            if data[y] < data[x]:
                x, y = y, x
            data[x] += data[y]
            data[y] = x
        return (x != y)


    N, *XY = list(map(int, open(0).read().split()))

    for x, y in zip(*[iter(XY)] * 2):
        union(x, y + MAX)

    X = Counter(find(i) for i in range(MAX))
    Y = Counter(find(i) for i in range(MAX, MAX * 2))
    res = sum(X[i] * Y[i] for i in range(MAX * 2))

    print((res - N))


if __name__ == '__main__':
    main()
# Original solution
from collections import Counter


def main():
    MAX = 10 ** 5 + 1

    data = [-1] * (2 * MAX)

    def find(x):
        if data[x] < 0:
            return x
        else:
            data[x] = find(data[x])
            return data[x]

    def union(x, y):
        x, y = find(x), find(y)
        if x != y:
            if data[y] < data[x]:
                x, y = y, x
            data[x] += data[y]
            data[y] = x
        return (x != y)


    N, *XY = list(map(int, open(0).read().split()))

    for x, y in zip(*[iter(XY)] * 2):
        union(x, y + MAX)

    X = Counter(find(i) for i in range(MAX))
    Y = Counter(find(i) for i in range(MAX, MAX * 2))
    res = sum(X[i] * Y[i] for i in range(MAX * 2))

    print((res - N))


if __name__ == '__main__':
    main()

# Optimized solution
def main():
    MAX = 10 ** 5 + 1

    data = [-1] * (2 * MAX)

    def find(x):
        if data[x] < 0:
            return x
        else:
            data[x] = find(data[x])
            return data[x]

    def union(x, y):
        x, y = find(x), find(y)
        if x != y:
            if data[y] < data[x]:
                x, y = y, x
            data[x] += data[y]
            data[y] = x
        return (x != y)


    N, *XY = list(map(int, open(0).read().split()))

    for x, y in zip(*[iter(XY)] * 2):
        union(x, y + MAX)

    X = [0] * (MAX * 2)
    Y = [0] * (MAX * 2)

    for i in range(MAX):
        X[find(i)] += 1
    for i in range(MAX, MAX * 2):
        Y[find(i)] += 1

    res = sum(X[i] * Y[i] for i in range(MAX * 2))

    print((res - N))


if __name__ == '__main__':
    main()
# Original solution
import sys
input = sys.stdin.readline

N = int(eval(input()))
XY = [list(map(int, input().split())) for _ in range(N)]

MAX = 10**5
Xs = [[] for _ in range(MAX+1)]
Ys = [[] for _ in range(MAX+1)]
for i, (x, y) in enumerate(XY):
    Xs[x].append(i)
    Ys[y].append(i)

ans = 0
checked = [False]*N
for i in range(N):
    if checked[i]: continue
    q = [i]
    checked[i] = True
    X = set()
    Y = set()
    c = 0
    while q:
        qq = []
        for p in q:
            x, y = XY[p]
            X.add(x)
            Y.add(y)
            c += 1
            for ni in Xs[x]:
                if not checked[ni]:
                    checked[ni] = True
                    qq.append(ni)
            for ni in Ys[y]:
                if not checked[ni]:
                    checked[ni] = True
                    qq.append(ni)
        q = qq
    ans += len(X)*len(Y)-c

print(ans)

# Optimized solution
import sys
input = sys.stdin.readline


def main():
    N = int(eval(input()))
    XY = [list(map(int, input().split())) for _ in range(N)]

    MAX = 10**5
    Xs = [[] for _ in range(MAX+1)]
    Ys = [[] for _ in range(MAX+1)]
    for i, (x, y) in enumerate(XY):
        Xs[x].append(i)
        Ys[y].append(i)

    ans = 0
    checked = [False]*N
    for i in range(N):
        if checked[i]: continue
        q = [i]
        checked[i] = True
        X = set()
        Y = set()
        c = 0
        while q:
            qq = []
            for p in q:
                x, y = XY[p]
                X.add(x)
                Y.add(y)
                c += 1
                for ni in Xs[x]:
                    if not checked[ni]:
                        checked[ni] = True
                        qq.append(ni)
                for ni in Ys[y]:
                    if not checked[ni]:
                        checked[ni] = True
                        qq.append(ni)
            q = qq
        ans += len(X)*len(Y)-c

    print(ans)


if __name__ == "__main__":
    main()