loop do
  n, x = gets.split(" ").map(&:to_i)
    exit if n == 0 and x == 0
  count = 0

  for i in 1..n
    for j in (i + 1)..n
      for k in (j + 1)..n
        count += 1 if i + j + k == x
      end
    end
  end

  puts count
end