import Control.Monad main :: IO () main = do input <- liftM (map (map read . words) . lines) (readFile "2.in") :: IO [[Int]] print $ sum [maximum l - minimum l | l <- input] let f = fst . head . filter ((/=1) . fst) . filter ((==0) . snd) . concat . concatMap (\(a,b) -> [map (a `divMod`) b, map (`divMod` a) b]) . (\l -> zip l (repeat l)) print $ sum $ map f input