X = 0; Y = 10 ** 5
N = gets.to_i
G = Hash.new{|h,k| h[k] = [] }
USED = {}

N.times do
  x,y = gets.split.map(&:to_i)
  G[X + x] << Y + y
  G[Y + y] << X + x
end

def bigraph_edge_count(u)
  return 0 if USED[u]

  ys = 0
  xs = 0

  q = [u]
  USED[u] = u
  
  until q.empty?
    v = q.shift
    if v > Y
      ys += 1
    else
      xs += 1
    end
    G[v].reject{|w| USED[w] }.each do |w| 
      USED[w] = u
      q << w
    end
  end
  
  ys * xs
end

puts G.keys.inject(0){|s, u| s + bigraph_edge_count(u) } - N
