class Group
  attr_accessor :x_list, :y_list
  def initialize(pos)
    @x_list = [pos.x]
    @y_list = [pos.y]
  end
end

class Pos
  attr_accessor :x, :y
  def initialize(array)
    @x = array[0]
    @y = array[1]
  end
end

def x_push(n)
  pos_list = @x_group[n]
  return if pos_list.nil?
  @x_group.delete(n)
  pos_list.each do |pos|
    next if @group.y_list.include?(pos.y)
    @group.y_list << pos.y
    @pos_list.delete(pos)
    y_push(pos.y)
  end
end

def y_push(n)
  pos_list = @y_group[n]
  return if pos_list.nil?
  @y_group.delete(n)
  pos_list.each do |pos|
    next if @group.x_list.include?(pos.x)
    @group.x_list << pos.x
    @pos_list.delete(pos)
    x_push(pos.x)
  end
end

N = gets.chop.to_i

@pos_list = []
N.times { @pos_list << Pos.new(gets.chop.split.map(&:to_i)) }
@x_group = @pos_list.group_by(&:x)
@y_group = @pos_list.group_by(&:y)

@groups = []
until @pos_list.empty?
  pos = @pos_list.pop
  @group = Group.new(pos)
  x_push(pos.x)
  y_push(pos.y)
  @groups << @group
end

puts @groups.map { |g| g.x_list.size * g.y_list.size }.inject(0, &:+) - N
