loop do
n,x = gets.split.map(&:to_i)


if n==0 && x==0 then
exit

else

count = 0
for i in 3..n
for j in 2..(i-1)
for k in 1..(j-1)

if i+j+k == x then
count += 1
end

end
end
end

puts count


end


end
