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

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramD a = new ProgramD();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {
            //入力
            string s = Console.ReadLine();

            //対になる塩基を出す
            if (s == "A")
                Console.WriteLine("T");
            else if (s == "T")
                Console.WriteLine("A");
            else if (s == "G")
                Console.WriteLine("C");
            else
                Console.WriteLine("G");

        }
    }

    class ProgramB
    {
        public void main()
        {

            //入力
            string s = Console.ReadLine();

            int ans = 0;

            //先頭から調べていく
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != 'A' && s[i] != 'T' && s[i] != 'C' && s[i] != 'G')
                    continue;

                int count = 0;

                for (int j = i; j < s.Length; j++)
                {
                    if (s[j] == 'A' || s[j] == 'T' || s[j] == 'C' || s[j] == 'G')
                    {
                        count++;
                    }
                    else
                        break;
                }

                ans = Math.Max(ans, count);
            }

            //答え出力
            Console.WriteLine(ans);
            

        }
    }

    class ProgramC
    {
        public void main()
        {

            //入力
            string[] ss = Console.ReadLine().Split(' ');
            int n = int.Parse(ss[0]);
            int q = int.Parse(ss[1]);
            string s = Console.ReadLine();

            //i文字目までにACが何個あるか記録する
            int[] AC = new int[n + 1];
            int count = 0;

            for(int i = 2; i <= n;i++)
            {
                if (s[i - 1] == 'C' && s[i - 2] == 'A')
                    count++;
                AC[i] = count;
            }

            for(int i = 0;i < q;i++)
            {
                string[] temp = Console.ReadLine().Split(' ');

                Console.WriteLine(AC[int.Parse(temp[1])] - AC[int.Parse(temp[0])]);
            }

        }


    }


    class ProgramD
    {
        public void main()
        {

            //入力
            int n = int.Parse(Console.ReadLine());
            long MOD = 1000000000 + 7;
            long[,,,] dp = new long[n, 4, 4, 4];

            

            //初項
            for (int k = 0; k < 4; k++)//2つ前
                for (int l = 0; l < 4; l++)//一つ前
                    for (int m = 0; m < 4; m++)//今
                    {
                        if ((k == 0 && l == 2 && m == 1) || (k == 0 && l == 1 && m == 2) || (k == 2 && l == 0 && m == 1))
                            continue;

                        dp[2, k, l, m] = 1;
                    }


            //動的計画法
            for (int i = 3; i < n; i++)//4文字目から見る
                for (int j = 0; j < 4; j++)//3つ前
                    for (int k = 0; k < 4; k++)//2つ前
                        for (int l = 0; l < 4; l++)//一つ前
                            for (int m = 0; m < 4; m++)//今参照してる列
                            {
                                // [A, C, G, T]
                                // _AG -> C (0,2,1)
                                // _AC -> G (0,1,2)
                                // _GA -> C (2,0,1)
                                // AG_ -> C (0,2,X,1)
                                // A_G -> C (0,X,2,1)
                                if ((k == 0 && l == 2 && m == 1) || (k == 0 && l == 1 && m == 2) ||
                                    (k == 2 && l == 0 && m == 1) || (j == 0 && k == 2 && m == 1) || (j == 0 && l == 2 && m == 1))
                                    continue;

                                dp[i, k, l, m] += dp[i - 1, j, k, l];
                                dp[i, k, l, m] %= MOD;


                            }

            long ans = 0;

            for (int k = 0; k < 4; k++)//2つ前
                for (int l = 0; l < 4; l++)//一つ前
                    for (int m = 0; m < 4; m++)//今
                    {
                        ans += dp[n -1, k, l, m];
                        ans %= MOD;
                    }


            Console.WriteLine(ans);

        }

        

    }

    


}