class Mss
  def max(list)
    max = -100_000
    max_minus = -100_000
    next_val = 0
    list.each do |input|
      next_val = [input + next_val, 0].max
      max_minus = [input, max_minus].max
      max = [max, next_val].max
    end
    max_minus < 0 ? max_minus : max
  end
end

inputs = STDIN.read.split("\n").map { |e| e.chomp.to_i }

loop do
  n = inputs.shift
  break if n == 0

  list = Array.new(n) { inputs.shift }
  puts Mss.new.max(list)
end