def how_many_ways(n, x)
  ary = [*1..n].combination(3).to_a
  cnt = 0
  ary.each do |i|
    cnt += 1 if i.inject(&:+) == x
  end
  return cnt
end

loop do
  n, x = gets.chomp.split(" ").map(&:to_i)
  break if [n, x] == [0, 0]
  puts how_many_ways(n, x)
end