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 # 頂点の最大数
 
class Graph
  attr_accessor :to, :seen, :cnt
 
  def initialize
    @to = Array.new(V*2){ [] }
    @seen = Array.new(V*2, false)
    @cnt = Array.new(2,0)
  end

  def add(x,y)
    y += V
    to[x] << y
    to[y] << x
  end

  def count(i)
    cnt.fill(0)
    dfs(i)
    cnt.first * cnt.last
  end
 
  def dfs(v)
    return if seen[v]
    seen[v] = true
    cnt[v/V] += 1
    to[v].each do |nv|
      dfs(nv)
    end
  end
end

# init
n = gets.to_i
g = Graph.new
n.times do
  x,y = gets.split.map(&:to_i)
  g.add(x,y)
end

# main
ans = 0
(V*2).times do |i|
  ans += g.count(i)
end
ans -= n
puts ans