import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.IntSet as S
import Data.Ord

main :: IO ()
main = readLn >>= readContents >>= print . solve 

solve :: [[Int]] -> Int
solve = foldl' ff 0 . edit . sortBy cmpf
    where
        cmpf lhs rhs = comparing maximum rhs lhs `mappend` comparing minimum rhs lhs 
        
        edit = zip (cycle [True, False])

        ff acc (t, [a, b])
            | t = acc + a
            | otherwise = acc - b

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine