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 PyPy3 (2.4.0) (judge verdict: Accepted)

N = int(input())
dpA = [0, 1, 4]
dpC = [0, 1, 4]
dpG = [0, 1, 4]
dpT = [0, 1, 4]
dpAG = [0, 0, 1]
dpGA = [0, 0, 1]
dpAC = [0, 0, 1]
dpAT = [0, 0, 1]
dpAGG = [0, 0, 0]
dpATG = [0, 0, 0]
dpAGT = [0, 0, 0]

for i in range(2, N):
	newA = dpA[i] + dpC[i] + dpG[i] + dpT[i]
	newC = dpA[i] + dpC[i] + dpG[i] + dpT[i] - dpAG[i] - dpGA[i] - dpAGG[i] - dpATG[i] - dpAGT[i]
	newG = dpA[i] + dpC[i] + dpG[i] + dpT[i] - dpAC[i]
	newT = dpA[i] + dpC[i] + dpG[i] + dpT[i]
	newAG = dpA[i]
	newGA = dpG[i]
	newAC = dpA[i] - dpGA[i]
	newAT = dpA[i]
	newAGG = dpAG[i]
	newATG = dpAT[i]
	newAGT = dpAG[i]
	dpA.append(newA)
	dpC.append(newC)
	dpG.append(newG)
	dpT.append(newT)
	dpAG.append(newAG)
	dpGA.append(newGA)
	dpAC.append(newAC)
	dpAT.append(newAT)
	dpAGG.append(newAGG)
	dpATG.append(newATG)
	dpAGT.append(newAGT)
print((dpA[N]+dpC[N]+dpG[N]+dpT[N])%1000000007)