loop do
  n = gets.to_i
  break if n == 0

  arr = n.times.map { gets.to_i }

  max = max_n = -100000
  r = 0

  arr.each do |a|
    max_n = [a, max_n].max
    r = [r + a, 0].max
    max = [r, max].max
  end
  puts max_n > 0 ? max : max_n
end