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)

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

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