results = []
while true do
   n, x = gets.split.map(&:to_i)
   if n == 0 && x == 0
      break
   end
   nums = []
   (1..n).each do |i|
      nums << i
   end
   sum = 0
   nums.combination(3) do |a,b,c|
      if a + b + c == x
         sum +=1
      end
   end
   results << sum
end

results.each do |result|
   puts result
end