prithivMLmods/Coder-Stat huggingface dataset:
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
// ios::sync_with_stdio(false);
#include <bits/stdc++.h>
#define LL long long
#define F(x, y, z) for (int x = y; x <= z; ++x)
#define D(x, y, z) for (int x = y; x >= z; --x)
using namespace std;
const int Mod = 998244353;
const int N = 3000010;
const int maxn = 3000001;
LL Min(LL x, LL y) { return x < y ? x : y; }
LL Max(LL x, LL y) { return x > y ? x : y; }
LL R() {
  LL ans = 0, f = 1;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-')
      f = -1;
  for (; c >= '0' && c <= '9'; c = getchar())
    ans = ans * 10 + c - '0';
  return ans * f;
}
LL jc[N], ni[N], n, m;
LL C(LL n, LL m) { return jc[n] * ni[m] % Mod * ni[n - m] % Mod; }
LL Calc(LL n, LL m, LL js) {
  LL ans = 0;
  F(i, 0, m) {
    if ((i + m) & 1)
      continue;
    ans += C(n, i) * C(js + (m - i) / 2 + n - 1, n - 1);
    ans %= Mod;
  }
  return ans;
}
LL Pow(LL x, LL bs) {
  LL an = 1;
  for (; bs; bs >>= 1, x = x * x % Mod)
    if (bs & 1)
      an = an * x % Mod;
  return an;
}
void Pre() {
  jc[0] = ni[0] = 1;
  F(i, 1, maxn) jc[i] = jc[i - 1] * i % Mod;
  ni[maxn] = Pow(jc[maxn], Mod - 2);
  D(i, maxn - 1, 1) ni[i] = ni[i + 1] * (i + 1) % Mod;
}
int main() {
  Pre();
  n = R();
  m = R();
  LL ans = Calc(n, m, m);
  ans -= n * (Calc(n, m, 0) - Calc(n - 1, m, 0));
  ans %= Mod;
  ans += Mod;
  ans %= Mod;
  cout << ans << '\n';
  return 0;
}

