import Control.Monad
import Data.Functor
import System.IO

minVal = minBound :: Int

main = do
  n <- readInt <$> getLine
  if n == 0 then return () else do
    xs <- replicateM n (readInt <$> getLine)
    print $ solve xs
    main

solve :: [Int] -> Int
solve = loop minVal 0
  where loop v _ [] = v
        loop v s (x:xs) = loop (max v w) w xs
          where w = max (s + x) x

readInt :: String -> Int
readInt = read