{-# LANGUAGE BangPatterns #-} {-# LANGUAGE NumericUnderscores #-} import qualified Data.Vector.Fusion.Stream.Monadic as VFSM import qualified Data.Vector.Unboxed.Mutable as VUM stream :: Monad m => Int -> Int -> VFSM.Stream m Int stream !l !r = VFSM.Stream step l where step x | x < r = return $ VFSM.Yield x (x + 1) | otherwise = return $ VFSM.Done {-# INLINE [0] step #-} {-# INLINE [1] stream #-} rep :: Monad m => Int -> (Int -> m ()) -> m () rep n = flip VFSM.mapM_ (stream 3 n) {-# INLINE rep #-} modulo :: Int modulo = 1_000_000_007 {-# INLINE modulo #-} main :: IO () main = do n <- readLn :: IO Int dp <- VUM.unsafeNew (n + 1) VUM.unsafeWrite dp 0 (1 :: Int) VUM.unsafeWrite dp 1 (2 :: Int) VUM.unsafeWrite dp 2 (2 :: Int) rep n $ \i -> do item1 <- VUM.unsafeRead dp (i - 2) item2 <- VUM.unsafeRead dp (i - 3) VUM.unsafeWrite dp i (mod (item1 + item2) modulo) print =<< VUM.unsafeRead dp (n - 1)