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++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

ll dp[110][4][4][4] = {};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll a = 0;
    ll g = 1;
    ll c = 2;
    ll t = 3;

    // input
    ll N;
    cin >> N;

    FOR(i, 0, 4){
        FOR(j, 0, 4){
            FOR(k, 0, 4){
                dp[2][i][j][k] = 1;
            }
        }
    }
    // agc
    dp[2][a][g][c] = 0;
    dp[2][a][c][g] = 0;
    dp[2][g][a][c] = 0;

    FOR(i, 2, N){
        FOR(l, 0, 4){
            FOR(m, 0, 4){
                FOR(n, 0, 4){
                    FOR(o, 0, 4){
                        if(l==a && m==g && n==c) continue;
                        if(l==a && m==c && n==g) continue;
                        if(l==g && m==a && n==c) continue;
                        
                        // A*GC
                        if(o==c && l==a && n==g) continue;
                        // AG*C
                        if(o==c && l==a && m==g) continue;

                        dp[i][m][n][o] += dp[i-1][l][m][n];
                        dp[i][m][n][o] %= mod;
                    }
                }
            }
        }

        dp[i][a][g][c] = 0;
        dp[i][a][c][g] = 0;
        dp[i][g][a][c] = 0;
    }

    ll sum = 0;
    FOR(l, 0, 4){
        FOR(m, 0, 4){
            FOR(n, 0, 4){
                sum += dp[N-1][l][m][n];
                sum %= mod;
            }
        }
    }

    p(sum);

    return 0;
}