N = gets.to_i

ns = []
list_x = []
list_y = []
N.times{|i|
	pos = gets.strip.split(/ /).collect(&:to_i)
	ns << pos
	x, y = pos
	if l = list_x[x]
		l << i
	else
		list_x[x] = [i]
	end
	if l = list_y[y]
		l << i
	else
		list_y[y] = [i]
	end
}

groups = N.times.to_a

def get_root(groups, g)
	parent = groups[g]
	if parent == g
		return parent
	else
		return groups[g] = get_root(groups, parent)
	end
end

def set_root(groups, g, root)
	parent = groups[g]
	groups[g] = root
	if parent == g
		return
	else
		set_root(groups, parent, root)
	end
end

def combine(groups, g1, g2)
	root = get_root(groups, g1)
	set_root(groups, g2, root)
end

def combine_groups(groups, l)
	if l
		if l.length > 1
			i1 = l[0]
			(1...l.length).each{|i|
				i2 = l[i]
				combine(groups, i1, i2)
				i1 = i2
			}
		end
	end
end

list_x.each{|l|
	combine_groups(groups, l)
}

list_y.each{|l|
	combine_groups(groups, l)
}

table = {}
groups.each_with_index{|g, i|
	g = get_root(groups, g)
	if l = table[g]
		l << i
	else
		table[g] = [i]
	end
}

count = 0
table.values.each{|list|
	x_table = {}
	y_table = {}
	list.each{|i|
		x, y = ns[i]
		x_table[x] = true
		y_table[y] = true
	}
	x_count = x_table.length
	y_count = y_table.length
	if x_count >= 2 && y_count >= 2
		count += (x_count * y_count - list.length)
	end
}
puts count
