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)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

type Mint = kyopro_lib::modint::Mint1_000_000_007;
fn g(a: i32, b: i32, c: i32, d: i32) -> bool {
    (a, b, c) != (0, 1, 2) && (b, c, d) != (0, 1, 2)
}
fn f(a: i32, b: i32, c: i32, d: i32) -> bool {
    g(a, b, c, d) && g(b, a, c, d) && g(a, c, b, d) && g(a, b, d, c)
}

fn main() {
    input! {
        n: usize,
    }

    let mut s = std::collections::BTreeMap::new();
    for i in 0..4 {
        for j in 0..4 {
            for k in 0..4 {
                if f(-1, i, j, k) {
                    s.insert((i, j, k), Mint::new(1));
                }
            }
        }
    }

    for _ in 3..n {
        let mut s2 = std::collections::BTreeMap::new();
        for ((i, j, k), x) in &s {
            for l in 0..4 {
                if f(*i, *j, *k, l) {
                    *s2.entry((*j, *k, l)).or_insert(Mint::new(0)) += *x;
                }
            }
        }
        s = s2;
    }
    let mut res = Mint::new(0);
    for (_, x) in s {
        res += x;
    }
    println!("{}", res.val());
}
*/

fn main() {
    let exe = "/tmp/binCABD84DB";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";