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
      ksum = a[0..k-1].inject(:+)
      max = ksum if ksum>max
      for l in 0..n-k
        ksum += a[k+l]-a[l]
        max = ksum if ksum>max
      end
    end
  end
  
  puts max
end