Language: C++

///////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <typeinfo>

using namespace std;

///////////////////////////////////////////////////////////////////////////////

#define pb push_back

struct T2 {
        long t0;
        long t1;
};

struct T3 {
        long t0;
        long t1;
        long t2;
};

void longin(long &a)
{
        cin >> a;
}

void longinl1(auto &v, long count)
{
        for (long i = 0; i < count ; ++i) {
                long a;
                cin >> a;
                v.push_back(a);
        }
}

void longinl2(auto &v, long count)
{
        for (long i = 0; i < count ; ++i) {
                long a, b;
                cin >> a >> b;
                v.push_back({a, b});
        }
}

void longinl3(auto &v, long count)
{
        for (long i = 0; i < count ; ++i) {
                long a, b, c;
                cin >> a >> b >> c;
                v.push_back({a, b, c});
        }
}

void longina(auto &v, long count)
{
        longinl1(v, count);
}

long min(const vector<long> v)
{
        long ret = (long)numeric_limits<double>::infinity();
        for (auto i : v) ret = min(ret, i);
        return ret;
}

///////////////////////////////////////////////////////////////////////////////

static long nn;
static long mod = pow(10, 9) + 7;

bool ok(const string &last4)
{
        string last3 = string(last4, 1, 3);
        string last2 = string(last4, 2, 2);
        string first2 = string(last4, 0, 2);

        if (last3 == "AGC") return false;
        if (last3 == "ACG") return false;
        if (last3 == "GAC") return false;
        if (last4[0] == 'A' && last2 == "GC") return false;
        if (last4[3] == 'C' && first2 == "AG") return false;

        return true;
}

long dfs(long cur, const string & last3)
{
        static map<string, long> *memo = new map<string, long>[nn+1];
        if (memo[cur].count(last3) > 0) {
                return memo[cur][last3];
        }

        if (cur == nn) return 1;

        long ret = 0;
        for (const char &c : "ACGT") {
                if (c == 0) continue;
                string cs = string(1, c);
                if (ok(last3 + cs)) {
                        ret = (ret + dfs(cur + 1, string(last3, 1, 2) + cs)) % mod;
                }
        }

        memo[cur][last3] = ret;
        return ret;
}

int main()
{
        long n;
        longin(n);
        nn = n;

        cout << dfs(0, "TTT");

        return 0;
}

///////////////////////////////////////////////////////////////////////////////


Compiler output:
a.cc:32:15: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   32 | void longinl1(auto &v, long count)
      |               ^~~~
a.cc:41:15: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   41 | void longinl2(auto &v, long count)
      |               ^~~~
a.cc:50:15: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   50 | void longinl3(auto &v, long count)
      |               ^~~~
a.cc:59:14: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   59 | void longina(auto &v, long count)
      |              ^~~~
a.cc: In function 'long int min(std::vector<long int>)':
a.cc:66:26: error: 'numeric_limits' was not declared in this scope
   66 |         long ret = (long)numeric_limits<double>::infinity();
      |                          ^~~~~~~~~~~~~~
a.cc:66:41: error: expected primary-expression before 'double'
   66 |         long ret = (long)numeric_limits<double>::infinity();
      |                                         ^~~~~~
a.cc: At global scope:
a.cc:74:19: error: 'pow' was not declared in this scope
   74 | static long mod = pow(10, 9) + 7;
      |                   ^~~