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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<iostream>
#include <cmath>
using namespace std;

int lenght(string str){
  int i=0;
 while(str[i]){
     i++;
 }
 return i;
}


int sub(char c1, char c2, char c3, int n, int N, int count){
    if(n==N){
        return 1;
    }
    if(c2=='A'&&c3=='C'){
        return count + sub('A','C','A',n+1, N,count) +  sub('A','C','T',n+1, N,count)+ sub('A','C','C',n+1, N,count);
    }
    if(c2=='A'&&c3=='G'){
        return count + sub('A','G','A',n+1, N,count) +  sub('A','G','T',n+1, N,count)+ sub('A','G','G',n+1, N,count);
    }
    if(c2=='G'&&c3=='A'){
        return count + sub('A','G','A',n+1, N,count) +  sub('A','G','T',n+1, N,count)+ sub('A','G','G',n+1, N,count);
    }
    if(c1=='A'&&c3=='G'){
        return count + sub(c2,'G','A',n+1, N,count) +  sub(c2,'G','T',n+1, N,count)+ sub(c2,'G','G',n+1, N,count);
    }
    if(c1=='A'&&c2=='G'){
        return count + sub('G',c3,'A',n+1, N,count) +  sub('G',c3,'T',n+1, N,count)+ sub('G', c3, 'G',n+1, N,count);
    }
    return count + sub(c2, c3, 'A', n+1, N,count) +  sub(c2, c3, 'C', n+1, N,count)+ sub(c2, c3, 'G',n+1, N,count)+ sub(c2, c3, 'T',n+1, N,count);
}

int sub2(char c1, char c2, int n, int N, int count){
    if(n==N)
        return 1;
    if(c1=='A'&&c2=='G'){
        return count + sub('A','G','A',n+1, N,count) +  sub('A','G','G',n+1, N,count)+ sub('A', 'G', 'T',n+1, N,count);
    }
    if(c1=='A'&&c2=='C'){
        return count + sub('A','C','A',n+1, N,count) +  sub('A','C','C',n+1, N,count)+ sub('A', 'C', 'T',n+1, N,count);
    }
    if(c1=='G'&&c2=='A'){
        return count + sub('G','A','A',n+1, N,count) +  sub('G','A','G',n+1, N,count)+ sub('G', 'A', 'T',n+1, N,count);
    }
    return count + sub(c1,c2,'A',n+1, N,count) +  sub(c1,c2,'G',n+1, N,count)+ sub(c1, c2, 'T',n+1, N,count) + sub(c1, c2, 'C',n+1, N,count);
}

int main(){
    int N, num;
    cin >> N;
    
    num = sub2('A','A',2,N,0) + sub2('A','G',2,N,0) + sub2('A','C',2,N,0) +sub2('A','T',2,N,0)+
    sub2('G','A',2,N,0) + sub2('G','G',2,N,0) + sub2('G','C',2,N,0) + sub2('G','T',2,N,0)+
    sub2('C','A',2,N,0) + sub2('C','G',2,N,0) + sub2('C','C',2,N,0) + sub2('C','T',2,N,0)+
    sub2('T','A',2,N,0) + sub2('T','G',2,N,0) + sub2('T','C',2,N,0) + sub2('T','T',2,N,0);
    
    if(num > pow(10,9)+7)
      cout << num%(int)(pow(10,9)+7) << endl;
    else
      cout << num << endl;
    
    return 0;
}