loop do
  n, x = gets.chomp.split(' ').map(&:to_i)
  break if [n, x] == [0, 0]
 
  cnt = 0
  # n + n + 1 + n + 2 = x
  for i in 1 .. x / 3 - 1
    #i + n + n + 1 = x
    for j in i + 1 .. (x - i - 1) / 2
      k = x - i - j
      if j < k && k <= n
        cnt += 1
      end
    end
  end
 
  puts cnt
end