#!/usr/bin/env ruby

result = []
numbers = []

loop do
    temp = 0
    numbers = gets.split.map(&:to_i)
    if numbers[0] == 0 and numbers[1] == 0 then
        break
    end
    1.upto(numbers[0]) do |index1|
        (index1+1).upto(numbers[0]) do |index2|
            (index2+1).upto(numbers[0]) do |index3|
                if index1 + index2 + index3 == numbers[1] then
                    temp += 1
                end
            end
        end
    end
    result << temp
end
puts result
