N = gets.to_i
Xs, Ys = readlines.map{|l| l.split.map(&:to_i)}.transpose

@p = Array.new(N + 1, -1)

def root(x)
  @p[x] < 0 ? x : @p[x] = root(@p[x])
end

def unite(x, y)
  x, y = root(x), root(y)
  if x != y
    x, y = y, x if @p[y] < @p[x]
    @p[x] += @p[y]
    @p[y] = x
  end
end

hx, hy = {}, {}
Xs.zip(Ys, [*0 ... N]) do |x, y, i|
  unite(i, hx[x]) if hx[x]
  hx[x] = i
  unite(i, hy[y]) if hy[y]
  hy[y] = i
end
puts (0 ... N).group_by{|i| root(i)}.values.inject(-N){|s, a| s + a.map{|i| Xs[i]}.uniq.size * a.map{|i| Ys[i]}.uniq.size}