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 dfs(v)
    return if seen[v]
    seen[v] = true
    cnt[v/V] += 1
    to[v].each do |nv|
      dfs(nv)
    end
  end
end

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

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