Language: C++

#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int N = 5000 + 7;

int M;

int dp[N][N];
int op[N][N];

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, mod;
  cin >> n >> mod;
  M = mod;
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      if (i) {
        dp[i][j] += dp[i - 1][j];
      }
      if (j >= i) {
        dp[i][j] += dp[i][j - i];
      }
      if (dp[i][j] >= M) dp[i][j] -= M;
    }
  }
  for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) op[i][j] = dp[i][j];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      dp[i][j] += dp[i][j - 1];
      if (dp[i][j] >= M) dp[i][j] -= M;
    }
  }
  if (n % 2) {
    int len = n / 2;
    int ret = 0;
    bool first = false;
    for (int x = 1; x <= n; x++) {
      int mx = n - x + 1;
      if (mx < x) {
        if (!first) {
          for (int len = n / 2; len >= 1; len--) {
            for (int s = mx; s <= n; s++) {
              for (int t = mx; t <= s; t++) {
                op[len][s] -= op[len - 1][s - t];
                if (op[len][s] < 0) op[len][s] += M;
              }
            }
          }
        } else {
          for (int len = n / 2; len >= 1; len--) {
            for (int s = mx; s <= n; s++) {
              if (!op[len - 1][s - mx]) break;
              if (!op[len][s]) break;
              op[len][s] -= op[len - 1][s - mx];
              if (op[len][s] < 0) op[len][s] += M;
            }
          }
        }
        first = true;
      }
      for (int j = 0; j < x; j++) {
        ret = (ret + dp[len][x - 1 - j] * (ll) op[len][j]) % M;
      }
    }
    cout << ret << endl;
  } else {
    int len = n / 2 - 1;
    int ret = 0;
    for (int x = 1; x <= n; x++) {
      int mx = n - x + 1;
      if (!first) {
          for (int len = n / 2; len >= 1; len--) {
            for (int s = mx; s <= n; s++) {
              for (int t = mx; t <= s; t++) {
                op[len][s] -= op[len - 1][s - t];
                if (op[len][s] < 0) op[len][s] += M;
              }
            }
          }
        } else {
          for (int len = n / 2; len >= 1; len--) {
            for (int s = mx; s <= n; s++) {
              if (!op[len - 1][s - mx]) break;
              if (!op[len][s]) break;
              op[len][s] -= op[len - 1][s - mx];
              if (op[len][s] < 0) op[len][s] += M;
            }
          }
        }
        first = true;
      }
      for (int i = 0; i < x; i++) {
        ret = (ret + dp[len + 1][x - 1 - i] * (ll) op[len][i]) % M;
      }
    }
    cout << ret << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:106:12: error: 'first' was not declared in this scope
  106 |       if (!first) {
      |            ^~~~~
a.cc:125:9: error: 'first' was not declared in this scope
  125 |         first = true;
      |         ^~~~~
a.cc:127:27: error: 'x' was not declared in this scope
  127 |       for (int i = 0; i < x; i++) {
      |                           ^
a.cc:131:13: error: 'ret' was not declared in this scope
  131 |     cout << ret << endl;
      |             ^~~
a.cc: At global scope:
a.cc:133:1: error: expected declaration before '}' token
  133 | }
      | ^