loop {
    n = gets.to_i
    break if n == 0

    a = (1..n).map{ gets.to_i }
    sum = max = 0
    a.each{|x|
        sum = [sum + x, 0].max
        max = sum if sum > max
    }
    p a.all?{|x| x < 0} ? a.max : max
}