import Data.List
import Control.Monad
import Data.Functor

main::IO ()
main=
  do
    n <- read <$> getLine::IO Int
    input <- replicateM n getLine
    let toCard=(\(a:b:_)->(a,b)) . map read . words::String->(Int,Int)
        cards=map toCard input
        (ansA,ansB)=foldl' (\(a0,b0) (a,b) ->
                          case compare a b of
                            LT->(a0,b0+a+b)
                            GT->(a0+a+b,b0)
                            EQ->(a0+a,b0+b)
                      )
                      (0,0) cards
    putStrLn $ show ansA ++ ' ' : show ansB