class Mss
  def max(list)
    max = 0
    next_val = 0
    list.each do |input|
      next_val = [input + next_val, 0].max
      max = [max, next_val].max
    end
    max
  end
end

result = []
loop do
  n = gets.chomp.to_i
  break if n == 0

  list = Array.new(n) { gets.chomp.to_i }
  result << Mss.new.max(list)
end

puts result