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