import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.List.Split
import Data.Char

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete

fix x = round (x * 100000)

mss (a:as) = mss' a a as
  where
    mss' r _ [] = r
    mss' r t (a:as) = mss' (max r $ max nt a) nt as
      where nt = max 0 t+a

main = do
    n <- getInt
    when (n/=0) $ do
        replicateM n getInt >>= print . mss >> main