loop do
    n = gets.to_i
    break if n== 0
    a = n.times.map{gets.to_i}
    max = -Float::INFINITY
    for i in 0...n
        sum = 0
        for j in i...n
            sum += a[j]
            max = [sum, max].max
        end
    end
    puts max
end