Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x) + modulo) % modulo)
#define Inf 1000000000000

// aのb乗
int beki(int a, int b, int M = modulo) {
  int x = 1;
  while (b != 0) {
    if (b & 1) {
      x = ((long long)x * a) % M;
    }
    a = ((long long)a * a) % M;
    b >>= 1;
  }
  return x;
}

// aの逆元
int gyakugen(int a) { return beki(a, modulo - 2); }

struct combi {
  deque<int> kaijou;
  deque<int> kaijou_;

  combi(int n) {
    kaijou.push_back(1);
    for (int i = 1; i <= n; i++) {
      kaijou.push_back(mod(kaijou[i - 1] * i));
    }

    int b = gyakugen(kaijou[n]);

    kaijou_.push_front(b);
    for (int i = 1; i <= n; i++) {
      int k = n + 1 - i;
      kaijou_.push_front(mod(kaijou_[0] * k));
    }
  }

  int combination(int n, int r) {
    if (r > n)
      return 0;
    int a = mod(kaijou[n] * kaijou_[r]);
    a = mod(a * kaijou_[n - r]);
    return a;
  }

  int junretsu(int a, int b) {
    int x = mod(kaijou_[a] * kaijou_[b]);
    x = mod(x * kaijou[a + b]);
    return x;
  }

  int catalan(int n) { return mod(combination(2 * n, n) * gyakugen(n + 1)); }
};

int main() {

  int N, M;
  cin >> N >> M;

  combi C(3000000);

  int ans = C.junretsu(3 * M, N - 1);

  {
    int temp = 0;

    for (int i = 2 * M + 1; i <= 3 * M; i++) {
      temp = mod(temp + C.junretsu(3 * M - i, N - 2));
    }

    temp = mod(temp * N);

    ans = mod(ans - temp);
  }

  {
    int temp = 0;
    for (int i = M + 1; i <= N; i++) {
      if ((3 * M - i) % 2 == 1)
        continue;
      int t = C.combination(N, i);
      t = mod(t * C.junretsu(N - 1, (3 * M - i) / 2));
      temp = mod(temp + t);
    }

    ans = mod(ans - temp);
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x) + modulo) % modulo)
#define Inf 1000000000000

// aのb乗
int beki(int a, int b, int M = modulo) {
  int x = 1;
  while (b != 0) {
    if (b & 1) {
      x = ((long long)x * a) % M;
    }
    a = ((long long)a * a) % M;
    b >>= 1;
  }
  return x;
}

// aの逆元
int gyakugen(int a) { return beki(a, modulo - 2); }

struct combi {
  deque<int> kaijou;
  deque<int> kaijou_;

  combi(int n) {
    kaijou.push_back(1);
    for (int i = 1; i <= n; i++) {
      kaijou.push_back(mod(kaijou[i - 1] * i));
    }

    int b = gyakugen(kaijou[n]);

    kaijou_.push_front(b);
    for (int i = 1; i <= n; i++) {
      int k = n + 1 - i;
      kaijou_.push_front(mod(kaijou_[0] * k));
    }
  }

  int combination(int n, int r) {
    if (r > n)
      return 0;
    int a = mod(kaijou[n] * kaijou_[r]);
    a = mod(a * kaijou_[n - r]);
    return a;
  }

  int junretsu(int a, int b) {
    int x = mod(kaijou_[a] * kaijou_[b]);
    x = mod(x * kaijou[a + b]);
    return x;
  }

  int catalan(int n) { return mod(combination(2 * n, n) * gyakugen(n + 1)); }
};

int main() {

  int N, M;
  cin >> N >> M;

  combi C(3000000);

  int ans = C.junretsu(3 * M, N - 1);

  {
    int temp = 0;

    for (int i = 2 * M + 1; i <= 3 * M; i++) {
      temp = mod(temp + C.junretsu(3 * M - i, N - 2));
    }

    temp = mod(temp * N);

    ans = mod(ans - temp);
  }

  {
    int temp = 0;
    for (int i = M + 1; i <= min(3 * M, N); i++) {
      if ((3 * M - i) % 2 == 1)
        continue;
      int t = C.combination(N, i);
      t = mod(t * C.junretsu(N - 1, (3 * M - i) / 2));
      temp = mod(temp + t);
    }

    ans = mod(ans - temp);
  }

  cout << ans << endl;

  return 0;
}