import Control.Applicative import Data.List import Data.Ratio main :: IO () main = solve <$> (getLine >> f) <*> (getLine >> f) >>= putStrLn where f = map read <$> words <$> getLine solve :: [Int] -> [Int] -> String solve (a:as) bs = let n = foldl' (\x y -> x * (1 % y)) (a % 1) as (b':bs') = reverse bs d = foldl' (\x y -> recip x * (y % 1)) (b' % 1) bs' ans = n * recip d in unwords . map show $ [numerator ans, denominator ans]