-- yukicoder My Practice -- author: Leonardone @ NEETSDKASU isKadomatsuRetsu :: [Int] -> Bool isKadomatsuRetsu [a1, a2, a3] = a1 /= a3 && (isMinA2 || isMaxA2) where isMinA2 = a2 < a1 && a2 < a3 isMaxA2 = a2 > a1 && a2 > a3 main = putStrLn . solve . map read . words =<< getLine solve [a1, a2, a3] = if isKadomatsuRetsu a123 then "INF" else show count where a123 = [a1, a2, a3] maxval = maximum a123 modKadomatsu p = map (`mod` p) a123 counter = isKadomatsuRetsu . modKadomatsu count = length $ filter counter [1 .. maxval]