#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
  0.upto(i.length - 1) do |j|
    break if i[j] >= 0
    if j == (i.length - 1)
      next i.sort[-1] 
    end
  end
  0.upto(i.length - 1) do |j|
    sum += i[j]
    sum = 0 if sum < 0
    mss = sum if mss < sum
  end
  puts mss
end