
while true
    

    n,x = gets.split.map{|i| i.to_i}
    if n==0 and x==0
        break
    end
    sum =0
    for i in 1..n-2
        for j in i+1..n-1
            for k in j+1..n

                if i+k+j==x
                    sum +=1
                end

            end
        end

    end

    puts sum

end
