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 JavaScript (node.js v5.12) (judge verdict: Runtime Error)

"use strict";
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};
function buildArray(...r){let e=0;for(let n=r.length;n>0;n--){const t=r[n-1];if("number"!=typeof t)return void console.error("Arguments must be number");e=Array(t).fill().map(()=>JSON.parse(JSON.stringify(e)))}return e}

function main(input) {
  const o = new I(input, String);

  const N = o.a();

  const dp = buildArray(Number(N + 10), 4, 4, 4);

  dp[0][3][3][3] = 1;
  for (let i = 1; i <= N; i++) {
    for (let s1 = 0; s1 < 4; s1++) {
      for (let s2 = 0; s2 < 4; s2++) {
        for (let s3 = 0; s3 < 4; s3++) {
          if (dp[i - 1][s1][s2][s3] === 0) continue;

          for (let a = 0; a < 4; a++) {
            if (s2 === 0 && s3 === 2 && a ===1) continue;
            if (s2 === 0 && s3 === 1 && a ===2) continue;
            if (s2 === 2 && s3 === 0 && a ===1) continue;
            if (s1 === 0 && s2 === 2 && a ===1) continue;
            if (s1 === 0 && s3 === 2 && a ===1) continue;
            dp[i][s2][s3][a] += dp[i - 1][s1][s2][s3];
          }
        }
      }
    }
  }

  let total = 0;
  for (let s1 = 0; s1 < 4; s1++) {
    for (let s2 = 0; s2 < 4; s2++) {
      for (let s3 = 0; s3 < 4; s3++) {
        total += dp[N][s1][s2][s3];
      }
    }
  }
  console.log(total);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));