# (1..n)
# a + b + c = x || a != b, b != c, c != a

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

  ary = [*1..n]

  i = 0
  ary.combination(3) do |a, b, c|
    if (a + b + c) == x
      i += 1
    end
    puts i
  end
end