import qualified Data.ByteString.Char8 as C import Data.Char import Data.Array.IO main :: IO () main = do ss <- C.getLine let (a, r1) = nextInt ss let (b, r2) = nextInt r1 let (c, r3) = nextInt r2 printans $ solve a b c isKadomatsu :: Int -> Int -> Int -> Bool isKadomatsu a b c | a < b && b > c && a /= c = True | a > b && b < c && a /= c = True | otherwise = False solve :: Int -> Int -> Int -> Int solve a b c | isKadomatsu a b c = -1 | isKadomatsu a b c = -1 | otherwise = solve2 a b c solve2 :: Int -> Int -> Int -> Int solve2 a b c = solve3 a b c m where m = max a $ max b c solve3 :: Int -> Int -> Int -> Int -> Int solve3 a b c m | m < 1 = 0 | isKadomatsu a' b' c' = x + 1 | otherwise = x where a' = mod a m b' = mod b m c' = mod c m x = solve3 a b c (m - 1) printans :: Int -> IO () printans n | n < 0 = putStrLn "INF" | otherwise = print n nextInt :: C.ByteString -> (Int, C.ByteString) nextInt ss | isDigit x = nextInt2 0 ss | otherwise = nextInt $ C.tail ss where x = C.head ss nextInt2 :: Int -> C.ByteString -> (Int, C.ByteString) nextInt2 n ss | C.null ss = (n, ss) | isDigit y = nextInt2 (n * 10 + (digitToInt y)) ys | otherwise = (n, ys) where y = C.head ss ys = C.tail ss