# coding: utf-8

def max_sum_seq
  loop do
    n = gets.chomp.to_i
    break if n == 0

    array = read(n)
    candidates = []
    n.times do |i|
      (i..n-1).each do |j|
        sum = 0
        (i..j).each do |k|
          sum += array[k]
        end
        candidates << sum
      end
    end
    max = find_max(candidates)
    puts max
  end
end

def find_max(array)
  max = -10000
  array.each do |a|
    if max < a then
      max = a
    end
  end
  max
end

def read(n)
  array = []
  (0..n-1).each do
    array << gets.chomp.to_i
  end
  array
end

max_sum_seq