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 <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define A 0
#define G 1
#define C 2
#define T 3
#define int long long
bool ng(int a, int b, int c, int d) {
    int x[4] = {a, b, c, d};
    rep(i, 4) {
        if(i != 0) swap(x[i], x[i - 1]);
        rep(j, 2) {
            if(x[j] == A && x[j + 1] == G && x[j + 2] == C) return true;
        }
        if(i != 0) swap(x[i], x[i - 1]);
    }
    return false;
}
int dp[110][4][4][4];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    rep(i, 4) rep(j, 4) rep(k, 4) {
        if(ng(i, j, k, -1)) continue;
        dp[3][i][j][k] = 1;
    }
    REP(i, 3, N - 1) {
        rep(a, 4) {
            rep(b, 4) {
                rep(c, 4) {
                    rep(d, 4) {
                        if(ng(a, b, c, d)) continue;
                        dp[i + 1][b][c][d] += dp[i][a][b][c];
                        dp[i + 1][b][c][d] %= mod;
                    }
                }
            }
        }
    }
    int ans = 0;
    rep(i, 4) rep(j, 4) rep(k, 4) ans = (ans + dp[N][i][j][k]) % mod;
    cout << ans << endl;

    return 0;
}