results = []

loop do
  n, x = gets.split.map(&:to_i)
  break if [n, x].all?(&:zero?)

  count = 0

  [*1..n].combination(3) do |a|
    count += 1 if a.inject(:+) == x
  end

  results << count
end

results.each do |result|
  p result
end

