readlines.each do |line|
  n, x = line.split.map(&:to_i)
  break if n == 0 && x == 0

  solves = []
  # i + j + j == x
  (1..x).each do |i|
    # j + k == x - i
    (i..x).each do |j|
      # k == x - i - j
      k = x - i - j
      solves << [i, j, k] if j < k
    end
  end
  puts solves.count
end