# encoding: utf-8                                                            

def solve arr
  ans, curr_max = 0, arr[0]
  arr.each do |num|
    if ans + num < 0
      ans = 0
    else
      ans = ans + num
      curr_max = ans if ans > curr_max
    end
  end
  curr_max
end

while n = gets
  n = n.rstrip.to_i
  break if n == 0
  num = []
  (1..n).each { |n| nn = gets.to_i; num << nn}
  puts "#{solve(num)}"
end