loop{
    n = gets.to_i
    break if n == 0

    maximum = -200000
    current = 0
    n.times{
        b = gets.to_i
        current += b
        if maximum < current
            maximum = current
        end

        if maximum < b
            maximum = current = b
        end
    }

    p maximum
}