while true
    n = gets.to_i
    break if n == 0

    table = [0]
    n.times{|i|
        table[i + 1] = table[i] + gets.to_i
    }

    answers = []
    1.upto(n){|interval|
        interval.upto(n){|right|
            answers << table[right] - table[right - interval]
        }
    }
    puts answers.max
end