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

    anscount = 0
    (1..(n - 2)).each do |a|
        ((a + 1)..(n - 1)).each do |b|
            ((b + 1)..n).each do |c|
                if a + b + c == x
                    anscount += 1
                end
            end
        end
    end
    puts anscount
end