loop do
  line = gets.chomp.split
  n = line[0].to_i
  x = line[1].to_i

  break if n == 0 && x == 0

  count = 0
  for i in 1..n do
    for j in i+1..n do
      for k in j+1..n do
        count += 1 if i + j + k == x
      end
    end
  end

  puts count
end