while s = gets
  n = s.to_i
  break if n == 0
  a = n.times.map { gets.to_i }

  max = 0
  (0..n - 1).each { |i|
    sum = 0
    (i..n - 1).each { |j|
      sum += a[j]
      max = sum if sum > max
    }
  }
  puts max
end