answers = []

while n = gets.to_i
  break if n == 0
  data = []
  n.times { data << gets.to_i }

  answer = -1.0 / 0

  i = 0
  while i < data.size
    j = 0
    while j < data.size
      answer = [data.slice(i, j + 1).inject(0) { |a, e| a + e }, answer].max
      j += 1
    end
    i += 1
  end
  answers << answer
end

answers.each { |answer| puts answer }