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: Wrong Answer)

MOD = int(10**9 + 7)
N = int(input())
cnt = [4, 4, 3, 4, 4, 4, 3, 4, 4, 4, 3, 4, 4, 4, 4, 4]
for i in range(N-3):
    c = [0 for _ in range(16)]
    for j in range(16):
        if j == 0:
            c[0] += cnt[0]
            c[1] += cnt[0]
            c[2] += cnt[0]
            c[3] += cnt[0]
        elif j == 1:
            c[4] += cnt[1]
            c[5] += cnt[1]
            c[7] += cnt[1]
        elif j == 2:
            c[8] += cnt[2]
            c[9] += cnt[2]
            c[11] += cnt[2]
        elif j == 3:
            c[12] += cnt[3]
            c[13] += cnt[3]
            c[14] += cnt[3]
            c[15] += cnt[3]
        elif j == 4:
            c[4] += cnt[4]
            c[5] += cnt[4]
            c[6] += cnt[4]
            c[7] += cnt[4]
        elif j == 5:
            c[0] += cnt[5]
            c[1] += cnt[5]
            c[3] += cnt[5]
        elif j == 6:
            c[8] += cnt[6]
            c[9] += cnt[6]
            c[10] += cnt[6]
            c[11] += cnt[6]
        elif j == 7:
            c[12] += cnt[7]
            c[13] += cnt[7]
            c[14] += cnt[7]
            c[15] += cnt[7]
        elif j == 8:
            c[8] += cnt[8]
            c[9] += cnt[8]
            c[10] += cnt[8]
            c[11] += cnt[8]
        elif j == 9:
            c[0] += cnt[9]
            c[1] += cnt[9]
            c[2] += cnt[9]
            c[3] += cnt[9]
        elif j == 10:
            c[4] += cnt[10]
            c[5] += cnt[10]
            c[6] += cnt[10]
            c[7] += cnt[10]
        elif j == 11:
            c[12] += cnt[11]
            c[13] += cnt[11]
            c[14] += cnt[11]
            c[15] += cnt[11]
        elif j == 12:
            c[12] += cnt[12]
            c[13] += cnt[12]
            c[14] += cnt[12]
            c[15] += cnt[12]
        elif j == 13:
            c[0] += cnt[13]
            c[1] += cnt[13]
            c[2] += cnt[13]
            c[3] += cnt[13]
        elif j == 14:
            c[4] += cnt[14]
            c[5] += cnt[14]
            c[6] += cnt[14]
            c[7] += cnt[14]
        elif j == 15:
            c[8] += cnt[15]
            c[9] += cnt[15]
            c[10] += cnt[15]
            c[11] += cnt[15]
    for j in range(16):
        c[j] = c[j] % MOD
    cnt = c[:]
print(sum(cnt) % MOD)