output_description: Print the maximum number of times we can do the operation.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      x_1 y_1
      :
      x_N y_N
attempt: class UnionFind:
      def __init__(self, size):
          self.parent = list(range(size))
          self.height = [0] * size
          self.size = [1] * size
          self.component = size
  
      def root(self, index):
          if self.parent[index] == index:  # 根の場合
              return index
          rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
          self.parent[index] = rootIndex  # 親の付け直し
          return rootIndex
  
      def union(self, index1, index2):  # 結合
          root1 = self.root(index1)
          root2 = self.root(index2)
  
          if root1 == root2:  # 連結されている場合
              return
  
          self.component -= 1  # 連結成分を減らす
  
          if self.height[root1] < self.height[root2]:
              self.parent[root1] = root2  # root2に結合
              self.size[root2] += self.size[root1]
          else:
              self.parent[root2] = root1  # root1に結合
              self.size[root1] += self.size[root2]
              if self.height[root1] == self.height[root2]:
                  self.height[root1] += 1
          return
  
      def isSameRoot(self, index1, index2):
          return self.root(index1) == self.root(index2)
  
      def sizeOfSameRoot(self, index):
          return self.size[self.root(index)]
  
      def getComponent(self):
          return self.component
  
  
  N = int(input())
  R = 10**5 + 10
  IXY = []
  
  for i in range(N):
      x, y = map(int, input().split())
      IXY.append((i, x, y))
  
  X = [[] for _ in range(R)]
  Y = [[] for _ in range(R)]
  for i, x, y in IXY:
      X[x].append(i)
      Y[y].append(i)
  
  tree = UnionFind(N)
  
  for x in X:
      for fr, to in zip(x, x[1:]):
          tree.union(fr, to)
  for y in Y:
      for fr, to in zip(y, y[1:]):
          tree.union(fr, to)
  
  G = [[0, set(), set()] for _ in range(N)]
  for i, x, y in IXY:
      r = tree.root(i)
      G[r][0] += 1
      G[r][1].add(x)
      G[r][2].add(y)
  
  ans = 0
  for grp in G:
      if grp[0] < 3:
          continue
      x = len(grp[1])
      y = len(grp[2])
      A = x * y
      ans += max(0, A - grp[0])
  print(ans)
  
problem_description: Statement
  
  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.
samples: [{"input": "3\n    1 1\n    5 1\n    5 5", "output": "1\n    \n\nBy choosing a = 1, b = 1, c = 5, d = 5, we can add a dot at (1, 5). We cannot\ndo the operation any more, so the maximum number of operations is 1.\n\n* * *"}, {"input": "2\n    10 10\n    20 20", "output": "0\n    \n\nThere are only two dots, so we cannot do the operation at all.\n\n* * *"}, {"input": "9\n    1 1\n    2 1\n    3 1\n    4 1\n    5 1\n    1 2\n    1 3\n    1 4\n    1 5", "output": "16\n    \n\nWe can do the operation for all choices of the form a = 1, b = 1, c = i, d = j\n(2 \\leq i,j \\leq 5), and no more. Thus, the maximum number of operations is\n16."}]