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 <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll n = inl();
        ll A = 0, C = 1, G = 2, T = 3;

        ll dp[n + 1][4][4][4];
        rep(i, n + 1) rep(j, 4) rep(k, 4) rep(l, 4) dp[i][j][k][l] = 0;
        // dp[i][j][k][l]: i文字目までで, i文字目がj, i+1文字目がk, i+2文字目がl, i+3文字目がm
        /*
         * ダメな列
         * AGC, ACG, GAC
         * AxGC, AGxC
         */
        rep(i, n) {
            rep(j, 4) {
                rep(k, 4) {
                    rep(l, 4) {
                        if (j == C && k == G && l == A) continue;
                        if (j == C && k == A && l == G) continue;
                        if (j == G && k == C && l == A) continue;

                        if (i < 3) {
                            dp[i + 1][j][k][l] = 1;
                        } else {
                            rep(m, 4) {
                                if (j == C && k == G && m == A) continue;
                                if (j == C && l == G && m == A) continue;

                                dp[i + 1][j][k][l] += dp[i][k][l][m];
                                dp[i + 1][j][k][l] %= mod;
                            }
                        }
                    }
                }
            }
        }
        ll ans = 0;
        rep(i, 4) rep(j, 4) rep(k, 4) ans += dp[n][i][j][k], ans %= mod;
        cout << ans << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}