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