e = 0
loop do
    n, x =gets.chomp.split.map(&:to_i)
    if n == 0 && x == 0
        break
    end
    (1..(n - 2)).each do |i|
        ((i + 1)..(n - 1)).each do |j|
            ((j + 1)..n).each do |k|
                d = i + j + k
                if d == x
                    e += 1
                end
            end
        end
    end
puts e
e = 0
end