while n = gets.to_i
  break if n == 0

  arr = (1..n).map { gets.to_i }

  sum = max = 0
  arr.each do |el|
    sum = [sum + el, 0].max
    max = sum if sum > max
  end
  puts arr.all? { |el| el < 0 } ? arr.max : max
end