require 'set'

N = gets.to_i
X = Hash.new{|h, k| h[k] = []}
Y = Hash.new{|h, k| h[k] = []}
N.times{
  x, y = gets.chomp.split(" ").map(&:to_i)
  X[x] << y
  Y[y] << x
}

sx = Set.new
sy = Set.new
qx = []
qy = []
ans = -N
X.each{|k, v|
  next if sx.include?(k)
  qx << k
  wkx, wky = [sx.size, sy.size]
  until(qx.empty? && qy.empty?) do
    until qx.empty? do
      x = qx.shift
      X[x].each{|y|
        (sy.add(y); qy.push(y)) if !sy.include?(y)
      }
    end
    until qy.empty? do
      y = qy.shift
      Y[y].each{|x|
        (sx.add(x); qx.push(x)) if !sx.include?(x)
      }
    end
  end
  ans += (sx.size - wkx) * (sy.size - wky)
}

puts ans
