import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- readLn
  as <- replicateM n readLn
  
  when (n /= 0) $ do
    print $ maximum $ concatMap (map sum . (\xs -> map (flip take $ xs) [0..length xs-1])) $ map (flip drop $ as) [0..n-1]
    main