while (n = $<.gets.to_i).nonzero?
  given = (1..n).map {$<.gets.to_i}
  max = -Float::INFINITY
  n.times do |i|
    sum = 0
    (i...n).each do |j|
      sum += given[j]
      max = sum if sum > max
    end
  end
  puts max
end
