while line = gets
  n, x = line.chomp.split(' ').map(&:to_i)
  break if n == 0 && x == 0
  res = 0
  (1..n).to_a.combination(3) do |a, b, c|
    if a + b + c == x
      res += 1
    end
  end
  puts res
end