while true
    n = gets.to_i
    break if n == 0
    a = []
    for i in 0..n-1
        a<<gets.to_i
    end
    max_ending_here = max_so_far = a[0]
    for i in 1..a.length-1
        max_ending_here = [a[i],max_ending_here+a[i]].max
        max_so_far = [max_so_far, max_ending_here].max
    end
    puts(max_so_far)
end