loop do
  n, x = gets.chomp.split(' ').map(&:to_i)
  break if [n, x] == [0, 0]

  cnt = 0
  ave1 = x / 3
  for i in 1 .. ave1 - 1
    ave2 = (x - i) / 2
    for j in i + 1 .. ave2
      k = x - i - j
      if j < k && k <= n
        cnt += 1
      end
    end
  end

  puts cnt
end