ans = []
while true
  count, value = gets.split(" ").map(&:to_i)
  break if count.zero? && value.zero?
  sum = 0
  memo = []
  (1..count).each do |val1|
    (1..count).each do |val2|
      next if val2 < val1 || val2 == val1
      (1..count).each do |val3|
        next if val3 < val2 || val2 == val3
        sum += 1 if val1 + val2 + val3 == value
      end
    end
  end
  ans << sum
end

puts ans