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(dead_code)]
pub const M: u64 = 1_000_000_007;

#[allow(unused_macros)]
macro_rules! map {
    ( $ value : expr ; $ ( $ key : expr ) ,* ) => { { IndexMap ( vec ! [ $ ( $ key ) ,* ] . into_iter ( ) . map ( | k | ( k , $ value ) ) . collect ::< std :: collections :: HashMap < _ , _ >> ( ) ) } };
    ( $ value : expr ; $ ( $ ( $ key : expr ) ,* ) ;* ) => { map ! ( $ ( $ ( $ key ) ,* ) ;* => $ value ) };
    ( $ ( $ head : expr ) ,*; $ ( $ ( $ tail : expr ) ,* ) ;* => $ init : expr ) => { map ! [ map ! ( $ ( $ ( $ tail ) ,* ) ;* => $ init ) ; $ ( $ head ) ,* ] };
    ( $ ( $ head : expr ) ,* => $ init : expr ) => { map ! [ $ init ; $ ( $ head ) ,* ] };
}
#[derive(Debug, Clone)]
struct IndexMap<K: Eq + std::hash::Hash, V>(pub std::collections::HashMap<K, V>);
impl<K, V> std::ops::Deref for IndexMap<K, V>
where
    K: Eq + std::hash::Hash,
{
    type Target = std::collections::HashMap<K, V>;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[allow(dead_code)]
impl<'a, K, V, Q: ?Sized> std::ops::Index<&'a Q> for IndexMap<K, V>
where
    K: std::borrow::Borrow<Q> + Eq + std::hash::Hash,
    Q: Ord + Eq + std::hash::Hash,
{
    type Output = V;
    fn index(&self, index: &Q) -> &V {
        self.0.get(index).expect("no entry found for key")
    }
}
#[allow(dead_code)]
impl<'a, K, V, Q: ?Sized> std::ops::IndexMut<&'a Q> for IndexMap<K, V>
where
    K: std::borrow::Borrow<Q> + Eq + std::hash::Hash,
    Q: Ord + Eq + std::hash::Hash,
{
    fn index_mut(&mut self, index: &Q) -> &mut V {
        self.0.get_mut(index).expect("no entry found for key")
    }
}

fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut dp = vec![map![0u64;'A','G','C','T','_';'A','G','C','T','_';'A','G','C','T','_']; n + 1];
    dp[0][&'_'][&'_'][&'_'] = 1;
    for p in 0..n {
        for i in "AGCT_".chars() {
            for j in "AGCT_".chars() {
                for k in "AGCT_".chars() {
                    for l in "AGCT".chars() {
                        if (i, j, l) == ('A', 'G', 'C') {
                            continue;
                        }
                        if (i, k, l) == ('A', 'G', 'C') {
                            continue;
                        }
                        if (j, k, l) == ('A', 'G', 'C') {
                            continue;
                        }
                        if (j, k, l) == ('G', 'A', 'C') {
                            continue;
                        }
                        if (j, k, l) == ('A', 'C', 'G') {
                            continue;
                        }
                        dp[p + 1][&j][&k][&l] += dp[p][&i][&j][&k];
                        dp[p + 1][&j][&k][&l] %= M;
                    }
                }
            }
        }
    }
    let mut ret = 0u64;
    for i in "AGCT".chars() {
        for j in "AGCT".chars() {
            for k in "AGCT".chars() {
                ret += dp[n][&i][&j][&k];
                ret %= M;
            }
        }
    }
    println!("{}", ret);
}