
def sum?(range_start, range_end, sum)
  (range_end-range_start).times do |diff|
    return true if diff+range_start+range_end == sum
  end
  false
end

def count(range_start, range_max, sum)
  result = 0
  range_start.upto(range_max) { |n| result += 1 if sum?(n, range_max, sum) }
  result
end

while input = gets
  arr = input.chomp.split(' ').map(&:to_i)
  break if arr[0] == 0
  sum = arr[1]
  range_max = arr[0] < sum-3 ? arr[0] : sum-3
  result = 0
  1.upto(range_max) do |n|
    result += count(n+1, range_max, sum-n)
  end
  puts result
end