n = gets.to_i
MX = 100001
x = Array.new(MX){[]}
y = Array.new(MX){[]}
n.times do
	xi,yi = gets.split.map(&:to_i)
	x[xi] << yi
	y[yi] << xi
end

sum = 0
visitedx = []
x.each_with_index do |ax,index|
	next if ax.empty?
	next if visitedx.include? index
	edgenum = 0
	visitedx << index
	visitedy = []
	until ax.empty?
		tax = ax.shift
		next if visitedy.include? tax
		edgenum += 1
		visitedy << tax
		y[tax].each do |tay|
			next if visitedx.include? tay
			edgenum += 1
			visitedx << tay
			ax.append tay
		end
	end
	(sum += visitedx.size * visitedy.size - edgenum)if (visitedx.size >= 2) && (visitedy.size >= 2)
end

puts sum
