Problem:
Score : 400 points

Problem Statement

You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7:

The string does not contain characters other than A, C, G and T.

The string does not contain AGC as a substring.

The condition above cannot be violated by swapping two adjacent characters once.

Notes

A substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.

For example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and (the empty string), but not AC.

Constraints

3 \leq N \leq 100

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7.

Sample Input 1

3

Sample Output 1

61

There are 4^3 = 64 strings of length 3 that do not contain characters other than A, C, G and T. Among them, only AGC, ACG and GAC violate the condition, so the answer is 64 - 3 = 61.

Sample Input 2

4

Sample Output 2

230

Sample Input 3

100

Sample Output 3

388130742

Be sure to print the number of strings modulo 10^9+7.

Solution in Python (3.4.3) (judge verdict: Accepted)

mod = 10**9 + 7

N = int(input())

# NG = {AGC,GAC,ACG,ATGC,AGGC,AGTC}
# (A,C,G,T) = (0,1,2,3)
# dp[i][j]: 長さiの条件を満たす文字列のうち、末尾がjとなるものの場合の数
# 初期条件 dp[1] = [1,1,1,1]
# ans = dp[0] + dp[1] + dp[2] + dp[3]

dp = [[0]*4 for _ in range(N+1)]

# A,C,G,T それぞれ1通りずつ
dp[1] = [1]*4


for i in range(2,N+1):
    for j in range(4):
        # ひとまず長さi-1の文字列にjを足して良いとする
        dp[i][j] += sum(dp[i-1])
        dp[i][j] %= mod
    # ダメなパターンを引いて補正する
    # 後ろ二文字が"AG","GA"の場合はCを付け足せない
    # ~AG, ~GA となる場合の数はそれぞれ dp[i-2][0]*1とdp[i-2][2]*1
    dp[i][1] -= dp[i-2][0] + dp[i-2][2]
     # 後ろ二文字が"AC"の場合はGを付け足せない
    # ~AC となる場合の数は dp[i-2][0] (- dp[i-3][2])
    dp[i][2] -= dp[i-2][0]
    if i >= 3:
        # 後ろ三文字が"ATG","AGG","AGT"となる場合はCを付け足せない
        # ~ATG, ~AGG, ~AGT となる場合の数は 合わせて dp[i-3][0]*3
        dp[i][1] -= dp[i-3][0]*3
        # ----------------------注意--------------------------
        # dp[i-2][0]は後ろから~ACとなる場合の数だから
        # これには~GACとなる場合の数も含まれている
        # しかし~GACというのは既に除外しているので
        # ~ACとなる場合の数は dp[i-2][0]-dp[i-3][2]
        # 余分に引いている分を+dp[i-3][2]することで補正
        dp[i][2] += dp[i-3][2]

ans = sum(dp[N]) % mod
print(ans)