def f(u, x)
  count = 0
  u.each { |i|
    count +=1 if x == i.sum
  }
  return count
end

while (n, x, = gets.split.map(&:to_i)) != [0, 0]
  a = [*1..n]
  u = a.combination(3).to_a
  puts f(u, x)
end
