loop do
    n = gets.to_i
    break if n== 0
    a = n.times.map{gets.to_i}
    dp = Array.new(n)
    a.each_with_index do |aa, i|
        if i == 0
            dp[0] = a[0]
            next
        end
        dp[i] = [a[i], a[i] + dp[i-1]].max
    end
    puts dp.max
end