while true
	n,x = gets.split.map(&:to_i)
	if n == 0 && x == 0
		break
	end
	a = 1
	b = 1
	c = 0
	cnt = 0
	for a in 1..(n-2) do
		for b in (a+1)..(n-1) do
			c = x - a - b
			if c <= n && c > b && a != b
				cnt += 1
			end
		end
	end
	puts cnt
end