import Control.Monad
import Data.Array

main = do
    n <- readLn
    unless (n==0) $ do
                  list <- replicateM n readLn
                  print $ mss2 0 0 list
                  main

mss2 :: Int -> Int -> [Int] -> Int
mss2 mx _ []  = mx 
mss2 mx locSum (x:xs)
    | thisSum > mx = mss2 thisSum thisSum xs
    | thisSum < 0  = mss2 mx 0 xs
    | otherwise    = mss2 mx thisSum xs
    where thisSum = locSum + x