loop do
   n=gets.to_i
   break if n==0
   arr=[]
   n.times do
      arr << gets.to_i
   end 
   result=[]
   max=-65536
   0.upto(n-1) do |i|
      next if  arr.length-1!=i and arr[i] < arr[i+1]
      i.upto(n-1) do |j|
         buf=arr[i..j].inject(:+)
         max=buf if max < buf
      end
   end
   puts max
end