import Data.List (inits, tails)
import Control.Applicative ((<$>))
import Control.Monad (replicateM)

allPartialLists :: [a] -> [[a]]
allPartialLists = filter (not . null) . concatMap inits . tails

maxSumSeq :: (Num a, Ord a) => [a] -> a
maxSumSeq = maximum . map sum . allPartialLists

main :: IO ()
main = do
    n <- read <$> getLine
    if n == 0
    then return ()
    else do
        bs <- map read <$> replicateM n getLine
        (putStrLn . show . maxSumSeq) bs
        main