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.Generic;
using System.Linq;



namespace CSharpSample01
{

    

    class Program
    {
        const long MOD = 1000000007;

        
        static long DP(int N)
        {
            //dp[n, t, s, f] := n文字の文字列の通りで、最後がf、最後-1がs、最後-2がtとなっている
            long[,,,] dp = new long[N + 1, 5, 5, 5];

            dp[0, 0, 0, 0] = 1;

            for(int n = 0; n < N; n++)
            {
                for (int t = 0; t < 5; t++)
                {
                    for(int s = 0; s < 5; s++)
                    {
                        for(int f = 0; f < 5; f++)
                        {
                            //dp[n, t, s, f]を使って、n+1文字目の文字nextを決める
                            for (int next = 1; next < 5; next++)
                            {
                                if (t == 1 && s == 2 && next == 3) continue;
                                if (t == 1 && f == 2 && next == 3) continue;
                                if (s == 1 && f == 2 && next == 3) continue;
                                if (s == 2 && f == 1 && next == 3) continue;
                                if (s == 1 && f == 3 && next == 2) continue;
                                dp[n + 1, s, f, next] += dp[n, t, s, f];
                                dp[n + 1, s, f, next] %= MOD;
                            }
                        }               
                    }
                }
            }

            long ans = 0;

            for(int t = 1; t < 5; t++)
            {
                for(int s = 1; s < 5; s++)
                {
                    for(int f = 1; f < 5; f++)
                    {
                        ans += dp[N, t, s, f];
                        ans %= MOD;
                    }
                }
            }

            return ans;
        }

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            Console.WriteLine(DP(N));
        }
    }
}