ans = []
loop do
    input = gets.split(" ")
    if input[0] == "0" && input[1] == "0"; break; end
    n = input[0].to_i
    x = input[1].to_i
    sum = 0
    1.upto(n) do |a|
        (a+1).upto(n) do |b|
            (b+1).upto(n) do |c|
                if a != b && b != c && a != c && (a + b + c == x)
                    sum += 1
                end
            end
        end
    end
    ans << sum
end
puts ans
