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

namespace Algorithm
{
    class Program
    {
        const int Mod = 1000000007;
        static long[,,,] dp = new long[101, 4, 4, 4];
        static void Main(string[] args)
        {
            // 写経
            var N = int.Parse(Console.ReadLine());
            dp[0, 0, 0, 0] = 1;

            for (var i = 0; i < N; i++)
                for (var a = 0; a < 4; a++)
                    for (var b = 0; b < 4; b++)
                        for (var c = 0; c < 4; c++)
                            for (var d = 0; d < 4; d++)
                            {
                                if (Ng(b, c, d) || Ng(c, b, d) || Ng(b, d, c)) continue;
                                if (Ng(a, c, d) || Ng(a, b, d)) continue;
                                Add(ref dp[i + 1, b, c, d], ref dp[i, a, b, c]);
                            }
            var ans = 0L;
            for (var a = 0; a < 4; a++)
                for (var b = 0; b < 4; b++)
                    for (var c = 0; c < 4; c++)
                        Add(ref ans, ref dp[N, a, b, c]);


            Console.WriteLine(ans);
        }

        static bool Ng(int a, int b, int c)
        {
            return (a == 1 && b == 2 && c ==3);
        }
        static void Add(ref long a, ref long b)
        {
            a = (a + b) % Mod;
        }
    }
}