import Control.Monad
import Control.Monad.Trans.State.Strict
import Data.Char (isSpace)
import Data.Maybe (fromJust)
import qualified Data.ByteString.Lazy.Char8 as B

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT (B.readInt . B.dropWhile isSpace)

parseInt2 :: Parser (Int,Int)
parseInt2 = liftM2 (,) parseInt parseInt

parse :: Parser [(Int,Int)]
parse = do
    n<-parseInt
    replicateM n parseInt2

main=do
    tas<-fromJust.evalStateT parse <$> B.getContents
    print.liftM2 (+) fst snd.foldl1 f $ tas

f (u,v) (t,a) = (t*n, a*n)
    where
        n = maximum [(u+v+t+a-1)`div`(t+a), (u+t-1)`div`t, (v+a-1)`div`a]
