# coding: utf-8

class Max
  def solve
    loop do
      n = gets.chomp.to_i
      break if n == 0

      max = -10000
      sum = 0
      n.times do
        a = gets.chomp.to_i
        sum += a
        if max < sum
          max = sum
        end
        if sum < 0 then
          sum = 0
        end
      end
      puts max
    end
  end
end

Max.new.solve