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 Ruby (2.3.3) (judge verdict: Runtime Error)

#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;


void solve(long long X, long long Y, long long Z, long long K, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    vector<long long> ab_ans;
    for (int i = 0; i < X; i++) {
        for (int j = 0; j < Y; j++) {
            ab_ans.push_back(A[i] + B[j]);
        }
    }
    std::sort(ab_ans.begin(), ab_ans.end(), std::greater<long long>() );
    long long ab_max = 3000;
    vector<long long> abc_ans;
    long long min_num = min(ab_max, X * Y);
    for (int i = 0; i < min_num; i++) {
        for (int j = 0; j < Z; j++) {
            abc_ans.push_back(ab_ans[i] + C[j]);
        }
    }
    std::sort(abc_ans.begin(), abc_ans.end(), std::greater<long long>() );
    for (int i=0; i<K; i++) {
        cout << abc_ans[i] << endl;
    }
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    long long Y;
    long long Z;
    long long K;
    cin >> X >> Y >> Z >> K;
    std::vector<long long> A(X);
    for(int i = 0 ; i < X ; i++){
        cin >> A[i];
    }
    std::vector<long long> B(Y);
    for(int i = 0 ; i < Y ; i++){
        cin >> B[i];
    }
    std::vector<long long> C(Z);
    for(int i = 0 ; i < Z ; i++){
        cin >> C[i];
    }
    solve(X, Y, Z, K, std::move(A), std::move(B), std::move(C));
    return 0;
}