#!/usr/local/bin/ruby
while (n=gets.to_i)!=0
  rec=Array.new
  for i in 0..n-1
    rec << gets.to_i
  end
  ans = -1000000
    for x in 0..n-1
    sum = 0
    for y in x..n-1
      sum = sum + rec[y].to_i
      if sum > ans
        ans = sum
      end
    end
  end
  puts "#{ans}"
end