import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.List

getAsInt :: IO [Int]
getAsInt =  unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

main :: IO ()
main = do
  _ <- getLine
  as <- getAsInt
  print $ solve as

solve :: [Int] -> Int
solve = go (- 10^9-7) 0
  where go _ n [] = n
        go m n (x:ys)
          | x >= 0 = go m (n+x) ys
          | x < 0 && m >= x = go m (n - x) ys
          | otherwise = go x (n - m) ys
