{-# LANGUAGE BangPatterns #-}
{-# OPTIONS_GHC -with-rtsopts="-A32m" #-}
module Main where
import qualified Data.ByteString.Char8 as B
import Data.List(sort, foldl', unfoldr)
import Data.Char(isSpace)
import Data.Monoid((<>))

data PI = PI {-# UNPACK #-} !Int {-# UNPACK #-} !Int
    deriving (Eq)
instance Ord PI where
    compare (PI x y) (PI z w) = compare (- (x + y)) (- (z + w)) <> compare x z 
    

parse :: B.ByteString -> [PI]
parse = unfoldr step
  where
  step !s | B.null s = Nothing
          | otherwise = do
               (n1, s1) <- B.readInt s
               (n2, s2) <- B.readInt (B.tail s1)
               let s3 = B.dropWhile isSpace s2
               return (PI n1 n2, s3)

main :: IO ()
main = do
    n <- fmap read getLine :: IO Int
    content <- B.getContents
    let asbs = parse content
    let l  = sort asbs
        ps = cycle [1,-1 :: Int]
        ans = sum $ zipWith (\(PI a b) p -> if p == 1 then a else - b) l ps
    print ans                
