loop do
  n, x = gets.split.map(&:to_i)
  if n == 0 && x == 0
    break
  end
  ans = 0
  for i in 1 .. n
    for j in i + 1 .. n
      for k in j + 1 .. n
        if i + j + k == x
          ans += 1
        end
      end
    end
  end
  puts ans
end

