loop do
  n = gets.to_i
  break if n == 0
  arr = []
  n.times do
    arr << gets.to_i
  end
  max = -300000
  size = arr.size
  size.times do |i|
    current = 0
    (i..(size - 1)).each do |j|
      current += arr[j]
      max = current if max < current
    end
  end
  puts max
end

