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

  a = Array.new

  for i in 1..n
    a.push(gets.to_i)
  end

  ans = -10**10

  for i in 0...n
    sum = 0
    for j in i...n
      sum += a[j]
      ans = sum if sum > ans
    end
  end

  puts ans
end