=begin
愚直に足す
=end

while (n, x = gets.split.map(&:to_i)) != [0, 0]
  cnt = 0
  (1..n).each do |i|
    ((i+1)..n).each do |j|
      k = x - (i+j)
      cnt += 1 if k <= n && k > j
    end
  end
  puts cnt
end
