data = []

loop do
  n = gets.to_i
  break if n == 0
  data << n.times.map{gets.to_i}
end

puts (data.map do |a|
  newa = [0]
  a.each do |i|
    if newa.last * i < 0
      newa << i
    else
      newa[-1] += i
    end
  end

  newa.shift if newa.first < 0
  newa.pop   if newa.last < 0

  p newa
  ((1..newa.size).to_a.map do |n|
    newnewa = newa.last(n)
    ((1..newnewa.size).to_a.map do |i|
      newnewa.first(i).inject(:+)
    end).max
  end).max
end)