while (n, x = gets.split.map(&:to_i))!=[0,0] do
    c = 0
    for i in 1..n-2 do
        for j in i+1..n-1 do
            for k in j+1..n do
                c+=1 if i + j + k == x
            end
        end
    end
    puts c
end
