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)

function Main(input) {
    'use strict';

    const n = parseInt(input.split("\n").shift());
    const charList = ["A", "T", "G", "C"];
    const div = 10 ** 9 + 7;
    let obj = [];
    const tmpObj = [];
    (function addChar(init){
        const queue = [init];
        while(queue.length !== 0){
            const str = queue.shift();
            if(str.length !== 3){
                charList.forEach(char => queue.push(str + char));
            }else{
                if(!str.match(/ACG|AGC|GAC/)){
                    obj[str] = 1;
                    tmpObj[str] = 0;
                } 
            }
        }
    })("");

    if(n === 3) console.log(Object.keys(obj).length);
    else{
        for(let i = 0; i < n - 3; i++){
            const newObj = Object.assign([],tmpObj);
            Object.keys(obj).forEach(key => {
                const val = obj[key];
                charList.forEach(char => {
                    const newStr = key + char;
                    if(!newStr.match(/ACG|AGC|GAC|AG.C|A.GC/)) newObj[newStr.slice(-3)] += val % div;
                })
            })
            obj = newObj;
        }
        console.log(Object.values(obj).reduce((acc, curr) => acc + curr) % div);
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));