while true
  n,x = gets.chomp.split.map(&:to_i)
  if [n,x] == [0,0]
    break
  end
sum = 0
for i in 1..(n-2)
  for j in (i+1)..(n-1)
   for k in (j+1)..n
     if i + j + k == x
      sum += 1
     end
   end
  end
end
 puts sum
end