import Control.Applicative
import Data.List

main = do
  contents <- fmap readZ . lines <$> getContents
  mapM_ (print . (maxSum [])) (dataCut contents)

dataCut :: [Int] -> [[Int]]
dataCut (0:_) = []
dataCut (x:xs) = (take x xs) : (dataCut (drop x xs))

readZ :: String -> Int
readZ all@(x:xs)
  | x == '-' = negate $ (read :: String -> Int) xs
  | otherwise = (read :: String -> Int) all

maxSum :: [Int] -> [Int] -> Int
maxSum [] (x:xs) = maxSum [x] xs
maxSum ls [] = maximum ls
maxSum ls (x:xs)
  | w > x = maxSum (w:ls) xs
  | otherwise = maxSum (x:ls) xs
    where
      w = head ls + x