N = gets.to_i
X, Y = N.times.map{gets.split.map(&:to_i)}.transpose

MX = 100001
edges = Array.new(2*MX){[]}
N.times do |i|
    edges[X[i]].push(Y[i]+MX)
    edges[Y[i]+MX].push(X[i])
end

ans = -N
visited = []
(2*MX).times do |i|
    que = [i]
    cnt = [0, 0]
    while que.size > 0
        x = que.pop
        next if visited[x]
        visited[x] = true
        cnt[x/MX] += 1
        que.concat(edges[x])
    end
    ans += cnt[0]*cnt[1]
end
puts ans