import Control.Applicative

import Control.Monad
    (replicateM, when)
    
type Set = [Int]

type Problem = (Int, Set)

type Result = Int

solve :: Problem -> Result

solve (n, set)
    = maximum $ map sum subs where
        subs = concat [[take y $ drop x set | y <- [1..(n - x)]] | x <- [0..(n - 1)]]
        
output :: Result -> String

output
    = show
    
input :: Int -> IO Set

input n
    = replicateM n $ read <$> getLine
    
check :: IO Int

check
    = read <$> getLine
    
main :: IO ()

main
    = do
        n <- check
        when (n /= 0) $ do
            set <- input n
            putStrLn $ output $ solve (n, set)
            main