while line = gets.chomp
  break if line == "0 0"
  n,x = line.split(" ").map(&:to_i)
  cnt = 0
  1.upto(n-2) do |a|
    (a+1).upto(n-1) do |b|
      c = x - a - b
      cnt += 1 if (c <= n and c > b)
    end
  end
  puts cnt
end