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# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
class Program
{
	static void Main(string[] args)
	{
		const int A = 1;
		const int C = 2;
		const int G = 3;
		const int T = 4;

		int N = int.Parse(Console.ReadLine());

		var dic = new Dictionary<int, BigInteger>();
		
		dic.Add(A, new BigInteger(1));
		dic.Add(C, new BigInteger(1));
		dic.Add(G, new BigInteger(1));
		dic.Add(T, new BigInteger(1));

		for(int i=1; i<N; i++) {
			var temp = new Dictionary<int, BigInteger>();
			
			foreach(KeyValuePair<int, BigInteger> pair in dic){

				for(int ACGT = A; ACGT<=T; ACGT++) {
					int checkValue = (pair.Key * 10 + ACGT) % 10000;
					if(!ContainAGC(checkValue)) {
						if(temp.ContainsKey(checkValue)) {
							BigInteger bi = temp[checkValue];
							bi += pair.Value;
							temp[checkValue] = bi;
						}
						else {
							BigInteger bi = new BigInteger();
							bi += pair.Value;
							temp.Add(checkValue, bi);
						}
					}
				}
			}
			dic = temp;
		}

		BigInteger sum = 0;
		foreach(KeyValuePair<int, BigInteger> pair in dic){
			sum += pair.Value;
		}

		Console.WriteLine(sum%1000000007);
	}


	static bool ContainAGC(int val) {
		if(val/10 == 132) return true; // AGC*
		if(val/100 == 13 && val%10 == 2) return true; // AG*C
		if(val/1000 == 1 && val%100 == 32) return true; // A*GC
		if(val%1000 == 132 || val%1000 == 123 || val%1000 == 312) return true; // *AGC, *ACG, *GAC
		return false;
	}
}