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;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var num = Input.num;
        //TAGC
        var dp = new long[num + 1, 4, 4, 4];
        dp[0, 0, 0, 0] = 1;
        for (var i = 0; i < num; i++)
            for (var j = 0; j < 4; j++)
                for (var k = 0; k < 4; k++)
                    for (var h = 0; h < 4; h++)
                        for (var l = 0; l < 4; l++)
                            if (isOk(j, k, h, l))
                                dp[i + 1, k, h, l] = (dp[i + 1, k, h, l] + dp[i, j, k, h]) % Input.MOD;
        var res = 0L;
        for (var i = 0; i < 4; i++)
            for (var j = 0; j < 4; j++)
                for (var h = 0; h < 4; h++)
                    res = (res + dp[num, i, j, h])%Input.MOD;
        WriteLine(res);
    }
    private static bool isOk(params int[] last)
    {
        for(var i = 0; i < 4; i++)
        {
            var li = new int[4];
            Array.Copy(last, li, 4);
            if (i > 0)
                Manipulation.Swap(li, i - 1, i);
            var str = string.Join("", li);
            if (str.StartsWith("123") || str.EndsWith("123"))
                return false;
        }
        return true;
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public static Tuple<int, int, long> MakeEdge(int num1, int num2, long weight=Inf)
        => new Tuple<int, int, long>(num1, num2, weight);
    public const long Inf = (long)1e18;
    public const double eps = 1e-11;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}

public class Manipulation
{
    public static void Swap<T>(T[] array, int index1, int index2)
    {
        var tmp = array[index1];
        array[index1] = array[index2];
        array[index2] = tmp;
    }

    public static void Swap<T>(ref T obj1, ref T obj2)
    {
        var tmp = obj1;
        obj1 = obj2;
        obj2 = tmp;
    }

    public static void Insert<T>(T[] array,int index,T val,int last)
    {
        for (var i = last; i > index; i--)
            array[i] = array[i - 1];
        array[index] = val;
    }
}