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

using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC122D
{
    static class MainClass
    {

        static int[] s;
        static long[,,,] dp = new long[101, 4, 4, 4];
        static bool[,,,] done = new bool[101, 4, 4, 4];
        static long mod = 1000000007;

        public static void Main(string[] args)
        {

            s = Array.ConvertAll(Console.ReadLine().Split().ToArray(), int.Parse);
            long ptn = 0;
            for(int i = 0; i < 4; i++)
            {
                for(int j = 0; j < 4; j++)
                {
                    for(int k = 0; k < 4; k++)
                    {
                        done[3,i,j,k] = true;
                        if (Ok(3, i, j, k))
                        {
                            dp[3, i, j, k]++;
                        }
                    }
                }
            }
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        ptn += Dfs(s[0], i, j, k);
                    }
                }
            }
            Console.WriteLine(ptn);

        }

        public static long Dfs(int n, int w1, int w2, int w3) {
            if (n == 0)
            {
                return 1;
            }
            else if (done[n,w1,w2,w3])
            {
                return dp[n, w1, w2, w3];
            }
            else
            {
                long ptn = 0;
                for (int i = 0; i < 4; i++)
                {
                    if (Ok(i,w1, w2, w3))
                    {
                        //Console.WriteLine("OK:  i  : " + i + " w1 " + w1 + " w2 " + w2 + " w3 " + w3);
                        ptn += Dfs(n-1,i,w1,w2)%mod;
                    }
                    else
                    {
                        //Console.WriteLine("NG:  i  : " + i + " w1 " + w1 + " w2 " + w2 + " w3 " + w3);

                    }
                }
                done[n, w1, w2, w3] = true;
                dp[n, w1, w2, w3] = ptn;
                //Console.WriteLine("ptn: " + ptn + " n " + n + " w1 " + w1 + " w2 " + w2 + " w3 " + w3);
                return ptn;
            }
        }

        public static bool Ok(int w1,int w2,int w3,int a)
        {
            string s1 = w1.ToString();
            string s2 = w2.ToString();
            string s3 = w3.ToString();
            string sa = a.ToString();

            if ((s1 + s2 + s3 + sa).Contains("012")) return false;
            if ((s2 + s1 + s3 + sa).Contains("012")) return false;
            if ((s1 + s3 + s2 + sa).Contains("012")) return false;
            if ((s1 + s2 + sa + s3).Contains("012")) return false;
            return true;
        }
    }
}