import qualified Data.IntMap as M

main :: IO ()
main = do
  n <- read <$> getLine
  print . eval . iter f (n - 3) . insert [0, 2, 1] 0 . insert [2, 0, 1] 0 . insert [0, 1, 2] 0 . fromList $ zip triple (repeat 1)

f :: M.Map Integer -> M.Map Integer
f kvs = fromList . map ((,) <$> id <*> g) $ triple
  where
    g t@(x : y : z : _) = foldl step 0 [0 .. 3]
      where
        step r w = r + if match [x, y, z, w] then 0 else kvs ! [y, z, w]

insert :: [Int] -> Int -> M.Map Int -> M.Map Int
insert = M.insert . encode

fromList :: [([Int], Int)] -> M.Map Int
fromList = M.fromList . map ((,) <$> encode . fst <*> snd)

(!) :: M.Map Int -> [Int] -> Int
(!) = flip (M.!) . encode

triple :: [Int]
triple = sequence . replicate 3 $ [0 .. 3]

eval :: M.Map Integer -> Int
eval = fromInteger . M.foldl step 0
  where
    step r k = (r + k) `mod` m

bads :: [[Maybe Int]]
bads = [[Nothing, Just 0, Just 2, Just 1], [Just 0, Nothing, Just 2, Just 1], [Just 0, Just 2, Nothing, Just 1], [Just 0, Just 2, Just 1, Nothing], [Nothing, Just 2, Just 0, Just 1], [Just 2, Just 0, Just 1, Nothing], [Nothing, Just 0, Just 1, Just 2], [Just 0, Just 1, Just 2, Nothing]]

match :: [Int] -> Bool
match = or . map match' . zip bads
  where
    match' (Just y, x) | x == y = True
    match' _ = False

m :: Integer
m = 10 ^ 9 + 7

iter :: (a -> a) -> Int -> a -> a
iter _ 0 = id
iter f = g
  where
    g n = f . g (pred n)

encode :: [Int] -> Int
encode = foldr step 0
  where
    step x r = x + 4 * r
