class Maximum
  def initialize
    @result = []

    while(@n = $stdin.gets.chomp.to_i)
      @max = -1000000
      if @n != 0
        calc  
      else 
        break
      end
    end
    render
  end

  def calc
    sum = 0
    @n.times do 
      val = $stdin.gets.chomp.to_i
      if val < 0
        sum += val
        if @max < sum
          @max = sum
        end
        if sum <= 0
          sum = 0
        end
      else
        sum += val
        if @max < sum
          @max = sum
        end
      end
    end
    @result.push(@max)
  end

  def render
    @result.each do |val|
      puts val
    end
  end
end

m = Maximum.new