#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int MOD = 1000000007; const char EMPTY = '_'; string normalizeState(const string& s) { char newChar = 'A'; map to; to[EMPTY] = EMPTY; string t; for(char c : s){ if(to.find(c) == to.end()){ to[c] = newChar; ++ newChar; } t.push_back(to[c]); } return t; } int main() { int n; cin >> n; map, long long> dp; dp[make_pair("____", 0)] = 1; long long ans = 0; for(int y=0; y<=n; ++y){ map, long long> nextDp; for(const auto& p : dp){ string s = p.first.first; bitset<4> upper; for(int i=0; i<4; ++i) upper[i] = (s[i] != EMPTY); for(int i=0; i<(1<<3); ++i){ bitset<5> side(i << 1); bool ng = false; int cnt = p.first.second; for(int j=0; j<4; ++j){ if(upper[j] && side[j] && side[j+1]) ng = true; if(upper[j] || side[j] || side[j+1]) ++ cnt; } if(ng) continue; string t = s; int sameCnt = 0; char newChar = 'Z'; for(int j=0; j<4; ++j){ if(!side[j]){ int k = j; while(side[k+1]) ++ k; if(j < k){ if(s[j] == EMPTY && s[k] == EMPTY){ t[j] = t[k] = newChar; -- newChar; } else if(s[j] == EMPTY || s[k] == EMPTY){ swap(t[j], t[k]); } else if(s[j] == s[k]){ t[j] = t[k] = EMPTY; ++ sameCnt; } else{ replace(t.begin(), t.end(), s[j], s[k]); t[j] = t[k] = EMPTY; } } } } if(sameCnt >= 2 || (sameCnt == 1 && t != "____")) continue; if(t == "____" && cnt > 0){ ans += cnt * p.second; ans %= MOD; } else{ t = normalizeState(t); nextDp[make_pair(t, cnt)] += p.second; nextDp[make_pair(t, cnt)] %= MOD; } } } dp.swap(nextDp); } cout << ans << endl; return 0; }