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

  a = Array.new(n){gets.to_i}
  
  max = a.max

  if n>1
    for k in 1..n
      kmax = Array.new(n-k+1){|i| a[i..i+k-1].inject(:+)}.max
      max = kmax if kmax>max
    end
  end
  
  puts max
end