import Control.Monad (replicateM)

main = do
    n <- readLn
    if n == 0 then return () else do
        replicateM n readLn >>= return . solve >>= print
        main

solve :: [Int] -> Int
solve = maximum . scanl1 accumMax
    where
    accumMax a b = max (a+b) b