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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define il inline

namespace io {

#define in(a) a = read()
#define out(a) write(a)
#define outn(a) out(a), putchar('\n')

#define I_int ll
inline I_int read() {
    I_int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}
char F[200];
inline void write(I_int x) {
    if (x == 0) return (void) (putchar('0'));
    I_int tmp = x > 0 ? x : -x;
    if (x < 0) putchar('-');
    int cnt = 0;
    while (tmp > 0) {
        F[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while (cnt > 0) putchar(F[--cnt]);
}
#undef I_int

}
using namespace io;

using namespace std;

#define N 100010
const ll mod = 1e9 + 7;
int n = read();
ll f[N][5][5][5];
/*
f[i][j][a][b]位置i，字符j,i-1字符a,i-2字符b

*/
map<int,string>mp;
bool check(int a,int b,int c, int d) {
	
	if(mp[a]+mp[c]+mp[b]=="AGC") return 0;
	if(mp[a]+mp[b]+mp[d]=="AGC") return 0;
	if(mp[a]+mp[c]+mp[d]=="AGC") return 0;
	
	if(mp[b]+mp[c]+mp[d]=="AGC") return 0;
	if(mp[b]+mp[d]+mp[c]=="AGC") return 0;
	
	if(mp[c]+mp[b]+mp[d]=="AGC") return 0;
	
	return 1;
}

int main() {
	if(n<=2) return outn(pow(4,n)), 0;
	mp[0]='Q'; mp[1]='A'; mp[2]='C';mp[3]='G';mp[4]='T';
	f[0][0][0][0]=1;
	 for(int i = 1; i <= n; ++i) {
	 	for(int j = 1; j <= 4; ++j) {
	 		for(int a = 0; a <= 4; ++a) {
	 			for(int b = 0; b <= 4; ++b) {
	 				for(int l = 0; l <= 4; ++l) {
	 					if(check(l,b,a,j)) (f[i][j][a][b] += f[i-1][a][b][l]) %= mod;
					 }
				 }
			 }
		 }
	 }
	 ll ans = 0;
	 for(int i = 1; i <= 4; ++i) {
	 	for(int j = 1; j <= 4; ++j) {
	 		for(int k = 1; k <= 4; ++k) {
	 			(ans+=f[n][i][j][k])%=mod;
			 }
		 }
	 }
	 outn(ans);
}