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: # -*- 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()
  
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."}]