#!/usr/bin/env runhaskell module Main where import Data.Bits import Data.Monoid data Mat22 a = Mat22 a a a a deriving (Eq, Ord, Show, Read) instance Num a => Monoid (Mat22 a) where mempty = Mat22 1 0 0 1 mappend (Mat22 a00 a01 a10 a11) (Mat22 b00 b01 b10 b11) = Mat22 (a00 * b00 + a01 * b10) (a00 * b01 + a01 * b11) (a10 * b00 + a11 * b10) (a10 * b01 + a11 * b11) fib :: Int -> Integer fib n = unpack $ go f0 mempty 1 where f0 = Mat22 1 1 1 0 go :: Mat22 Integer -> Mat22 Integer -> Int -> Mat22 Integer go _ g i | i > n = g go f g i = if n .&. i == 0 then go (f <> f) g (i `shift` 1) else go (f <> f) (f <> g) (i `shift` 1) unpack (Mat22 a b c d) = b solve :: Int -> Integer solve l = if l `mod` 2 == 0 then let h = l `div` 2 in 2 * fib (h-1) * fib h else fib l main :: IO () main = do l <- readLn let y = solve l if y == 0 then do print $ l+1 putStrLn "INF" else do print l print y