Fixed submission:
// ios::sync_with_stdio(false);
#include <bits/stdc++.h>
#define LL long long
#define F(x, y, z) for (int x = y; x <= z; ++x)
#define D(x, y, z) for (int x = y; x >= z; --x)
using namespace std;
const int Mod = 998244353;
const int N = 3000010;
const int maxn = 3000001;
LL Min(LL x, LL y) { return x < y ? x : y; }
LL Max(LL x, LL y) { return x > y ? x : y; }
LL R() {
  LL ans = 0, f = 1;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-')
      f = -1;
  for (; c >= '0' && c <= '9'; c = getchar())
    ans = ans * 10 + c - '0';
  return ans * f;
}
LL jc[N], ni[N], n, m;
LL C(LL n, LL m) { return jc[n] * ni[m] % Mod * ni[n - m] % Mod; }
LL Calc(LL n, LL m, LL js) {
  LL ans = 0;
  int ma = min(n, m);
  F(i, 0, ma) {
    if ((i + m) & 1)
      continue;
    ans += C(n, i) * C(js + (m - i) / 2 + n - 1, n - 1);
    ans %= Mod;
  }
  return ans;
}
LL Pow(LL x, LL bs) {
  LL an = 1;
  for (; bs; bs >>= 1, x = x * x % Mod)
    if (bs & 1)
      an = an * x % Mod;
  return an;
}
void Pre() {
  jc[0] = ni[0] = 1;
  F(i, 1, maxn) jc[i] = jc[i - 1] * i % Mod;
  ni[maxn] = Pow(jc[maxn], Mod - 2);
  D(i, maxn - 1, 1) ni[i] = ni[i + 1] * (i + 1) % Mod;
}
int main() {
  Pre();
  n = R();
  m = R();
  LL ans = Calc(n, m, m);
  ans -= n * (Calc(n, m, 0) - Calc(n - 1, m, 0));
  ans %= Mod;
  ans += Mod;
  ans %= Mod;
  cout << ans << '\n';
  return 0;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll p = 998244353, jc[4000010], ny[4000010];
ll ksm(ll x, ll y) {
  ll xlh = 1;
  while (y) {
    if (y & 1)
      xlh = xlh * x % p;
    x = x * x % p;
    y /= 2;
  }
  return xlh;
}
ll C(ll x, ll y) { return jc[x] * ny[y] % p * ny[x - y] % p; }
ll solve(ll n, ll zo, ll m) {
  ll i, ans = 0, xlh, sy;
  for (i = 0; i <= m; i++)
    if (zo % 2 == i % 2) {
      xlh = C(n, i);
      sy = zo - i;
      sy /= 2;
      xlh = xlh * C(sy - 1 + n, n - 1) % p;
      ans = (ans + xlh) % p;
    }
  return ans;
}
int main() {
  ll i, n, m;
  jc[0] = ny[0] = 1;
  for (i = 1; i <= 4000000; i++)
    jc[i] = jc[i - 1] * i % p;
  ny[4000000] = ksm(jc[4000000], p - 2);
  for (i = 4000000 - 1; i; i--)
    ny[i] = ny[i + 1] * (i + 1) % p;
  scanf("%lld%lld", &n, &m);
  printf("%lld", (solve(n, m * 3, m) -
                  n * (solve(n, m, m) - solve(n - 1, m, m) + p) % p + p) %
                     p);
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll p = 998244353, jc[4000010], ny[4000010];
ll ksm(ll x, ll y) {
  ll xlh = 1;
  while (y) {
    if (y & 1)
      xlh = xlh * x % p;
    x = x * x % p;
    y /= 2;
  }
  return xlh;
}
ll C(ll x, ll y) {
  if (x < 0 || y < 0 || x < y)
    return 0;
  return jc[x] * ny[y] % p * ny[x - y] % p;
}
ll solve(ll n, ll zo, ll m) {
  ll i, ans = 0, xlh, sy;
  for (i = 0; i <= m; i++)
    if (zo % 2 == i % 2) {
      xlh = C(n, i);
      sy = zo - i;
      sy /= 2;
      xlh = xlh * C(sy - 1 + n, n - 1) % p;
      ans = (ans + xlh) % p;
    }
  return ans;
}
int main() {
  ll i, n, m;
  jc[0] = ny[0] = 1;
  for (i = 1; i <= 4000000; i++)
    jc[i] = jc[i - 1] * i % p;
  ny[4000000] = ksm(jc[4000000], p - 2);
  for (i = 4000000 - 1; i; i--)
    ny[i] = ny[i + 1] * (i + 1) % p;
  scanf("%lld%lld", &n, &m);
  printf("%lld", (solve(n, m * 3, m) -
                  n * (solve(n, m, m) - solve(n - 1, m, m) + p) % p + p) %
                     p);
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

const int MX = 3000000, md = 998244353;

long long inv[MX], f[MX], inv_f[MX];

long long c(int n, int k) {
  if (k == -1)
    return n == -1 ? 1 : 0;

  return f[n] * inv_f[n - k] % md * inv_f[k] % md;
}

int main() {
  inv[1] = f[0] = f[1] = inv_f[0] = inv_f[1] = 1;
  for (int i = 2; i < MX; i++) {
    inv[i] = md - inv[md % i] * (md / i) % md;
    f[i] = f[i - 1] * i % md;
    inv_f[i] = inv_f[i - 1] * inv[i] % md;
  }

  int n, m;
  ignore = scanf("%d %d", &n, &m);

  int ans = 0;
  for (int k = m % 2; k <= m; k += 2) {
    ans = (ans + c(n, k) * c((3 * m - k) / 2 + n - 1, n - 1)) % md;
  }

  for (int k = 2 * m + 1; k <= 3 * m; k++) {
    ans = (ans - c(3 * m - k + n - 2, n - 2) * n) % md;
  }

  if (ans < 0)
    ans += md;

  printf("%d\n", ans);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

const int MX = 3000000, md = 998244353;

long long inv[MX], f[MX], inv_f[MX];

long long c(int n, int k) {
  if (k == -1)
    return n == -1 ? 1 : 0;

  return f[n] * inv_f[n - k] % md * inv_f[k] % md;
}

int main() {
  inv[1] = f[0] = f[1] = inv_f[0] = inv_f[1] = 1;
  for (int i = 2; i < MX; i++) {
    inv[i] = md - inv[md % i] * (md / i) % md;
    f[i] = f[i - 1] * i % md;
    inv_f[i] = inv_f[i - 1] * inv[i] % md;
  }

  int n, m;
  ignore = scanf("%d %d", &n, &m);

  int ans = 0;
  for (int k = m % 2; k <= m && k <= n; k += 2) {
    ans = (ans + c(n, k) * c((3 * m - k) / 2 + n - 1, n - 1)) % md;
  }

  for (int k = 2 * m + 1; k <= 3 * m; k++) {
    ans = (ans - c(3 * m - k + n - 2, n - 2) * n) % md;
  }

  if (ans < 0)
    ans += md;

  printf("%d\n", ans);

  return 0;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout << x << '\n', 0;
using namespace std;
const int N = 1e6 + 100, mod = 998244353;
ll power(ll n, ll k) {
  if (k == 0)
    return 1;
  if (k % 2 == 1) {
    ll x = power(n, k / 2);
    return x * x % mod * n % mod;
  }
  ll x = power(n, k / 2);
  return x * x % mod;
}
ll fac[N], fm[N];
ll ent(ll k, ll n) {
  if (k < 0 || k > n)
    return 0;
  if (k == 0 || k == n)
    return 1;
  return fac[n] * fm[k] % mod * fm[n - k] % mod;
}
int32_t main() {
  fac[0] = 1;
  for (int i = 1; i < N; i++) {
    fac[i] = fac[i - 1] * i % mod;
    fm[i] = power(fac[i], mod - 2);
  }
  //   cout << ent(3,5) << endl;
  ll ans = 0;
  ll n, m;
  cin >> n >> m;
  ll z = 3 * m;
  for (int i = 0; i <= min(n, m); i++) {
    ll t = z - i;
    if (t % 2 == 1)
      continue;
    ans += ent(i, n) * ent(n - 1, n - 1 + t / 2) % mod;
  }
  for (int i = 2 * m + 1; i <= 3 * m; i++) {
    ll t = z - i;
    ans -= n * ent(n - 2, n - 2 + t) % mod;
    ans += mod;
    ans %= mod;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout << x << '\n', 0;
using namespace std;
const int N = 2e6 + 100, mod = 998244353;
ll power(ll n, ll k) {
  if (k == 0)
    return 1;
  if (k % 2 == 1) {
    ll x = power(n, k / 2);
    return x * x % mod * n % mod;
  }
  ll x = power(n, k / 2);
  return x * x % mod;
}
ll fac[N], fm[N];
ll ent(ll k, ll n) {
  if (k < 0 || k > n)
    return 0;
  if (k == 0 || k == n)
    return 1;
  return fac[n] * fm[k] % mod * fm[n - k] % mod;
}
int32_t main() {
  fac[0] = 1;
  for (int i = 1; i < N; i++) {
    fac[i] = fac[i - 1] * i % mod;
    fm[i] = power(fac[i], mod - 2);
  }
  //   cout << ent(3,5) << endl;
  ll ans = 0;
  ll n, m;
  cin >> n >> m;
  ll z = 3 * m;
  for (int i = 0; i <= min(n, m); i++) {
    ll t = z - i;
    if (t % 2 == 1)
      continue;
    ans += ent(i, n) * ent(n - 1, n - 1 + t / 2) % mod;
  }
  for (int i = 2 * m + 1; i <= 3 * m; i++) {
    ll t = z - i;
    ans -= n * ent(n - 2, n - 2 + t) % mod;
    ans += mod;
    ans %= mod;
  }
  cout << ans << endl;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string.h>
#define N 2000005
using namespace std;
typedef long long ll;
const int mod = 998244353;
int n, m;
ll f[N], inv[N];
ll C(int n, int m) { return f[n] * inv[m] % mod * inv[n - m] % mod; }
ll solve(int n, int m) {
  ll ans = 0;
  for (int i = m & 1; i <= m; i += 2) {
    ll w = C(n, i);
    int res = m * 3 - i >> 1;
    ans = (ans + w * C(res + n - 1, n - 1)) % mod;
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  f[0] = f[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i <= 2000002; i++)
    f[i] = f[i - 1] * i % mod, inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  for (int i = 1; i <= 2000002; i++)
    inv[i] = inv[i - 1] * inv[i] % mod;
  ll ans = (solve(n, m) - C(n + m - 2, n - 1) * n) % mod;
  ans = (ans + mod) % mod;
  printf("%lld", ans);
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string.h>
#define N 2000005
using namespace std;
typedef long long ll;
const int mod = 998244353;
int n, m;
ll f[N], inv[N];
ll C(int n, int m) { return f[n] * inv[m] % mod * inv[n - m] % mod; }
ll solve(int n, int m) {
  ll ans = 0;
  for (int i = m & 1; i <= m && i <= n; i += 2) {
    ll w = C(n, i);
    int res = m * 3 - i >> 1;
    ans = (ans + w * C(res + n - 1, n - 1)) % mod;
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  f[0] = f[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i <= 2000002; i++)
    f[i] = f[i - 1] * i % mod, inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  for (int i = 1; i <= 2000002; i++)
    inv[i] = inv[i - 1] * inv[i] % mod;
  ll ans = (solve(n, m) - C(n + m - 2, n - 1) * n) % mod;
  ans = (ans + mod) % mod;
  printf("%lld", ans);
  return 0;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

typedef long long LL;

const int maxn = 1e6 + 5;
const LL mo = 998244353;

int n, m;

LL mi(LL x, LL y) {
  LL re = 1;
  for (; y; y >>= 1, x = x * x % mo)
    if (y & 1)
      re = re * x % mo;
  return re;
}

LL fac[4 * maxn], ny[4 * maxn];
void Pre(int n) {
  fac[0] = 1;
  fo(i, 1, n) fac[i] = fac[i - 1] * i % mo;
  ny[n] = mi(fac[n], mo - 2);
  fd(i, n - 1, 0) ny[i] = ny[i + 1] * (i + 1) % mo;
}
LL C(int n, int m) { return fac[n] * ny[m] % mo * ny[n - m] % mo; }

LL calc(int n, int sum, int m) {
  LL re = 0;
  fo(i, 0, m) if (!((sum - i) & 1))(
      re += C(n, i) * C((sum - i) / 2 + n - 1, n - 1)) %= mo;
  return re;
}

int main() {
  scanf("%d %d", &n, &m);

  Pre(3 * m + n);

  LL ans = calc(n, 3 * m, m) - (calc(n, m, m) - calc(n - 1, m, m)) % mo * n;

  printf("%lld\n", (ans % mo + mo) % mo);
}

Fixed submission:
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

typedef long long LL;

const int maxn = 1e6 + 5;
const LL mo = 998244353;

int n, m;

LL mi(LL x, LL y) {
  LL re = 1;
  for (; y; y >>= 1, x = x * x % mo)
    if (y & 1)
      re = re * x % mo;
  return re;
}

LL fac[4 * maxn], ny[4 * maxn];
void Pre(int n) {
  fac[0] = 1;
  fo(i, 1, n) fac[i] = fac[i - 1] * i % mo;
  ny[n] = mi(fac[n], mo - 2);
  fd(i, n - 1, 0) ny[i] = ny[i + 1] * (i + 1) % mo;
}
LL C(int n, int m) {
  return (n < m) ? 0 : fac[n] * ny[m] % mo * ny[n - m] % mo;
}

LL calc(int n, int sum, int m) {
  LL re = 0;
  fo(i, 0, m) if (!((sum - i) & 1))(
      re += C(n, i) * C((sum - i) / 2 + n - 1, n - 1)) %= mo;
  return re;
}

int main() {
  scanf("%d %d", &n, &m);

  Pre(3 * m + n);

  LL ans = calc(n, 3 * m, m) - (calc(n, m, m) - calc(n - 1, m, m)) % mo * n;

  printf("%lld\n", (ans % mo + mo) % mo);
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long

#define N 1000005
int P[N];
int PI[N];
#define MOD 998244353

ll modInverse(ll a, ll m) {
  ll m0 = m;
  ll y = 0, x = 1;
  if (m == 1)
    return 0;
  while (a > 1) {
    int q = a / m;
    int t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0)
    x += m0;
  return x;
}

void fun() {
  P[0] = 1;
  int i;
  for (i = 1; i < N; i++) {
    P[i] = (P[i - 1] * i) % MOD;
  }
  for (i = 0; i < N; i++) {
    PI[i] = modInverse(P[i], MOD);
  }
}

int ncr(int n, int r) {
  int ans = P[n];
  ans *= PI[r];
  ans %= MOD;
  ans *= PI[n - r];
  ans %= MOD;
  return ans;
}

int distribute(int x, int n) {
  int ans = ncr(n + x - 1, n - 1);
  return ans;
}

int dp[N];

int32_t main() {
  ios_base::sync_with_stdio(false);

  fun();

  int n, m;
  cin >> n >> m;

  int ans = 0;
  for (int i = 0; i <= min(n, m); i++) {
    int left = m - i;
    if (left % 2)
      continue;
    int temp = m + left / 2;
    int dis = distribute(temp, n);
    ans += dis * ncr(n, i);
    ans %= MOD;
  }

  for (int i = 2 * m + 1; i <= 3 * m; i++) {
    int temp = 3 * m - i;
    temp = distribute(temp, n - 1);
    ans -= temp * n;
    ans %= MOD;
    if (ans < 0)
      ans += MOD;
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long

#define N 3000005
int P[N];
int PI[N];
#define MOD 998244353

ll modInverse(ll a, ll m) {
  ll m0 = m;
  ll y = 0, x = 1;
  if (m == 1)
    return 0;
  while (a > 1) {
    int q = a / m;
    int t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0)
    x += m0;
  return x;
}

void fun() {
  P[0] = 1;
  int i;
  for (i = 1; i < N; i++) {
    P[i] = (P[i - 1] * i) % MOD;
  }
  for (i = 0; i < N; i++) {
    PI[i] = modInverse(P[i], MOD);
  }
}

int ncr(int n, int r) {
  int ans = P[n];
  ans *= PI[r];
  ans %= MOD;
  ans *= PI[n - r];
  ans %= MOD;
  return ans;
}

int distribute(int x, int n) {
  int ans = ncr(n + x - 1, n - 1);
  return ans;
}

int dp[N];

int32_t main() {
  ios_base::sync_with_stdio(false);

  fun();

  int n, m;
  cin >> n >> m;

  int ans = 0;
  for (int i = 0; i <= min(n, m); i++) {
    int left = m - i;
    if (left % 2)
      continue;
    int temp = m + left / 2;
    int dis = distribute(temp, n);
    ans += dis * ncr(n, i);
    ans %= MOD;
  }

  for (int i = 2 * m + 1; i <= 3 * m; i++) {
    int temp = 3 * m - i;
    temp = distribute(temp, n - 1);
    ans -= temp * n;
    ans %= MOD;
    if (ans < 0)
      ans += MOD;
  }
  cout << ans << endl;

  return 0;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x)                                                         \
  sort(all((x)));                                                              \
  (x).resize(unique(all((x))) - (x).begin())

#define random_shuffle(...) shuffle(__VA_ARGS__, rng)
#define rand() rng()

using namespace std;

inline int nxt() {
  int x;
  scanf("%d", &x);
  return x;
}

const int N = 5111111;
long long fact[N], inv[N], invfact[N];
const int mod = 998244353;

long long C(int n, int k) {
  return fact[n] * invfact[k] % mod * invfact[n - k] % mod;
}

int main() {
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

  fact[0] = invfact[0] = 1;
  for (int i = 1; i < N; ++i) {
    inv[i] = (i == 1) ? 1 : mod - inv[mod % i] * (mod / i) % mod;
    fact[i] = fact[i - 1] * i % mod;
    invfact[i] = invfact[i - 1] * inv[i] % mod;
  }

  int n = nxt(), m = nxt();
  long long ans = C(3 * m + n - 1, n - 1) - n * C(m + n - 2, n - 1);

  for (int i = m + 1; i <= n; ++i) {
    if (i % 2 != m % 2) {
      continue;
    }
    long long tmp = C((3 * m - i) / 2 + n - 1, n - 1) * C(n, i) % mod;
    ans -= tmp;
  }

  ans %= mod;
  cout << (ans + mod) % mod << "\n";

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x)                                                         \
  sort(all((x)));                                                              \
  (x).resize(unique(all((x))) - (x).begin())

#define random_shuffle(...) shuffle(__VA_ARGS__, rng)
#define rand() rng()

using namespace std;

inline int nxt() {
  int x;
  scanf("%d", &x);
  return x;
}

const int N = 5111111;
long long fact[N], inv[N], invfact[N];
const int mod = 998244353;

long long C(int n, int k) {
  if (n < k) {
    return 0;
  }
  return fact[n] * invfact[k] % mod * invfact[n - k] % mod;
}

int main() {
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

  fact[0] = invfact[0] = 1;
  for (int i = 1; i < N; ++i) {
    inv[i] = (i == 1) ? 1 : mod - inv[mod % i] * (mod / i) % mod;
    fact[i] = fact[i - 1] * i % mod;
    invfact[i] = invfact[i - 1] * inv[i] % mod;
  }

  int n = nxt(), m = nxt();
  long long ans = C(3 * m + n - 1, n - 1) - n * C(m + n - 2, n - 1);

  for (int i = m + 1; i <= n; ++i) {
    if (i % 2 != m % 2) {
      continue;
    }
    long long tmp = C((3 * m - i) / 2 + n - 1, n - 1) * C(n, i) % mod;
    ans -= tmp;
  }

  ans %= mod;
  cout << (ans + mod) % mod << "\n";

  return 0;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define mod 998244353
#define mad(a, b) a = (a + b) % mod
#define mul(a, b) a = (a * b) % mod
#define N 1500010
ll fac[N], inv[N], ivf[N];
ll C(ll n, ll k) {
  if (n < k)
    return 0;
  return fac[n] * ivf[n - k] % mod * ivf[k] % mod;
}
ll H(ll n, ll k) {
  // if(k==0)return 1;
  return C(n + k - 1, k);
}
ll P(ll n, ll k) { return fac[n] * ivf[n - k] % mod; }
ll po(ll x, ll y) {
  ll res = 1;
  for (; y; y >>= 1) {
    if (y & 1)
      res = res * x % mod;
    x = x * x % mod;
  }
  return res;
}

int main() {
  fac[0] = ivf[0] = inv[1] = 1;
  for (int i = 1; i < N; i++) {
    if (i > 1)
      inv[i] = (mod - mod / i * inv[mod % i] % mod) % mod;
    fac[i] = fac[i - 1] * i % mod;
    ivf[i] = ivf[i - 1] * inv[i] % mod;
  }
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  for (ll p = 0; p <= m; p++) {
    if ((3 * m - p) % 2 == 1)
      continue;
    ll cur = H(n, (3 * m - p) / 2) * C(n, p);
    mad(ans, cur);
    // cout<<cur<<endl;
  }
  mad(ans, -n * H(n, m - 1));
  if (ans < 0)
    ans += mod;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define mod 998244353
#define mad(a, b) a = (a + b) % mod
#define mul(a, b) a = (a * b) % mod
#define N 5000010
ll fac[N], inv[N], ivf[N];
ll C(ll n, ll k) {
  if (n < k)
    return 0;
  return fac[n] * ivf[n - k] % mod * ivf[k] % mod;
}
ll H(ll n, ll k) {
  // if(k==0)return 1;
  return C(n + k - 1, k);
}
ll P(ll n, ll k) { return fac[n] * ivf[n - k] % mod; }
ll po(ll x, ll y) {
  ll res = 1;
  for (; y; y >>= 1) {
    if (y & 1)
      res = res * x % mod;
    x = x * x % mod;
  }
  return res;
}

int main() {
  fac[0] = ivf[0] = inv[1] = 1;
  for (int i = 1; i < N; i++) {
    if (i > 1)
      inv[i] = (mod - mod / i * inv[mod % i] % mod) % mod;
    fac[i] = fac[i - 1] * i % mod;
    ivf[i] = ivf[i - 1] * inv[i] % mod;
  }
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  for (ll p = 0; p <= m; p++) {
    if ((3 * m - p) % 2 == 1)
      continue;
    ll cur = H(n, (3 * m - p) / 2) * C(n, p);
    mad(ans, cur);
    // cout<<cur<<endl;
  }
  mad(ans, -n * H(n, m - 1));
  if (ans < 0)
    ans += mod;
  cout << ans << endl;
  return 0;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MN 1500000
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m, ans, p[MN + 5], inv[MN + 5];
inline int C(int n, int m) {
  return m > n ? 0 : 1LL * p[n] * inv[m] % mod * inv[n - m] % mod;
}
int main() {
  n = read();
  m = read();
  p[0] = p[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i <= MN; ++i)
    p[i] = 1LL * p[i - 1] * i % mod,
    inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
  for (int i = 2; i <= MN; ++i)
    inv[i] = 1LL * inv[i - 1] * inv[i] % mod;
  if (n == 2)
    return 0 * printf("%d\n", m + 1);
  for (int i = 0; i <= m; i += 2)
    if (m - i <= n) {
      int t = i / 2 + m;
      ans = (ans + 1LL * C(n, m - i) * C(t + n - 1, n - 1)) % mod;
      ans = (ans + 1LL * C(n, m - i) * (mod - (m - i)) % mod *
                       C(t - m + n - 1, n - 1)) %
            mod;
      ans = (ans + 1LL * C(n, m - i) * (mod - (n - (m - i))) % mod *
                       C(t - m + n - 2, n - 1)) %
            mod;
    }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MN 2500000
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m, ans, p[MN + 5], inv[MN + 5];
inline int C(int n, int m) {
  return m > n ? 0 : 1LL * p[n] * inv[m] % mod * inv[n - m] % mod;
}
int main() {
  n = read();
  m = read();
  p[0] = p[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i <= MN; ++i)
    p[i] = 1LL * p[i - 1] * i % mod,
    inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
  for (int i = 2; i <= MN; ++i)
    inv[i] = 1LL * inv[i - 1] * inv[i] % mod;
  if (n == 2)
    return 0 * printf("%d\n", m + 1);
  for (int i = 0; i <= m; i += 2)
    if (m - i <= n) {
      int t = i / 2 + m;
      ans = (ans + 1LL * C(n, m - i) * C(t + n - 1, n - 1)) % mod;
      ans = (ans + 1LL * C(n, m - i) * (mod - (m - i)) % mod *
                       C(t - m + n - 1, n - 1)) %
            mod;
      ans = (ans + 1LL * C(n, m - i) * (mod - (n - (m - i))) % mod *
                       C(t - m + n - 2, n - 1)) %
            mod;
    }
  cout << ans;
  return 0;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

const ll MAX = 1500100, MOD = 998244353;
ll fac[MAX], finv[MAX], inv[MAX];
// 前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
// 二項係数の計算
ll COM(int n, int k) {
  if (n < 0 || k < 0 || n < k)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int n, m;
  cin >> n >> m;
  COMinit();
  ll ans = 0;
  if (m % 2 == 0) {
    for (int i = 0; i <= m; i += 2) {
      ans += COM((3 * m - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD; // 奇数がi個
      ans -= COM((m - 2 - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD * n %
             MOD; // 2n+2以上
      ans -= COM((m - i) / 2 + n - 2, n - 2) * COM(n - 1, i - 1) % MOD * n %
             MOD; // 2n+1
      ans += MOD;
      ans %= MOD;
    }
  }
  if (m % 2 == 1) {
    for (int i = 1; i <= m; i += 2) {
      ans += COM((3 * m - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD; // 奇数がi個
      ans -= COM((m - 2 - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD * n %
             MOD; // 2n+2以上
      ans -= COM((m - i) / 2 + n - 2, n - 2) * COM(n - 1, i - 1) % MOD * n %
             MOD; // 2n+1
      ans += MOD;
      ans %= MOD;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

const ll MAX = 3500100, MOD = 998244353;
ll fac[MAX], finv[MAX], inv[MAX];
// 前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
// 二項係数の計算
ll COM(int n, int k) {
  if (n < 0 || k < 0 || n < k)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int n, m;
  cin >> n >> m;
  COMinit();
  ll ans = 0;
  if (m % 2 == 0) {
    for (int i = 0; i <= m; i += 2) {
      ans += COM((3 * m - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD; // 奇数がi個
      ans -= COM((m - 2 - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD * n %
             MOD; // 2n+2以上
      ans -= COM((m - i) / 2 + n - 2, n - 2) * COM(n - 1, i - 1) % MOD * n %
             MOD; // 2n+1
      ans += MOD;
      ans %= MOD;
    }
  }
  if (m % 2 == 1) {
    for (int i = 1; i <= m; i += 2) {
      ans += COM((3 * m - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD; // 奇数がi個
      ans -= COM((m - 2 - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD * n %
             MOD; // 2n+2以上
      ans -= COM((m - i) / 2 + n - 2, n - 2) * COM(n - 1, i - 1) % MOD * n %
             MOD; // 2n+1
      ans += MOD;
      ans %= MOD;
    }
  }
  cout << ans << endl;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 998244353;

const int MAX = 1000000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int N, M;
  cin >> N >> M;
  COMinit();
  ll ans = COM(3 * M + N - 1, N - 1);
  ll igai = 0;
  rep(i, M) {
    igai += (COM(i + N - 2, i) * N % mod);
    igai %= mod;
  }
  for (int i = M + 1; i <= min(3 * M, N); i++) {
    if ((3 * M - i) % 2)
      continue;
    ll tmp = (3 * M - i) / 2;
    igai += (COM(tmp + N - 1, tmp) * COM(N, i) % mod);
    igai %= mod;
  }
  ans -= igai;
  if (ans < 0)
    ans += mod;
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 998244353;

const int MAX = 3000000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int N, M;
  cin >> N >> M;
  COMinit();
  ll ans = COM(3 * M + N - 1, N - 1);
  ll igai = 0;
  rep(i, M) {
    igai += (COM(i + N - 2, i) * N % mod);
    igai %= mod;
  }
  for (int i = M + 1; i <= min(3 * M, N); i++) {
    if ((3 * M - i) % 2)
      continue;
    ll tmp = (3 * M - i) / 2;
    igai += (COM(tmp + N - 1, tmp) * COM(N, i) % mod);
    igai %= mod;
  }
  ans -= igai;
  if (ans < 0)
    ans += mod;
  cout << ans << endl;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
const int MAX = 1500000;
const int MOD = 998244353;
int add(int a, int b) { return (a + b) % MOD; }
int mul(int a, int b) { return 1LL * a * b % MOD; }
int sub(int a, int b) { return add(a, MOD - b); }
int pow_mod(int b, int p) {
  int ret = 1;
  while (p) {
    if (p & 1)
      ret = mul(ret, b);
    b = mul(b, b);
    p >>= 1;
  }
  return ret;
}
int fct[MAX + 5], ifct[MAX + 5];
void init() {
  fct[0] = 1;
  for (int i = 1; i <= MAX; i++)
    fct[i] = mul(fct[i - 1], i);
  ifct[MAX] = pow_mod(fct[MAX], MOD - 2);
  for (int i = MAX - 1; i >= 0; i--)
    ifct[i] = mul(ifct[i + 1], i + 1);
}
int comb(int n, int m) {
  if (n < m)
    return 0;
  else
    return mul(fct[n], mul(ifct[m], ifct[n - m]));
}
int n, m, l;
int main() {
  init();
  scanf("%d%d", &n, &m);
  int ans = 0;
  for (int i = (m & 1); i <= n && i <= m; i += 2) {
    int t = (3 * m - i) / 2;
    int del = comb(t + n - 1, n - 1);
    if (t >= m)
      del = sub(del, mul(i, comb(t - m + n - 1, n - 1)));
    if (t >= m + 1)
      del = sub(del, mul(n - i, comb(t - m - 1 + n - 1, n - 1)));
    ans = add(ans, mul(comb(n, i), del));
  }
  printf("%d\n", ans);
}

Fixed submission:
#include <cstdio>
const int MAX = 3000000;
const int MOD = 998244353;
int add(int a, int b) { return (a + b) % MOD; }
int mul(int a, int b) { return 1LL * a * b % MOD; }
int sub(int a, int b) { return add(a, MOD - b); }
int pow_mod(int b, int p) {
  int ret = 1;
  while (p) {
    if (p & 1)
      ret = mul(ret, b);
    b = mul(b, b);
    p >>= 1;
  }
  return ret;
}
int fct[MAX + 5], ifct[MAX + 5];
void init() {
  fct[0] = 1;
  for (int i = 1; i <= MAX; i++)
    fct[i] = mul(fct[i - 1], i);
  ifct[MAX] = pow_mod(fct[MAX], MOD - 2);
  for (int i = MAX - 1; i >= 0; i--)
    ifct[i] = mul(ifct[i + 1], i + 1);
}
int comb(int n, int m) {
  if (n < m)
    return 0;
  else
    return mul(fct[n], mul(ifct[m], ifct[n - m]));
}
int n, m, l;
int main() {
  init();
  scanf("%d%d", &n, &m);
  int ans = 0;
  for (int i = (m & 1); i <= n && i <= m; i += 2) {
    int t = (3 * m - i) / 2;
    int del = comb(t + n - 1, n - 1);
    if (t >= m)
      del = sub(del, mul(i, comb(t - m + n - 1, n - 1)));
    if (t >= m + 1)
      del = sub(del, mul(n - i, comb(t - m - 1 + n - 1, n - 1)));
    ans = add(ans, mul(comb(n, i), del));
  }
  printf("%d\n", ans);
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
// C - GP 2
#include <bits/stdc++.h>

using namespace std;

#define MOD 998244353

struct FactTable {
  vector<long long> a;
  FactTable(int n) : a(n + 1, 1) {
    for (int i = 2; i < a.size(); i++)
      a[i] = a[i - 1] * i % MOD;
  }
  inline long long operator()(int n) { return a[n]; }
} fact(1000000);

long long minv(long long a) {
  long long r = 1;
  for (long long n = MOD - 2; n > 0; a = a * a % MOD, n >>= 1)
    if (n & 1)
      r = r * a % MOD;
  return r;
}

long long cnr(int n, int r) {
  if (r < 0 || r > n)
    return 0;
  if (r == 0 || r == n)
    return 1;
  return fact(n) * minv(fact(r)) % MOD * minv(fact(n - r)) % MOD;
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);

  long long n, m;
  cin >> n >> m;

  long long ans = 0;

  for (int k = 0; k <= min(m, n); k++) {
    if ((3 * m - k) % 2)
      continue;
    long long c = (3 * m - k) / 2;
    ans = (ans + cnr(c + n - 1, c) * cnr(n, k) % MOD) % MOD;
  }

  long long r = 0;
  for (int k = 0; k <= min(m, n); k++) {
    if ((m - k) % 2)
      continue;
    long long c = (m - k) / 2;
    r = (r + cnr(c + n - 1, c) * cnr(n, k) % MOD -
         cnr(c + n - 2, c) * cnr(n - 1, k) % MOD + MOD) %
        MOD;
  }
  ans = (ans - r * n % MOD + MOD) % MOD;

  cout << ans << endl;

  return 0;
}


Fixed submission:
// C - GP 2
#include <bits/stdc++.h>

using namespace std;

#define MOD 998244353

struct FactTable {
  vector<long long> a;
  FactTable(int n) : a(n + 1, 1) {
    for (int i = 2; i < a.size(); i++)
      a[i] = a[i - 1] * i % MOD;
  }
  inline long long operator()(int n) { return a[n]; }
} fact(2000000);

long long minv(long long a) {
  long long r = 1;
  for (long long n = MOD - 2; n > 0; a = a * a % MOD, n >>= 1)
    if (n & 1)
      r = r * a % MOD;
  return r;
}

long long cnr(int n, int r) {
  if (r < 0 || r > n)
    return 0;
  if (r == 0 || r == n)
    return 1;
  return fact(n) * minv(fact(r)) % MOD * minv(fact(n - r)) % MOD;
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);

  long long n, m;
  cin >> n >> m;

  long long ans = 0;

  for (int k = 0; k <= min(m, n); k++) {
    if ((3 * m - k) % 2)
      continue;
    long long c = (3 * m - k) / 2;
    ans = (ans + cnr(c + n - 1, c) * cnr(n, k) % MOD) % MOD;
  }

  long long r = 0;
  for (int k = 0; k <= min(m, n); k++) {
    if ((m - k) % 2)
      continue;
    long long c = (m - k) / 2;
    r = (r + cnr(c + n - 1, c) * cnr(n, k) % MOD -
         cnr(c + n - 2, c) * cnr(n - 1, k) % MOD + MOD) %
        MOD;
  }
  ans = (ans - r * n % MOD + MOD) % MOD;

  cout << ans << endl;

  return 0;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#define RI register int
#define CI const int &
using namespace std;
const int N = 3000005, mod = 998244353;
int n, m, fact[N], inv[N], ans, tp;
inline void inc(int &x, CI y) {
  if ((x += y) >= mod)
    x -= mod;
}
inline void dec(int &x, CI y) {
  if ((x -= y) < 0)
    x += mod;
}
inline int quick_pow(int x, int p = mod - 2, int mul = 1) {
  for (; p; p >>= 1, x = 1LL * x * x % mod)
    if (p & 1)
      mul = 1LL * mul * x % mod;
  return mul;
}
inline int C(CI n, CI m) {
  return 1LL * fact[n] * inv[m] % mod * inv[n - m] % mod;
}
inline void init(CI n) {
  RI i;
  for (fact[0] = i = 1; i <= n; ++i)
    fact[i] = 1LL * fact[i - 1] * i % mod;
  for (inv[n] = quick_pow(fact[n]), i = n - 1; ~i; --i)
    inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
}
int main() {
  RI i;
  scanf("%d%d", &n, &m);
  init(n + 3 * m);
  for (i = 0; i <= m; ++i)
    if (!((3 * m - i) & 1))
      tp = (3 * m - i) / 2,
      inc(ans, 1LL * C(n, i) * C(tp + n - 1, n - 1) % mod);
  for (i = 2 * m + 1; i <= 3 * m; ++i)
    dec(ans, 1LL * n * C(3 * m - i + n - 2, n - 2) % mod);
  return printf("%d", ans), 0;
}

Fixed submission:
#include <cstdio>
#define RI register int
#define CI const int &
using namespace std;
const int N = 3000005, mod = 998244353;
int n, m, fact[N], inv[N], ans, tp;
inline void inc(int &x, CI y) {
  if ((x += y) >= mod)
    x -= mod;
}
inline void dec(int &x, CI y) {
  if ((x -= y) < 0)
    x += mod;
}
inline int quick_pow(int x, int p = mod - 2, int mul = 1) {
  for (; p; p >>= 1, x = 1LL * x * x % mod)
    if (p & 1)
      mul = 1LL * mul * x % mod;
  return mul;
}
inline int C(CI n, CI m) {
  if (n < m)
    return 0;
  return 1LL * fact[n] * inv[m] % mod * inv[n - m] % mod;
}
inline void init(CI n) {
  RI i;
  for (fact[0] = i = 1; i <= n; ++i)
    fact[i] = 1LL * fact[i - 1] * i % mod;
  for (inv[n] = quick_pow(fact[n]), i = n - 1; ~i; --i)
    inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
}
int main() {
  RI i;
  scanf("%d%d", &n, &m);
  init(n + 3 * m);
  for (i = 0; i <= m; ++i)
    if (!((3 * m - i) & 1))
      tp = (3 * m - i) / 2,
      inc(ans, 1LL * C(n, i) * C(tp + n - 1, n - 1) % mod);
  for (i = 2 * m + 1; i <= 3 * m; ++i)
    dec(ans, 1LL * n * C(3 * m - i + n - 2, n - 2) % mod);
  return printf("%d", ans), 0;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1000005, M = 998244353;
int fac[N], inv[N], n, m, ans;
int ksm(int x, int y) {
  int ans = 1;
  for (; y; y >>= 1, x = x * x % M)
    if (y & 1)
      (ans *= x) %= M;
  return ans;
}
int C(int x, int y) {
  if (x < y)
    return 0;
  return fac[x] * inv[y] % M * inv[x - y] % M;
}
signed main() {
  scanf("%lld%lld", &n, &m);
  fac[0] = inv[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % M, inv[i] = ksm(fac[i], M - 2);
  for (int i = m & 1; i <= m; i += 2)
    (ans += C(n + (3 * m - i) / 2 - 1, n - 1) * C(n, i)) %= M;
  for (int i = m & 1; i <= m; i += 2)
    (ans += M - n * C(n + (m - i) / 2 - 1, n - 1) % M * C(n, i) % M) %= M;
  n--;
  for (int i = m & 1; i <= m; i += 2)
    (ans += (n + 1) * C(n + (m - i) / 2 - 1, n - 1) % M * C(n, i) % M) %= M;
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3000005, M = 998244353;
int fac[N], inv[N], n, m, ans;
int ksm(int x, int y) {
  int ans = 1;
  for (; y; y >>= 1, x = x * x % M)
    if (y & 1)
      (ans *= x) %= M;
  return ans;
}
int C(int x, int y) {
  if (x < y)
    return 0;
  return fac[x] * inv[y] % M * inv[x - y] % M;
}
signed main() {
  scanf("%lld%lld", &n, &m);
  fac[0] = inv[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % M, inv[i] = ksm(fac[i], M - 2);
  for (int i = m & 1; i <= m; i += 2)
    (ans += C(n + (3 * m - i) / 2 - 1, n - 1) * C(n, i)) %= M;
  for (int i = m & 1; i <= m; i += 2)
    (ans += M - n * C(n + (m - i) / 2 - 1, n - 1) % M * C(n, i) % M) %= M;
  n--;
  for (int i = m & 1; i <= m; i += 2)
    (ans += (n + 1) * C(n + (m - i) / 2 - 1, n - 1) % M * C(n, i) % M) %= M;
  printf("%lld\n", ans);
  return 0;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = (int)1e6 + 5, M = (int)5e5 + 5, mod = 998244353;
int n, m, fact[4 * M], inv_fact[4 * M], ans;

int add(int _a, int _b) {
  _a += _b;
  if (_a >= mod)
    _a -= mod;
  return _a;
}

int multi(int _a, int _b) { return (int)((ll)_a * _b % mod); }

int bin_pow(int _a, int _n) {
  int ret = 1;
  for (; _n; _n >>= 1, _a = multi(_a, _a))
    if (_n & 1)
      ret = multi(ret, _a);
  return ret;
}

int C(int _k, int _n) {
  return multi(fact[_n], multi(inv_fact[_k], inv_fact[_n - _k]));
}

int candy_distribution(int _n, int _sum) { return C(_n - 1, _sum + _n - 1); }

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  fact[0] = 1;
  for (int i = 1; i < 4 * M; ++i)
    fact[i] = multi(fact[i - 1], i);
  inv_fact[4 * M - 1] = bin_pow(fact[4 * M - 1], mod - 2);
  for (int i = 4 * M - 2; i >= 0; --i)
    inv_fact[i] = multi(inv_fact[i + 1], i + 1);

  cin >> n >> m;

  for (int n_odd = 0; n_odd <= m; ++n_odd) {
    int rem = 3 * m - n_odd;
    if (rem & 1)
      continue;
    rem >>= 1;
    ans = add(ans, multi(C(n_odd, n), candy_distribution(n, rem)));
  }

  for (int exceed = 2 * m + 1; exceed <= 3 * m; ++exceed) {
    int rem = 3 * m - exceed;
    ans = add(ans, mod - multi(n, candy_distribution(n - 1, rem)));
  }

  cout << ans << '\n';

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = (int)1e6 + 5, M = (int)5e5 + 5, mod = 998244353;
int n, m, fact[4 * M], inv_fact[4 * M], ans;

int add(int _a, int _b) {
  _a += _b;
  if (_a >= mod)
    _a -= mod;
  return _a;
}

int multi(int _a, int _b) { return (int)((ll)_a * _b % mod); }

int bin_pow(int _a, int _n) {
  int ret = 1;
  for (; _n; _n >>= 1, _a = multi(_a, _a))
    if (_n & 1)
      ret = multi(ret, _a);
  return ret;
}

int C(int _k, int _n) {
  if (_k < 0 || _k > _n || _n < 0)
    return 0;
  return multi(fact[_n], multi(inv_fact[_k], inv_fact[_n - _k]));
}

int candy_distribution(int _n, int _sum) { return C(_n - 1, _sum + _n - 1); }

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  fact[0] = 1;
  for (int i = 1; i < 4 * M; ++i)
    fact[i] = multi(fact[i - 1], i);
  inv_fact[4 * M - 1] = bin_pow(fact[4 * M - 1], mod - 2);
  for (int i = 4 * M - 2; i >= 0; --i)
    inv_fact[i] = multi(inv_fact[i + 1], i + 1);

  cin >> n >> m;

  for (int n_odd = 0; n_odd <= m; ++n_odd) {
    int rem = 3 * m - n_odd;
    if (rem & 1)
      continue;
    rem >>= 1;
    ans = add(ans, multi(C(n_odd, n), candy_distribution(n, rem)));
  }

  for (int exceed = 2 * m + 1; exceed <= 3 * m; ++exceed) {
    int rem = 3 * m - exceed;
    ans = add(ans, mod - multi(n, candy_distribution(n - 1, rem)));
  }

  cout << ans << '\n';

  return 0;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define Tp template <typename Ty>
#define Ts template <typename Ty, typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int &
#define I inline
#define W while
#define SZ 5000000
#define X 998244353
#define Qinv(x) Qpow(x, X - 2)
#define Inc(x, y) ((x += (y)) >= X && (x -= X))
#define C(x, y) (1LL * Fac[x] * IFac[y] % X * IFac[(x) - (y)] % X)
#define S(x, y) C((x) + (y)-1, (y)-1)
using namespace std;
int n, m, Fac[SZ + 5], IFac[SZ + 5];
I int Qpow(RI x, RI y) {
  RI t = 1;
  W(y) y & 1 && (t = 1LL * t * x % X), x = 1LL * x * x % X, y >>= 1;
  return t;
}
int main() {
  RI i, ans = 0;
  for (scanf("%d%d", &n, &m), Fac[0] = i = 1; i <= SZ; ++i)
    Fac[i] = 1LL * Fac[i - 1] * i % X;
  for (IFac[SZ] = Qinv(Fac[SZ]), i = SZ - 1; ~i; --i)
    IFac[i] = 1LL * IFac[i + 1] * (i + 1) % X;
  for (i = m & 1; i <= m; i += 2)
    ans = (1LL * C(n, i) * S(3 * m - i >> 1, n) + ans) % X;
  for (i = 2 * m + 1; i <= 3 * m; ++i)
    ans = (X - 1LL * n * S(3 * m - i, n - 1) + ans) % X;
  return printf("%d", ans), 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define Tp template <typename Ty>
#define Ts template <typename Ty, typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int &
#define I inline
#define W while
#define SZ 5000000
#define X 998244353
#define Qinv(x) Qpow(x, X - 2)
#define Inc(x, y) ((x += (y)) >= X && (x -= X))
#define C(x, y)                                                                \
  ((x) < (y) ? 0 : 1LL * Fac[x] * IFac[y] % X * IFac[(x) - (y)] % X)
#define S(x, y) C((x) + (y)-1, (y)-1)
using namespace std;
int n, m, Fac[SZ + 5], IFac[SZ + 5];
I int Qpow(RI x, RI y) {
  RI t = 1;
  W(y) y & 1 && (t = 1LL * t * x % X), x = 1LL * x * x % X, y >>= 1;
  return t;
}
int main() {
  RI i, ans = 0;
  for (scanf("%d%d", &n, &m), Fac[0] = i = 1; i <= SZ; ++i)
    Fac[i] = 1LL * Fac[i - 1] * i % X;
  for (IFac[SZ] = Qinv(Fac[SZ]), i = SZ - 1; ~i; --i)
    IFac[i] = 1LL * IFac[i + 1] * (i + 1) % X;
  for (i = m & 1; i <= m; i += 2)
    ans = (1LL * C(n, i) * S(3 * m - i >> 1, n) + ans) % X;
  for (i = 2 * m + 1; i <= 3 * m; ++i)
    ans = (X - 1LL * n * S(3 * m - i, n - 1) + ans) % X;
  return printf("%d", ans), 0;
}
Problem p02965 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 200000;
const int MOD = 998244353;
//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
int COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main() {
  int n, m;
  cin >> n >> m;
  COMinit();
  int ans = n * COM(m + n - 2, m) % MOD;
  for (int i = m; 3 * m - 2 * i >= 0; i++) {
    ans = (ans +
           (COM(i + n - 1, i) + (MOD - n * COM(i - m + n - 1, i - m) % MOD)) *
               COM(n, 3 * m - 2 * i) % MOD) %
          MOD;
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 2000000;
const int MOD = 998244353;
//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
int COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main() {
  int n, m;
  cin >> n >> m;
  COMinit();
  int ans = n * COM(m + n - 2, m) % MOD;
  for (int i = m; 3 * m - 2 * i >= 0; i++) {
    ans = (ans +
           (COM(i + n - 1, i) + (MOD - n * COM(i - m + n - 1, i - m) % MOD)) *
               COM(n, 3 * m - 2 * i) % MOD) %
          MOD;
  }
  cout << ans;
}
Problem p02966 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
int n;
ll a[305][305], sum[305][305], f[305][305], s[305][305];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (i != j)
        scanf("%lld", &a[i][j]);
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j] * (i < j);
    }
  memset(f, 0x3f, sizeof(f));
  f[0][0] = 0;
  for (int i = 0; i <= n; i++)
    for (int j = i; j <= n; j++) {
      if (f[i][j] > 1e17)
        continue;
      for (int k = j + 1; k <= n; k++)
        f[j][k] =
            min(f[j][k], f[i][j] + s[k][k] - s[j][k] - s[k][j] + s[j][j] +
                             sum[n][j] - sum[n][i] - sum[k][j] + sum[k][i]);
    }
  ll ans = 1e18;
  for (int i = 0; i <= n; i++)
    ans = min(ans, f[i][n]);
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
int n;
ll a[505][505], sum[505][505], f[505][505], s[505][505];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (i != j)
        scanf("%lld", &a[i][j]);
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j] * (i < j);
    }
  memset(f, 0x3f, sizeof(f));
  f[0][0] = 0;
  for (int i = 0; i <= n; i++)
    for (int j = i; j <= n; j++) {
      if (f[i][j] > 1e17)
        continue;
      for (int k = j + 1; k <= n; k++)
        f[j][k] =
            min(f[j][k], f[i][j] + s[k][k] - s[j][k] - s[k][j] + s[j][j] +
                             sum[n][j] - sum[n][i] - sum[k][j] + sum[k][i]);
    }
  ll ans = 1e18;
  for (int i = 0; i <= n; i++)
    ans = min(ans, f[i][n]);
  printf("%lld\n", ans);
  return 0;
}