loop do
    n = gets.to_i
    break if n== 0
    a = n.times.map{gets.to_i}
    max = temp = 0
    a.each_with_index do |aa, i|
        if i == 0
            max = temp = a[0]
            next
        end
        temp = [a[i], a[i] + temp].max
        max = [temp, max].max
    end
    puts max
end