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 <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(var,n)  for(int var=0;var<(n);++var)

const ll MOD=1000000007LL;

ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }

//xのe丈の高速計算
ll POW(ll x, ll e) {
  //最初1
  ll v=1;
  //後処理は、xの二乗を取って、e/2する。
  //for (;something;)はwhile(something)に同じ
  for(; e; x=MUL(x,x), e>>=1) {
    //もしeが奇数なら、vにxをかける。
    if (e&1) v = MUL(v,x);
  }
  return v;
}


//a,b,c,d  1<->A, 2<->G, 3<->C, 4<->Tに対応?で、admissible出ない組み合わせがbad==true
inline bool bad(int a,int b,int c,int d){
    if (        b==1 && c==2 && d==3) return true;
    if (a==1         && c==2 && d==3) return true;
    if (        b==2 && c==1 && d==3) return true;
    if (        b==1 && c==3 && d==2) return true;
    if (a==1 && b==2         && d==3) return true;
    return false;
}


ll solve(int N) {
  //n のとき、a,b,c,dそれぞれ5通り試すの。
    ll dp[101][256][2];
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int i=0;i<N;i++){
        for (int a=0;a<4;a++) for (int b=0;b<4;b++) for (int c=0;c<4;c++) for (int d=0;d<4;d++) {
            //何か5進法で表記しておるな？
            int abcd = ((a*4+b)*4+c)*4+d;
            for (int e=0; e<4; ++e) {
              //
                int bcde = ((b*4+c)*4+d)*4+e;
                //直前n-1でbadになるかどうかと、nでbadになるかどうかで4通りあるが、それぞれ
                //
                bool _bad = bad(b,c,d,e);
                for (int j=0;j<2;j++){
                    (dp[i+1][bcde][j || _bad] += dp[i][abcd][j]) %= MOD;
                }
            }
        }
    }
    ll ans = 0;
    for (int i=0;i<256;i++) {
        (ans += dp[N][i][1]) %= MOD;
    }
    return SUB(POW(4,N), ans);
}

int main() {
    int N; cin >> N;
    cout << solve(N) << endl;
    return 0;
}