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 [] True 0
  where go ms b n []
          | null ms   = n
          | b         = n - head ms
          | otherwise = n + head ms
        go [m] b n (x:ys)
          | x >= 0 && - m >=   x = go [-x] b (n - m) ys
          | x >= 0 && - m <    x = go [ m] b (n + x) ys
          | x <  0 && - m >= - x = go [ x] (not b) (n - m) ys
          | x <  0 && - m <  - x = go [ m] (not b) (n - x) ys
        go [] b n (x:ys)
          | x >= 0    = go []  b (n + x) ys
          | otherwise = go [x] (not b) n ys