module Main (main) where
import System
import Control.Monad
play :: (Int,Int) -> (Int,Int)
play (x,y)
| x == y = (x,y)
| x < y = (0,x + y)
| otherwise = (x + y,0)
execute :: [(Int,Int)] -> (Int,Int)
execute xs = foldr1 (\(p,q) (r,s) -> (p+r,q+s)) $ map play xs
listToTuple :: [String] -> (Int,Int)
listToTuple (x:y:_) = (read x,read y)
main :: IO ()
main = do
(inputFile:_) <- getArgs
(l:ls) <- liftM lines $ readFile inputFile
let
sheeds = map (listToTuple . words) $ take (read l) ls
(x,y) = execute sheeds
writeFile "output.txt" $ show x ++ " " ++ show y