if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  require 'rubygems';RUBY=Gem.ruby
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},RUBY,$0) #100MB
end

V = 100_005 # 頂点の最大数+a

n = gets.to_i
to = Array.new(V*2){ [] }
seen = Array.new(V*2, false)
cnt = Array.new(2,0)

n.times do
  x,y = gets.split.map(&:to_i)
  y += V
  to[x] << y
  to[y] << x
end

dfs = -> v do
  return if seen[v]
  seen[v] = true
  cnt[v/V] += 1
  to[v].each do |nv|
    dfs[nv]
  end
end

ans = 0
(V*2).times do |i|
  cnt.fill(0)
  dfs[i]
  ans += cnt[0] * cnt[1]
end
ans -= n
puts ans
