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 Rust (1.15.1) (judge verdict: Accepted)

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

const R: u64 = 1000000007;

fn main() {
    let n: usize = read();
    /*
    if n == 3 {
        println!("{}", 4 * 4 * 4 - 3);
        return;
    }

    let mut dp: Vec<Vec<Vec<Vec<Vec<u32>>>>> = vec![vec![vec![vec![vec![1; 4]; 4]; 4]; 4]; 101];
    for p in 0..4 {
        dp[4][p][0][2][1] = 0;
    }
    for s in 0..4 {
        dp[4][0][2][1][s] = 0;
    }
    for q in 0..4 {
        dp[4][0][q][2][1] = 0;
    }
    for p in 0..4 {
        dp[4][p][2][0][1] = 0;
    }
    for s in 0..4 {
        dp[4][2][0][1][s] = 0;
    }
    for p in 0..4 {
        dp[4][p][0][1][2] = 0;
    }
    for s in 0..4 {
        dp[4][0][1][2][s] = 0;
    }
    for r in 0..4 {
        dp[4][0][2][r][1] = 0;
    }

    for i in 5..(n + 1) {
        for p in 0..4 {
            for q in 0..4 {
                for r in 0..4 {
                    for s in 0..4 {}
                }
            }
        }
    }
    */

    let mut dp: Vec<Vec<Vec<Vec<u64>>>> = vec![vec![vec![vec![1; 4]; 4]; 4]; 101];
    dp[3][0][2][1] = 0;
    dp[3][2][0][1] = 0;
    dp[3][0][1][2] = 0;

    for i in 4..(n + 1) {
        for q in 0..4 {
            for r in 0..4 {
                for s in 0..4 {
                    if q == 0 && r == 2 && s == 1 {
                        dp[i][q][r][s] = 0;
                    } else if q == 2 && r == 0 && s == 1 {
                        dp[i][q][r][s] = 0;
                    } else if q == 0 && r == 1 && s == 2 {
                        dp[i][q][r][s] = 0;
                    } else if r == 2 && s == 1 || q == 2 && s == 1 {
                        dp[i][q][r][s] =
                            (dp[i - 1][1][q][r] + dp[i - 1][2][q][r] + dp[i - 1][3][q][r]) % R;
                    } else {
                        dp[i][q][r][s] = (dp[i - 1][0][q][r]
                            + dp[i - 1][1][q][r]
                            + dp[i - 1][2][q][r]
                            + dp[i - 1][3][q][r])
                            % R;
                    }
                }
            }
        }
    }

    let mut ans: u64 = 0;
    for q in 0..4 {
        for r in 0..4 {
            for s in 0..4 {
                ans = (ans + dp[n][q][r][s]) % R;
            }
        }
    }
    println!("{}", ans);
}