#include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; #include int main() { int n, m; cin >> n >> m; atcoder::modint::set_mod(m); vector dp1(n + 1, 0); dp1[1] = dp1[2] = 1; array dp2{}, nxt{}; FOR(a, 1, 3) REP(b, a + 1) ++dp2[a * 3 + b]; FOR(i, 3, n + 1) { FOR(x, 1, 3) for (int y = 0; y <= x && y <= 2; ++y) { const int id = x * 3 + y; if (dp2[id] == 0) continue; for (int a = 0; a <= 1 && a <= y; ++a) { dp1[i] += dp1[i - 1] * dp2[id] * (x == 1 || y == 1 || a == 1 ? 1 : i * 2 - 4); } } fill(nxt.begin(), nxt.end(), 0); FOR(x, 3, 5) for (int y = 2; y <= x && y <= 4; ++y) { const int id = (x - 2) * 3 + (y - 2); if (dp2[id] == 0) continue; for (int a = 1; a <= y && a <= 3; ++a) for (int b = 0; b <= a && b <= 2; ++b) { nxt[min(a, 2) * 3 + b] += dp2[id] * (x == 3 || y == 3 || a == 3 ? 1 : i * 2 - 4) * (y == 2 || a == 2 || b == 2 ? 1 : i * 2 - 3); } } dp2.swap(nxt); } atcoder::modint ans = dp1[n]; FOR(i, 1, n * 2) ans *= i; cout << ans.val() << '\n'; return 0; }