#include #include #include int main() { using mint = atcoder::modint; int n, m; std::cin >> n >> m; mint::set_mod(m); mint ans = 1; std::array, 2> pd{}; pd[0][0] = { 1 }; for (int x = 0; x < 2 * n - 3; ++x) { // pd: dp(x,*,*), dp: dp(x+1,*,*) std::array, 2> dp{}; for (int f : { 0, 1 }) { // T: tofu, R: red ball, W: white ball // g=0 (RTRT...RT) { constexpr int g = 0; const mint val = pd[f][g]; // W dp[0][0] += val; // R dp[1][1] += val; } // g=1 (RTRT...TR) { constexpr int g = 1; const mint val = pd[f][g]; // W dp[0][1] += val; // TR mint weightR = f ? 1 : x; // if f=0 then vertex (x,_) has degree of 1 dp[1][1] += val * weightR; // TW mint weightW = weightR * (x + 1); // vertex (x+1,_) has degree of 1 dp[0][0] += val * weightW; } } dp.swap(pd); if (x % 2 == 0) { // level x/2+1 ans *= pd[0][1] + pd[1][1]; } } // level n for (int x = 1; x <= 2 * n - 1; ++x) { ans *= x; } std::cout << ans.val() << std::endl; }