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 (GCC 5.4.1) (judge verdict: Runtime Error)

#include<stdio.h>
#include<string.h>

int ru4(int a){
	int i,r=1;
	for(i=0;i<a;i++)r=r*4;
	return r;
}

int main(){
	int i,a=0,n,ans=0;
	char s[1024][13]={0};
	scanf("%d",&n);
	n=ru4(n);
	for(a=0;a<n;a++){
		int acp=a,j=0;
		char stmp[6]={0};
		while(acp>0){
			stmp[j]=acp%4;
			acp/=4;
			j++;
		}
		for(j=0;j<5;j++){
			if(stmp[j]==0)stmp[j]='A';
			if(stmp[j]==1)stmp[j]='G';
			if(stmp[j]==2)stmp[j]='C';
			if(stmp[j]==3)stmp[j]='T';
		}
		strcpy(s[a],stmp);
	}
	for(i=0;i<n;i++){
		int j;
		int f=0;
		for(j=0;j<3;j++){
			if(s[i][j]=='A'&&s[i][j+1]=='G'&&s[i][j+2]=='C')f=1;
			if(s[i][j]=='G'&&s[i][j+1]=='A'&&s[i][j+2]=='C')f=1;
			if(s[i][j]=='A'&&s[i][j+1]=='C'&&s[i][j+2]=='G')f=1;
		}
		for(j=0;j<2;j++){
			if(s[i][j]=='A'&&s[i][j+1]=='G'&&s[i][j+3]=='C')f=1;
			if(s[i][j]=='A'&&s[i][j+2]=='G'&&s[i][j+3]=='C')f=1;
		}
		if(f==0)ans++;
	}
//	for(i=0;i<1024;i++)printf("%s\n",s[i]);
	printf("%d\n",ans);
	return 0;
}