while true
	n,x = gets.chomp.split(" ").map(&:to_i)
	break if n == 0 && x == 0
	nums = [n]
	count = 0
	n.times do |i|
		nums[i] = i + 1
	end
	for i in 0..n - 1 do
		for j in i + 1..n - 1 do
			for k in j + 1..n - 1 do
					count += 1 if nums[i] + nums[j] + nums[k] == x
			end
		end
	end
	puts count
end