while line = gets do
  break if (n = line.to_i) == 0
  array = []
  n.times do
    array.push gets.to_i
  end
  answer = -1000000000
  0.step(n - 1, 1) do |i|
    sum = 0
    i.step(n - 1, 1) do |j|
      sum += array[j]
      answer = sum if sum > answer
    end
  end
  puts answer
end