module Main where
import qualified Control.Monad as CM
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A
import qualified Data.Ord as O

int = read :: String -> Int
long = read :: String -> Integer
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser :: String -> [[Integer]]
parser = map (map long . words) . tail . lines
printer :: Integer -> String
printer = (++"\n") . show

solver :: [[Integer]] -> Integer
solver abs = answer
  where tabs = map (\[a,b]->[a+b,a,b]) abs
        pairs = L.sortBy (\[t1,a1,b1] [t2,a2,b2]->O.comparing (*(-1)) t1 t2) tabs
        answer = takahashi pairs 0 0

--takahashi :: [Integer] -> Integer -> Integer -> Integer
takahashi [] sa sb = sa - sb
takahashi ([t,a,b]:pairs) sa sb
  = aoki pairs (sa+a) sb

aoki [] sa sb = sa - sb
aoki ([t,a,b]:pairs) sa sb
  = takahashi pairs sa (sb+b)


