import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Ord

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    ds <- replicateM n $ do
        [a,b] <- getIntList
        return (a+b, b)
    let ans = sum $ zipWith (\k (x,y) -> k*x-y) (cycle [1,0]) $ sortOn Down ds
    print ans