while input = STDIN.gets.split(" ")
  n = input[0].to_i
  x = input[1].to_i

if n == 0 && x == 0
  break
end

num = 0
  for i in 1..n  do
    a = i
    for j in 1..n do if j > i
      b = j
      for k in 1..n  do if k >j
        c = k
        if a + b + c == x
          num +=1
        end
      end
      end end
    end end
  puts num
end
