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: Accepted)

#include <stdio.h>

int main(){
	int n;
	int mod = 1e9+7;
	scanf("%d",&n);
	//ACGT以外の文字を含まない
	//AGCを部分列として含まない
	//A=0 G = 1 C = 2 T=3と考えると
	//012,021,102,0?12,01?2の5つがダメ
	//dp[x][c3][c2][c1];は長さxで一番右からc3c2c1と並んでおり合計数
	//dp[3][0][0][0]は長さ3で末尾に000が並んでいるってわけ
	int dp[101][4][4][4]={};
	int i,j,k;
	//長さ3の文字の合計数を1にセットする
	for(i=0;i<4;i++)for(j=0;j<4;j++)for(k=0;k<4;k++)dp[3][i][j][k]=1;
	//条件を満たさない奴の数を0にセットする
	dp[3][0][1][2]=0;
	dp[3][0][2][1]=0;
	dp[3][1][0][2]=0;
	int a,b,c,d;
	//現在の状態から追加できるかどうかを調べる
	for(i=3;i<n;i++){
		//dpの[][a][b][c]から新たにdを追加できるかどうか調べる
		for(a=0;a<4;a++){
			for(b=0;b<4;b++){
				for(c=0;c<4;c++){
					for(d=0;d<4;d++){
						if(dp[i][a][b][c]==0)continue;
						if(b==0&&c==1&&d==2)continue;
						if(b==0&&c==2&&d==1)continue;
						if(a==0&&c==1&&d==2)continue;
						if(a==0&&b==1&&d==2)continue;
						if(b==1&&c==0&&d==2)continue;
						dp[i+1][b][c][d]+= dp[i][a][b][c];
						dp[i+1][b][c][d]%=mod;
					}
				}
			}
		}
	}
	int ans = 0;
	for(a=0;a<4;a++){
			for(b=0;b<4;b++){
				for(c=0;c<4;c++){
					ans+=dp[n][a][b][c];
					ans %=mod;
				}
			}
	}
	printf("%d",ans);
}