$ cat sol3.hs
import Control.Monad

main :: IO ()
main = do
  n       <- read <$> getLine
  ratios  <- replicateM n ((map read . words) <$> getLine)
  let [r1, r2]:rs = ratios
  print $ uncurry (+) $ minVote rs (r1, r2)

getMult :: Int -> Int -> Int
getMult x y
  | x `mod` y == 0  = mult
  | otherwise       = mult + 1
    where
      mult = x `div` y

minVote :: [[Int]] -> (Int, Int) -> (Int, Int)
minVote [] x = x
minVote ([r1, r2]:rs) (v1, v2) = minVote rs cv
  where
    m1    = getMult v1 r1
    m2    = getMult v2 r2
    m     = max m1 m2
    cv    = (r1 * m, r2 * m)