# Kadane
module Kadane
  def self.max_subarray(a)
    max_so_far =  max_ending_here = 0
    a.each do |i|
      max_ending_here = [0, max_ending_here + i].max
      max_so_far = [max_so_far, max_ending_here].max
    end
    max_so_far
  end
end

answers = []

while n = gets.to_i
  break if n == 0
  a = []
  n.times { a << gets.to_i }
  answers << Kadane.max_subarray(a)
end

puts answers