Problem p02974 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define owo(i, a, b) for (int i = (a); i < (b); ++i)
#define uwu(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout << "ayaya~" << endl

using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gp_hash_table<int, int> mp;*/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
ll modInv(ll a) { return binpow(a, MOD - 2); }
const double PI = acos(-1);
const double eps = -1e6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 51;
ll dp[mxN][mxN][mxN * mxN + 101];
int n, m;
int main() {
  // freopen("file.in", "r", stdin);
  // freopen("file.out", "w", stdout);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m;
  dp[0][0][0] = 1;
  owo(i, 0, n + 1) {
    owo(j, 0, i + 1) {
      owo(k, 0, m + 1) {
        // pair the next ones
        dp[i + 1][j][k + 2 * j] = (dp[i + 1][j][k + 2 * j] + dp[i][j][k]) % MOD;
        // pair one of them backwards and one fowards
        dp[i + 1][j][k + 2 * j] =
            (dp[i + 1][j][k + 2 * j] + 2 * j * dp[i][j][k]) % MOD;
        // pair them both backwards
        if (j > 0) {
          dp[i + 1][j - 1][k + 2 * j] =
              (dp[i + 1][j - 1][k + 2 * j] + j * j * dp[i][j][k]) % MOD;
        }
        // pair them both fowards
        dp[i + 1][j + 1][k + 2 * j] =
            (dp[i + 1][j + 1][k + 2 * j] + dp[i][j][k]) % MOD;
        // cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<"\n";
      }
    }
  }
  cout << dp[n][0][m] << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define owo(i, a, b) for (int i = (a); i < (b); ++i)
#define uwu(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout << "ayaya~" << endl

using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gp_hash_table<int, int> mp;*/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
ll modInv(ll a) { return binpow(a, MOD - 2); }
const double PI = acos(-1);
const double eps = -1e6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 51;
ll dp[mxN][mxN][mxN * mxN + 101];
int n, m;
int main() {
  // freopen("file.in", "r", stdin);
  // freopen("file.out", "w", stdout);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m;
  dp[0][0][0] = 1;
  owo(i, 0, n) {
    owo(j, 0, i + 1) {
      owo(k, 0, m + 1) {
        // pair the next ones
        dp[i + 1][j][k + 2 * j] = (dp[i + 1][j][k + 2 * j] + dp[i][j][k]) % MOD;
        // pair one of them backwards and one fowards
        dp[i + 1][j][k + 2 * j] =
            (dp[i + 1][j][k + 2 * j] + 2 * j * dp[i][j][k]) % MOD;
        // pair them both backwards
        if (j > 0) {
          dp[i + 1][j - 1][k + 2 * j] =
              (dp[i + 1][j - 1][k + 2 * j] + j * j * dp[i][j][k]) % MOD;
        }
        // pair them both fowards
        dp[i + 1][j + 1][k + 2 * j] =
            (dp[i + 1][j + 1][k + 2 * j] + dp[i][j][k]) % MOD;
        // cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<"\n";
      }
    }
  }
  cout << dp[n][0][m] << "\n";
  return 0;
}