#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n); i >= 0; i--)
#define revrepr(i, a, b) for (int i = (a); i >= b; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T>
void print(const vector<T> &v, const string &spacer) { rep(i, v.size()) cout << (0 < i ? spacer : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &spacer) { for (const auto &v: vv) print(v, spacer); }

//from https://github.com/spaghetti-source/algorithm/blob/master/number_theory/modular_arithmetics.cc
struct ModInt {
    static ll mod;
    ll val;
    ModInt(ll v = 0) : val(v % mod) {}
    ModInt operator-() const { return ModInt(val ? mod - val : val); }
    ModInt &operator+=(ModInt a) {
        if ((val += a.val) >= mod) val -= mod;
        return *this;
    }
    ModInt &operator-=(ModInt a) {
        if ((val -= a.val) < 0) val += mod;
        return *this;
    }
    ModInt &operator*=(ModInt a) {
        val = (__uint128_t(val) * a.val) % mod;
        return *this;
    }
    ModInt &operator/=(ModInt a) {
        ll u = 1, v = a.val, s = 0, t = mod;
        while (v) {
            ll q = t / v;
            swap(s -= u * q, u);
            swap(t -= v * q, v);
        }
        a.val = (s < 0 ? s + mod : s);
        val /= t;
        return (*this) *= a;
    }
    ModInt inv() const { return ModInt(1) /= (*this); }
    bool operator<(ModInt x) const { return val < x.val; }
};
ll ModInt::mod = 1e9 + 7;

ostream &operator<<(ostream &os, ModInt a) {
    os << a.val;
    return os;
}
ModInt operator+(ModInt a, ModInt b) { return a += b; }
ModInt operator-(ModInt a, ModInt b) { return a -= b; }
ModInt operator*(ModInt a, ModInt b) { return a *= b; }
ModInt operator/(ModInt a, ModInt b) { return a /= b; }
ModInt pow(ModInt a, ll e) {
    ModInt x(1);
    for (; e > 0; e /= 2) {
        if (e % 2 == 1) x *= a;
        a *= a;
    }
    return x;
}

ModInt comb(int n, int k) {
    ModInt x = 1, y = 1;
    rep(i, k) {
        x *= n - i;
        y *= i + 1;
    }
    return x / y;
}

int main() {
    int n;
    cin >> n;
    const vector<string> forbidden_strs = {"?AGC", "A?GC", "?GAC", "?ACG", "AG?C"};
    using ci = pair<char, int>;
    map<char, int> mp = {ci('T', 0), ci{'A', 1}, ci{'C', 2}, ci{'G', 3}};
    vector<int> masks(5), forbidden_nums(5);
    const int l6 = (1 << 6) - 1;
    rep(i, 5) {
        int m = 0;
        rep(j, 4) {
            m <<= 2;
            if (forbidden_strs.at(i).at(j) != '?') m |= 3;
        }
        masks.at(i) = m;
    }
    rep(i, 5) {
        int num = 0;
        rep(j, 4) {
            num <<= 2;
            if (forbidden_strs.at(i).at(j) != '?') num |= mp[forbidden_strs.at(i).at(j)];
        }
        forbidden_nums.at(i) = num;
    }
    
    auto is_ok = [&](int num){
        rep(i, 5) if ((num & masks.at(i)) == forbidden_nums.at(i)) return false;
        return true;
    };
    
    //dp[i][j] 条件を満たすi番目の末尾6文字がj
    vector<vector<ModInt>> dp(n + 1, vector<ModInt>(1 << 6));
    dp[0][0] = 1;
    rep(i, n) rep(j, 1 << 6) rep(c, 4) {
        int num = j << 2 | c;
        if (is_ok(num)) dp[i + 1][num & l6] += dp[i][j];
    }
    
    ModInt ans = 0;
    rep(i, 1 << 6) ans += dp[n][i];
    cout << ans << endl;
}

Measured memory_bytes: 256