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;
class Program
    {
        static int name2num(string s)
        {
            int ret = 0;
            foreach (char c in s)
            {
                ret *= 4;
                ret += "ATCG".IndexOf(c);
            }
            return ret;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int A = 0, T = 1, C = 2, G = 3;
            long[] arr = new long[64];
            arr[name2num("TTT")] = 1;
            for (int i=0; i<n; i++)
            {
               long[] buf = new long[64];
               for (int j=0; j<64; j++)
               {
                   if (j%16 == name2num("AAG"))
                   {
                       foreach(char c in "ATG") buf[name2num("AG" + c.ToString())] += arr[j]; 
                   }
                   else if (j%16 == name2num("AAC"))
                   {
                       foreach(char c in "ATC") buf[name2num("AT" + c.ToString())] += arr[j];
                   }
                   else if (j%16 == name2num("AGA"))
                   {
                       foreach(char c in "ATG") buf[name2num("GA" + c.ToString())] += arr[j];
                   }
                   else if (j/16 == A && j%4 == G)
                   {
                       foreach(char c in "ATG") buf[j*4%64 + name2num(c.ToString())] += arr[j]; 
                   }
                   else if (j/4 == name2num("AG"))
                   {
                       foreach(char c in "ATG") buf[j*4%64 + name2num(c.ToString())] += arr[j]; 
                   }
                   else
                   {
                       foreach(char c in "ATGC") buf[j*4%64 + name2num(c.ToString())] += arr[j];
                   }
               }
               arr = buf;
               for (int j=0; j<64; j++) buf[j] = buf[j] % 1000000007;
            }
            long ans = 0;
            foreach (long i in arr) ans = (ans + i) % 1000000007;
            Console.WriteLine(ans);
        }
    }
    //mcs Main.cs
    //mono Main.exe