q = 10^9+7 apply n f x = foldr ($) x (replicate n f) main = readLn >>= print . flip mod q . step step :: Integer -> Integer step 1 = 1 step 2 = 1 step 3 = 3 step n = flip mod q $ sum $ head $ apply (fromIntegral n - 3) dp [[1,1,1],[0,1,0],[1,0,0]] dp xs@[[x1,x2,x3],[y1,y2,y3],[z1,z2,z3]] = [x2+x3, y1+y3, z1+z2] : take 2 xs