import Data.List
import Control.Monad

main = do
    n <- readLn
    unless ( n == 0) $ do
        nums <- replicateM n readLn
        print $ mss2 nums
        main

mss1 :: [Int] -> Int
mss1 = maximum.map sum.concatMap inits.tails

mss2 = maximum . scanr (\x y -> 0 `max` (x+y)) 0