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)

#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: u64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut memo = vec![vec![vec![vec![0; 4]; 4]; 4]; n+3];
    for a in 0..4 {
        for b in 0..4 {
            for c in 0..4 {
                if a == 1 && b == 2 && c == 3 { continue; }
                if a == 1 && b == 3 && c == 2 { continue; }
                if a == 2 && b == 1 && c == 3 { continue; }
                memo[0][a][b][c] = 1;
            }}}
    for i in 1..n+1 {
        for a in 0..4 {
            for b in 0..4 {
                for c in 0..4 {
                    for d in 0..4 {
                if b == 1 && c == 2 && d == 3 { continue; }
                if b == 1 && c == 3 && d == 2 { continue; }
                if b == 2 && c == 1 && d == 3 { continue; }
                if a == 1 && b == 2 && d == 3 { continue; }
                if a == 1 && c == 2 && d == 3 { continue; }
                        memo[i][b][c][d] += memo[i-1][a][b][c];
                        memo[i][b][c][d] %= M;
                    }
                }
            }
        }
    }

    // Please Update rustc
    // put!(memo[n-3].iter().flatten().flatten().fold(0, |a,s|(a+s)%M));
    {
        let mut ans = 0;
        for a in 0..4 {
            for b in 0..4 {
                for c in 0..4 {
                    ans += memo[n-3][a][b][c];
                    ans %= M;
                }}}
        put!(ans);
    }

}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}