q = 10^9+7 :: Integer fib modulo n = fst (fibr (0,1) n) where tpq (p,q) (a,b) = (mod (p*a + q*b) modulo, mod (q*a + (p+q)*b) modulo) fibr pq@(p,q) n | n < 1 = (0,1) | even n = fibr (mod (p^2 + q^2) modulo, mod (2*p*q + q^2) modulo) (div n 2) | otherwise = tpq pq (fibr pq (n-1)) main = do n <- readLn :: IO Integer print $ fib q (fib q (mod n (2 * (10^9) + 16)))