while n = STDIN.gets.chomp.to_i
  if n == 0 then break end
  a=[]
  n.times do
    a.push(STDIN.gets.chomp.to_i)
  end
  max_sum=-1000000000
  (-1...a.length).each do |i|
    sum=0
    (i+1...a.length).each do |j| 
      sum += a[j]
      if max_sum < sum then max_sum = sum end
    end
  end 
  puts max_sum
end