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 Kotlin (1.0.0) (judge verdict: Accepted)

fun initList(lmChar : MutableList<MutableList<MutableList<MutableList<MutableList<Long>>>>>){
    val l3 = mutableListOf<MutableList<MutableList<MutableList<Long>>>>()
    for(b3 in 0..3) {
        val l2 = mutableListOf<MutableList<MutableList<Long>>>()
        for (b2 in 0..3) {
            val l1 = mutableListOf<MutableList<Long>>()
            for (b1 in 0..3) {
                val l0 = mutableListOf<Long>()
                for (b0 in 0..3) {
                    if(b0 + b1 + b2 + b3 == 0) l0.add(1L)
                    else l0.add(0L)
                }
                l1.add(l0)
            }
            l2.add(l1)
        }
        l3.add(l2)
    }
    lmChar.add(l3)
}

fun nextStep(lmChar : MutableList<MutableList<MutableList<MutableList<MutableList<Long>>>>>, i : Int){
    val l3 = mutableListOf<MutableList<MutableList<MutableList<Long>>>>()
    for(b3 in 0..3) {
        val l2 = mutableListOf<MutableList<MutableList<Long>>>()
        for (b2 in 0..3) {
            val l1 = mutableListOf<MutableList<Long>>()
            for (b1 in 0..3) {
                val l0 = mutableListOf<Long>()
                for (b0 in 0..3) {
                    val flag = calculator(listOf(b3, b2, b1, b0))
                    val value =
                        lmChar[i - 1][1][b3][b2][b1] + lmChar[i - 1][2][b3][b2][b1] + lmChar[i - 1][3][b3][b2][b1] + lmChar[i - 1][0][b3][b2][b1]
                    l0.add((value % 1000000007L) * flag)
                }
                l1.add(l0)
            }
            l2.add(l1)
        }
        l3.add(l2)
    }
    lmChar.add(l3)
}

fun calculator(l : List<Int>) : Long{
    if(l[0] == 1 && l[1] == 2 && l[2] == 3) return 0L
    if(l[0] == 2 && l[1] == 1 && l[2] == 3) return 0L
    if(l[0] == 1 && l[1] == 3 && l[2] == 2) return 0L
    if(l[1] == 1 && l[2] == 2 && l[3] == 3) return 0L
    if(l[1] == 2 && l[2] == 1 && l[3] == 3) return 0L
    if(l[1] == 1 && l[2] == 3 && l[3] == 2) return 0L
    if(l[0] == 1 && l[2] == 2 && l[3] == 3) return 0L
    if(l[0] == 1 && l[1] == 2 && l[3] == 3) return 0L
    return 1L
}

fun main(args: Array<String>){
    val n = readLine()!!.toInt()
    val lmChar = mutableListOf<MutableList<MutableList<MutableList<MutableList<Long>>>>>()
    initList(lmChar)
    for(i in 1..n) nextStep(lmChar, i)
    var retValue = 0L
    for(b3 in 0..3){
        for(b2 in 0..3){
            for(b1 in 0..3){
                for(b0 in 0..3){
                    retValue += lmChar[n][b3][b2][b1][b0]
                    retValue %= 1000000007L
                }
            }
        }
    }
    println(retValue)
}