#main
arr = Array.new
until (n = gets) == "0\n"
  a = Array.new
  (n.to_i).times do
    a << gets.to_i
  end
  arr << a
end
arr.each do |i|
  mss = 0
  sum = 0
  max = -100000
  b = Array.new(1){[0]}
  i.each do |j|
    b << (b[-1] + [0]).map{|x| x + j}
  end
  puts b.flatten.max
end