import Data.List (transpose) modulo = 10 ^ 9 + 7 period = 2 * (modulo + 1) `div` 3 fib_mat :: [[Int]] fib_mat = [[1, 1], [1, 0]] initial_vector :: [[Int]] initial_vector = [[0], [1]] multiply :: (Integral a) => [[a]] -> [[a]] -> a -> [[a]] multiply a b mo = map (\r -> map ((`mod` mo) . sum . zipWith (*) r) b') a where b' = transpose b expt :: [[Int]] -> Int -> Int -> [[Int]] expt = expt' [[1, 0], [0, 1]] where expt' a _ 0 _ = a expt' a b n mo | n `mod` 2 == 1 = expt' (multiply a b mo) b' n' mo | otherwise = expt' a b' n' mo where n' = n `div` 2 b' = multiply b b mo main = do n <- readLn let ([an]:_) = multiply (expt fib_mat n period) initial_vector period ([bn]:_) = multiply (expt fib_mat an modulo) initial_vector modulo print bn