modulo :: Int modulo = 1000 {-# INLINE modulo #-} type Number = (Int, Int) infixr 8 @^@ infixl 7 @*@ (@*@) :: Number -> Number -> Number (ap, aq) @*@ (bp, bq) = ((ap * bp + 3 * aq * bq) `mod` modulo, (ap * bq + aq * bp) `mod` modulo) {-# INLINE (@*@) #-} (@^@) :: Number -> Int -> Number a @^@ i | i == 0 = (1, 0) | odd i = res @*@ a | otherwise = res where res :: Number res = (a @*@ a) @^@ (div i 2) {-# NOINLINE (@^@) #-} main :: IO () main = do n <- readLn :: IO Int let x = (1, 1) @^@ n print $ if even n then ((fst x) * 2 - 1) `mod` modulo else ((fst x) * 2) `mod` modulo