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 (x:xs) = if x >= 0
               then go (-x) True 0 xs
               else go   x False 0 xs
  where go m b n []
          | b         = n - m
          | otherwise = n + m
        go m b n (y:ys)
          | y >= 0 && - m >=   y = go (-y) b (n - m) ys
          | y >= 0 && - m <    y = go  m b (n + y) ys
          | y <  0 && - m >= - y = go  y (not b) (n - m) ys
          | y <  0 && - m <  - y = go  m (not b) (n - y) ys
