while true do
  s = gets.split()
  n = s[0].to_i
  x = s[1].to_i
  count = 0
  if n == 0 and x == 0
    break
  end
  (1..n-2).each do |i|
    (i+1..n-1).each do |t|
      (t+1..n).each do |c|
        if i + t + c == x
          count += 1
        end
      end
    end
  end
  p count
end