N = gets.to_i
XYs = readlines.map{|l| x, y = l.split.map(&:to_i)}

es = XYs.each_with_object(Hash.new{|h, k| h[k] = []}){|(x, y), h| h[x] << -y; h[-y] << x}
vs = {}
ans = es.keys.inject(-N) do |s, k|
  cx, cy, q = 0, 0, [k]
  while !q.empty?
    v = q.pop
    next if vs[v]
    vs[v] = true
    v > 0 ? cx += 1 : cy += 1
    q += es[v]
  end
  s + cx*cy
end
puts ans