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

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template <class T> inline bool chmax(T &a, const T &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
// constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

constexpr int MOD = 998244353;

long long inv(long long n) {
  long long res = 1;
  while (n > 1) {
    res *= (MOD - MOD / n);
    res %= MOD;
    n = MOD % n;
  }
  return res;
}

void solve() {
  ll n, a, b, k;
  cin >> n >> a >> b >> k;

  vector<ll> comb(n + 1);
  ll nume = 1, deno = 1;
  for (int i = 0; i < n + 1; ++i) {
    comb.at(i) = nume * inv(deno) % MOD;
    nume *= n - i;
    deno *= i + 1;
    nume %= MOD;
    deno %= MOD;
  }

  ll res = 0;
  for (ll i = 0; i <= n; ++i) {
    if (a * i > k)
      break;
    if ((k - a * i) % b == 0) {
      ll j = (k - a * i) / b;
      res += comb.at(i) * comb.at(j);
      res %= MOD;
    }
  }
  cout << res << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);

  solve();

  return 0;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template <class T> inline bool chmax(T &a, const T &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
// constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

constexpr int MOD = 998244353;

long long inv(long long n) {
  long long res = 1;
  while (n > 1) {
    res *= (MOD - MOD / n);
    res %= MOD;
    n = MOD % n;
  }
  return res;
}

void solve() {
  ll n, a, b, k;
  cin >> n >> a >> b >> k;

  vector<ll> comb(n + 1);
  ll nume = 1, deno = 1;
  for (int i = 0; i < n + 1; ++i) {
    comb.at(i) = nume * inv(deno) % MOD;
    nume *= n - i;
    deno *= i + 1;
    nume %= MOD;
    deno %= MOD;
  }

  ll res = 0;
  for (ll i = 0; i <= n; ++i) {
    if (a * i > k)
      break;
    if ((k - a * i) % b == 0) {
      ll j = (k - a * i) / b;
      if (j > n)
        continue;
      res += comb.at(i) * comb.at(j);
      res %= MOD;
    }
  }
  cout << res << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);

  solve();

  return 0;
}
Problem p03332 (C++)

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

using namespace std;

const int N = 3e5 + 5;

long long n;
long long a;
long long b;
long long k;

const int mod = 998244353;

inline int modexp(int a, int x) {
  int res = 1;
  while (x) {
    if (x & 1) {
      res = (long long)res * a % mod;
    }
    a = (long long)a * a % mod;
    x >>= 1;
  }
  return res;
}

int fac[N];
int inv[N];

inline int c(int n, int m) {
  if (m > n) {
    return 0;
  }
  return fac[n] * (long long)inv[m] % mod * inv[n - m] % mod;
}

int main() {
  scanf("%lld %lld %lld %lld", &n, &a, &b, &k);
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fac[i] = (long long)fac[i - 1] * i % mod;
  }
  inv[n] = modexp(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; --i) {
    inv[i] = (long long)inv[i + 1] * (i + 1) % mod;
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    if ((k - i * a) % b == 0) {
      ans = (ans + c(n, i) * (long long)c(n, (k - i * a) / b) % mod) % mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}

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

using namespace std;

const int N = 3e5 + 5;

long long n;
long long a;
long long b;
long long k;

const int mod = 998244353;

inline int modexp(int a, int x) {
  int res = 1;
  while (x) {
    if (x & 1) {
      res = (long long)res * a % mod;
    }
    a = (long long)a * a % mod;
    x >>= 1;
  }
  return res;
}

int fac[N];
int inv[N];

inline int c(int n, int m) {
  if (m > n) {
    return 0;
  }
  if (m < 0) {
    return 0;
  }
  return fac[n] * (long long)inv[m] % mod * inv[n - m] % mod;
}

int main() {
  scanf("%lld %lld %lld %lld", &n, &a, &b, &k);
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fac[i] = (long long)fac[i - 1] * i % mod;
  }
  inv[n] = modexp(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; --i) {
    inv[i] = (long long)inv[i + 1] * (i + 1) % mod;
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    if ((k - i * a) % b == 0) {
      ans = (ans + c(n, i) * (long long)c(n, (k - i * a) / b) % mod) % mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03332 (C++)

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

typedef long long ll;
const ll MOD = 998244353;
const int N = 3e5;

ll dmod(ll x) { return x % MOD; }

ll fe(ll x, ll p) {
  if (p == 0)
    return 1ll;
  if (p == 1)
    return x;
  ll ret = fe(x, p / 2);
  ret = dmod(ret * ret);
  if (p & 1)
    ret = dmod(ret * x);
  return ret;
}

ll fakto[N + 5];

void pre() {
  fakto[0] = 1ll;
  for (int i = 1; i <= N; i++) {
    fakto[i] = dmod(fakto[i - 1] * (ll)i);
  }
  return;
}

ll nCr(ll n, ll r) {
  ll inv = dmod(fakto[r] * fakto[n - r]);
  inv = fe(inv, MOD - 2);
  return dmod(inv * fakto[n]);
}

int n;
ll a, b, k;

int main() {
  pre();
  scanf("%d", &n);
  scanf("%lld%lld%lld", &a, &b, &k);
  ll ans = 0ll;
  for (int i = 0; i <= n; i++) {
    ll dk = k - a * (ll)i;
    if (dk % b != 0)
      continue;
    ll bagi = dk / b;
    if (bagi > n)
      continue;
    ll ret = nCr(n, i);
    ret = dmod(ret * nCr(n, bagi));
    ans = dmod(ans + ret);
  }
  printf("%lld\n", ans);
  return 0;
}


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

typedef long long ll;
const ll MOD = 998244353;
const int N = 3e5;

ll dmod(ll x) { return x % MOD; }

ll fe(ll x, ll p) {
  if (p == 0)
    return 1ll;
  if (p == 1)
    return x;
  ll ret = fe(x, p / 2);
  ret = dmod(ret * ret);
  if (p & 1)
    ret = dmod(ret * x);
  return ret;
}

ll fakto[N + 5];

void pre() {
  fakto[0] = 1ll;
  for (int i = 1; i <= N; i++) {
    fakto[i] = dmod(fakto[i - 1] * (ll)i);
  }
  return;
}

ll nCr(ll n, ll r) {
  ll inv = dmod(fakto[r] * fakto[n - r]);
  inv = fe(inv, MOD - 2);
  return dmod(inv * fakto[n]);
}

int n;
ll a, b, k;

int main() {
  pre();
  scanf("%d", &n);
  scanf("%lld%lld%lld", &a, &b, &k);
  ll ans = 0ll;
  for (int i = 0; i <= n; i++) {
    ll dk = k - a * (ll)i;
    if (dk < 0)
      break;
    if (dk % b != 0)
      continue;
    ll bagi = dk / b;
    if (bagi > n)
      continue;
    ll ret = nCr(n, i);
    ret = dmod(ret * nCr(n, bagi));
    ans = dmod(ans + ret);
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long n, a, b, k, tong, u[300005], x;
long long modd = 998244353;
long long poww(long long i, long long j) {
  if (j == 0)
    return 1ll;
  else {
    long long them;
    them = poww(i, j / 2);
    if (j % 2 == 0)
      return ((them * them) % modd);
    else
      return ((((them * them) % modd) * i) % modd);
  }
}
long long c(long long i) {
  if (i == 0)
    return 1ll;
  else
    return (((x * u[i]) % modd) * u[n - i]) % modd;
}
int main() {
  cin >> n >> a >> b >> k;
  long long i, j, h;
  tong = 0;
  x = 1;
  u[0] = 1;
  for (i = 1; i <= n; i++) {
    x = (x * i) % modd;
    u[i] = (u[i - 1] * poww(i, modd - 2)) % modd;
  }

  for (i = 0; i <= n; i++)
    if (k >= a * i)
      if ((k - a * i) % b == 0)
        if (((k - a * i) / b) + i <= 2 * n) {
          tong = (tong + (c(i) * c((k - a * i) / b)) % modd) % modd;
        }
  cout << tong << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long n, a, b, k, tong, u[300005], x;
long long modd = 998244353;
long long poww(long long i, long long j) {
  if (j == 0)
    return 1ll;
  else {
    long long them;
    them = poww(i, j / 2);
    if (j % 2 == 0)
      return ((them * them) % modd);
    else
      return ((((them * them) % modd) * i) % modd);
  }
}
long long c(long long i) {
  if (i == 0)
    return 1ll;
  else
    return (((x * u[i]) % modd) * u[n - i]) % modd;
}
int main() {
  cin >> n >> a >> b >> k;
  long long i, j, h;
  tong = 0;
  x = 1;
  u[0] = 1;
  for (i = 1; i <= n; i++) {
    x = (x * i) % modd;
    u[i] = (u[i - 1] * poww(i, modd - 2)) % modd;
  }

  for (i = 0; i <= n; i++)
    if (k >= a * i)
      if ((k - a * i) % b == 0)
        if (((k - a * i) / b) <= n) {
          tong = (tong + (c(i) * c((k - a * i) / b)) % modd) % modd;
        }
  cout << tong << endl;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MOD 998244353
using namespace std;
typedef long long ll;
ll N, A, B, K;
ll qpow(ll x, int n, ll d = 1) {
  for (; n; n >>= 1, x = x * x % MOD)
    if (n & 1)
      d = d * x % MOD;
  return d;
}
const int maxn = 3e5 + 10;
ll jc[maxn];
ll C(int a, int b) {
  return jc[a] * qpow(jc[b] * jc[a - b] % MOD, MOD - 2) % MOD;
}
int main() {
  cin >> N >> A >> B >> K;
  if (B == 0 && A != 0)
    swap(A, B);
  if (A == 0 && B == 0) {
    if (K == 0)
      cout << qpow(4, N) << endl;
    else
      cout << 0 << endl;
  }
  jc[0] = 1;
  for (int i = 1; i < maxn; ++i)
    jc[i] = jc[i - 1] * i % MOD;
  ll ans = 0;
  for (ll a = 0; a <= N; ++a) {
    if ((K - a * A) % B != 0)
      continue;
    ll b = (K - a * A) / B;
    if (b > N)
      continue;
    //	cerr << a << ' ' << b << endl;
    // cerr << C(N,a)*C(N,b) << endl;
    (ans += C(N, a) * C(N, b) % MOD) %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define MOD 998244353
using namespace std;
typedef long long ll;
ll N, A, B, K;
ll qpow(ll x, int n, ll d = 1) {
  for (; n; n >>= 1, x = x * x % MOD)
    if (n & 1)
      d = d * x % MOD;
  return d;
}
const int maxn = 3e5 + 10;
ll jc[maxn];
ll C(int a, int b) {
  return jc[a] * qpow(jc[b] * jc[a - b] % MOD, MOD - 2) % MOD;
}
int main() {
  cin >> N >> A >> B >> K;
  if (B == 0 && A != 0)
    swap(A, B);
  if (A == 0 && B == 0) {
    if (K == 0)
      cout << qpow(4, N) << endl;
    else
      cout << 0 << endl;
  }
  jc[0] = 1;
  for (int i = 1; i < maxn; ++i)
    jc[i] = jc[i - 1] * i % MOD;
  ll ans = 0;
  for (ll a = 0; a <= N; ++a) {
    if (K - a * A < 0 || (K - a * A) % B != 0)
      continue;
    ll b = (K - a * A) / B;
    if (b > N)
      continue;
    //	cerr << a << ' ' << b << endl;
    // cerr << C(N,a)*C(N,b) << endl;
    (ans += C(N, a) * C(N, b) % MOD) %= MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int mx = 300005;
const int md = 998244353;
int n, t = md - 2;
long long fact[mx] = {1}, a, b, k, u, in[mx], comb[mx], ans;

int main() {
  scanf("%d%lld%lld%lld", &n, &a, &b, &k);
  for (int i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * i % md;
  u = fact[n];
  in[n] = 1;
  while (t) {
    if (t & 1)
      in[n] = in[n] * u % md;
    u = u * u % md;
    t >>= 1;
  }
  for (int i = n; i > 0; i--)
    in[i - 1] = in[i] * i % md;
  for (int i = 0; i <= n; i++)
    comb[i] = fact[n] * in[n - i] % md * in[i] % md;
  for (int i = 0; i <= n; i++) {
    if ((k - a * i) % b == 0) {
      long long u = (k - a * i) / b;
      if (u <= n)
        ans = (ans + comb[i] * comb[u]) % md;
    }
  }
  printf("%lld\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int mx = 300005;
const int md = 998244353;
int n, t = md - 2;
long long fact[mx] = {1}, a, b, k, u, in[mx], comb[mx], ans;

int main() {
  scanf("%d%lld%lld%lld", &n, &a, &b, &k);
  for (int i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * i % md;
  u = fact[n];
  in[n] = 1;
  while (t) {
    if (t & 1)
      in[n] = in[n] * u % md;
    u = u * u % md;
    t >>= 1;
  }
  for (int i = n; i > 0; i--)
    in[i - 1] = in[i] * i % md;
  for (int i = 0; i <= n; i++)
    comb[i] = fact[n] * in[n - i] % md * in[i] % md;
  for (int i = 0; i <= n; i++) {
    if ((k - a * i) % b == 0) {
      long long u = (k - a * i) / b;
      if (0 <= u && u <= n)
        ans = (ans + comb[i] * comb[u]) % md;
    }
  }
  printf("%lld\n", ans);
}
Problem p03332 (C++)

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

typedef long long ll;

const ll MOD = 998244353;

ll ncr[300005];
ll fact[300005];
ll inv[300005];

ll ex(ll a, ll b) {
  if (b == 0)
    return 1;
  ll r = ex(a, b >> 1);
  r *= r;
  r %= MOD;
  if (b & 1)
    r = (r * a) % MOD;
  return r;
}

int main() {
  ll n, a, b, k, ans = 0;
  cin >> n >> a >> b >> k;

  fact[0] = 1;
  inv[0] = 1;
  for (ll i = 1; i <= n; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
    inv[i] = ex(fact[i], MOD - 2);
  }
  for (ll i = 0; i <= n; i++) {
    ncr[i] = fact[n] * inv[i];
    ncr[i] %= MOD;
    ncr[i] *= inv[n - i];
    ncr[i] %= MOD;
  }

  for (ll i = 0; i <= n; i++) {
    ll rem = k - i * a;
    if (rem >= 0 && rem % b == 0) {
      ans += ncr[i] * ncr[rem / b];
      ans %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;

const ll MOD = 998244353;

ll ncr[300005];
ll fact[300005];
ll inv[300005];

ll ex(ll a, ll b) {
  if (b == 0)
    return 1;
  ll r = ex(a, b >> 1);
  r *= r;
  r %= MOD;
  if (b & 1)
    r = (r * a) % MOD;
  return r;
}

int main() {
  ll n, a, b, k, ans = 0;
  cin >> n >> a >> b >> k;

  fact[0] = 1;
  inv[0] = 1;
  for (ll i = 1; i <= n; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
    inv[i] = ex(fact[i], MOD - 2);
  }
  for (ll i = 0; i <= n; i++) {
    ncr[i] = fact[n] * inv[i];
    ncr[i] %= MOD;
    ncr[i] *= inv[n - i];
    ncr[i] %= MOD;
  }

  for (ll i = 0; i <= n; i++) {
    ll rem = k - i * a;
    if (rem >= 0 && rem % b == 0 && rem / b <= n) {
      ans += ncr[i] * ncr[rem / b];
      ans %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 998244353
#define INF (1 << 29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))

Int mod_pow(Int x, Int a, Int m = MOD) {
  if (a == 0)
    return 1;
  Int res = mod_pow(x, a / 2, m);
  res = res * res % m;
  if (a % 2)
    res *= x;
  return res % m;
}

Int inv(Int x) { return mod_pow(x, MOD - 2); }

Int fact[324000], res;

Int nCk(Int n, Int k) {
  if (n < k)
    return 0;
  return fact[n] * inv(fact[k]) % MOD * inv(fact[n - k]) % MOD;
}

int main() {
  fact[0] = 1;
  for (Int i = 1; i < 324000; i++)
    fact[i] = fact[i - 1] * i % MOD;
  Int n, a, b, k;
  cin >> n >> a >> b >> k;
  for (Int i = 0; i <= n; i++) {
    Int red = i;
    if ((k - red * a) % b)
      continue;
    Int blue = (k - red * a) / b;
    if (blue > n)
      continue;
    res += nCk(n, red) * nCk(n, blue) % MOD;
    res %= MOD;
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 998244353
#define INF (1 << 29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))

Int mod_pow(Int x, Int a, Int m = MOD) {
  if (a == 0)
    return 1;
  Int res = mod_pow(x, a / 2, m);
  res = res * res % m;
  if (a % 2)
    res *= x;
  return res % m;
}

Int inv(Int x) { return mod_pow(x, MOD - 2); }

Int fact[324000], res;

Int nCk(Int n, Int k) {
  if (n < k)
    return 0;
  return fact[n] * inv(fact[k]) % MOD * inv(fact[n - k]) % MOD;
}

int main() {
  fact[0] = 1;
  for (Int i = 1; i < 324000; i++)
    fact[i] = fact[i - 1] * i % MOD;
  Int n, a, b, k;
  cin >> n >> a >> b >> k;
  for (Int i = 0; i <= n; i++) {
    Int red = i;
    if ((k - red * a) % b)
      continue;
    Int blue = (k - red * a) / b;
    if (blue > n || blue < 0)
      continue;
    res += nCk(n, red) * nCk(n, blue) % MOD;
    res %= MOD;
  }
  cout << res << endl;
  return 0;
}
Problem p03332 (C++)

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

using namespace std;

long long n, a, b, k, pref[300005], suff[300005], ans = 0;
const long long mod = 998244353;

long long BinPow(long long x, long long n) {
  if (n == 0)
    return 1;
  else if (n == 1)
    return x;
  else {
    long long sum = BinPow(x, n / 2);
    sum *= sum;
    sum %= mod;
    if (n % 2 != 0)
      sum *= x;
    sum %= mod;
    return sum;
  }
}

long long C(long long s, long long k) {
  return (((pref[s] * suff[k]) % mod) * suff[s - k]) % mod;
}

int main() {
  cin.tie(0), ios::sync_with_stdio(0);
  cin >> n >> a >> b >> k;
  pref[0] = 1, suff[0] = 1;
  for (int i = 1; i <= n; i++) {
    pref[i] = pref[i - 1] * i;
    pref[i] %= mod;
  }
  for (int i = 1; i <= n; i++) {
    suff[i] = BinPow(pref[i], mod - 2);
    suff[i] %= mod;
  }
  for (long long i = 0; i <= n; i++) {
    if ((k - a * i) % b == 0 && (k - a * i) >= 0) {
      long long times = (k - a * i) / b;
      ans += (C(n, times) * C(n, i)) % mod;
      ans %= mod;
    }
  }
  cout << ans;
}


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

using namespace std;

long long n, a, b, k, pref[300005], suff[300005], ans = 0;
const long long mod = 998244353;

long long BinPow(long long x, long long n) {
  if (n == 0)
    return 1;
  else if (n == 1)
    return x;
  else {
    long long sum = BinPow(x, n / 2);
    sum *= sum;
    sum %= mod;
    if (n % 2 != 0)
      sum *= x;
    sum %= mod;
    return sum;
  }
}

long long C(long long s, long long k) {
  return (((pref[s] * suff[k]) % mod) * suff[s - k]) % mod;
}

int main() {
  cin.tie(0), ios::sync_with_stdio(0);
  cin >> n >> a >> b >> k;
  pref[0] = 1, suff[0] = 1;
  for (int i = 1; i <= n; i++) {
    pref[i] = pref[i - 1] * i;
    pref[i] %= mod;
  }
  for (int i = 1; i <= n; i++) {
    suff[i] = BinPow(pref[i], mod - 2);
    suff[i] %= mod;
  }
  for (long long i = 0; i <= n; i++) {
    if ((k - a * i) % b == 0 && (k - a * i) >= 0) {
      long long times = (k - a * i) / b;
      if (times <= n) {
        ans += (C(n, times) * C(n, i)) % mod;
        ans %= mod;
      }
    }
  }
  cout << ans;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.14159265358979
#define EPS 1e-8

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define endl "\n"

const ll INF = (ll)2e18;

const ll mod = (ll)998244353;
const int N = 2e5 + 5;

ll fac[300050] = {0};
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

ll modinverse(ll a, ll m) { return binpow(a, m - 2, m); }

ll ncr(ll a, ll b) {
  return fac[a] * modinverse(fac[b], mod) % mod * modinverse(fac[a - b], mod) %
         mod;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, a, b, k;
  cin >> n >> a >> b >> k;

  fac[0] = 1;

  for (ll i = 1; i <= 300000; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
  }
  ll ans2 = 0;

  for (ll i = 0; i <= n; i++) {
    ll val = i * a;

    if (k >= (i * a) && (k - i * a) % b == 0) {
      ll val1 = i;
      ll val2 = (k - i * a) / b;
      ll ans1;
      ans1 = ncr(n, val1);
      ans1 *= ncr(n, val2);
      ans1 %= mod;
      ans2 += ans1;
      ans2 %= mod;
    }
  }

  cout << ans2;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.14159265358979
#define EPS 1e-8

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define endl "\n"

const ll INF = (ll)2e18;

const ll mod = (ll)998244353;
const int N = 2e5 + 5;

ll fac[300050] = {0};
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

ll modinverse(ll a, ll m) { return binpow(a, m - 2, m); }

ll ncr(ll a, ll b) {
  return fac[a] * modinverse(fac[b], mod) % mod * modinverse(fac[a - b], mod) %
         mod;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, a, b, k;
  cin >> n >> a >> b >> k;

  fac[0] = 1;

  for (ll i = 1; i <= 300000; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
  }
  ll ans2 = 0;

  for (ll i = 0; i <= n; i++) {
    ll val = i * a;

    if (k >= (i * a) && (k - i * a) % b == 0) {
      ll val1 = i;
      ll val2 = (k - i * a) / b;
      ll ans1;
      if (val2 > n)
        continue;
      ans1 = ncr(n, val1);
      ans1 *= ncr(n, val2);
      ans1 %= mod;
      ans2 += ans1;
      ans2 %= mod;
    }
  }

  cout << ans2;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
// Compiler version g++ 6.3.0
#define MOD 998244353
int InvMod(int a) {
  int b = MOD - 2, Ans = 1, P = a;
  for (int i = 0; (1 << i) <= b; ++i) {
    if ((1 << i) & b) {
      Ans = 1LL * Ans * P % MOD;
    }
    P = (1LL * P * P) % MOD;
  }
  return Ans;
}
int fact[300001];
int C(int n, int k) {
  return 1LL * fact[n] * InvMod(fact[k]) % MOD * InvMod(fact[n - k]) % MOD;
}
int main() {
  fact[0] = 1;
  for (int i = 1; i <= 300000; ++i)
    fact[i] = 1LL * i * fact[i - 1] % MOD;
  int n, a, b;
  long long k;
  scanf("%d %d %d %lld", &n, &a, &b, &k);
  int ct = 0;
  for (int i = 0; i <= n; ++i) {
    long long aux = k - 1LL * i * a;
    if (aux < 0 || aux % b != 0)
      continue;
    long long j = aux / b;
    ct = (ct + 1LL * C(n, i) * C(n, j) % MOD) % MOD;
  }
  printf("%d", ct);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// Compiler version g++ 6.3.0
#define MOD 998244353
int InvMod(int a) {
  int b = MOD - 2, Ans = 1, P = a;
  for (int i = 0; (1 << i) <= b; ++i) {
    if ((1 << i) & b) {
      Ans = 1LL * Ans * P % MOD;
    }
    P = (1LL * P * P) % MOD;
  }
  return Ans;
}
int fact[300001];
int C(int n, int k) {
  return 1LL * fact[n] * InvMod(fact[k]) % MOD * InvMod(fact[n - k]) % MOD;
}
int main() {
  fact[0] = 1;
  for (int i = 1; i <= 300000; ++i)
    fact[i] = 1LL * i * fact[i - 1] % MOD;
  int n, a, b;
  long long k;
  scanf("%d %d %d %lld", &n, &a, &b, &k);
  int ct = 0;
  for (int i = 0; i <= n; ++i) {
    long long aux = k - 1LL * i * a;
    if (aux < 0 || aux % b != 0)
      continue;
    int j = aux / b;
    if (j > n)
      continue;
    ct = (ct + 1LL * C(n, i) * C(n, j) % MOD) % MOD;
  }
  printf("%d", ct);
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll F[N], I[N];
inline ll sum(ll a, ll b) { return (a + b) % Mod; }
inline ll mul(ll a, ll b) { return (a * b) % Mod; }
inline ll pw(ll x, ll y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      res = mul(res, x);
    x = mul(x, x);
    y >>= 1;
  }
  return res;
}
inline ll C(ll r, ll n) {
  if (r < 0 || r > n)
    return 0;
  return mul(F[n], mul(I[r], I[n - r]));
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  F[0] = 1;
  for (int i = 1; i < N; i++)
    F[i] = mul(i, F[i - 1]);
  I[N - 1] = pw(F[N - 1], Mod - 2);
  for (int i = N - 2; i >= 0; i--)
    I[i] = mul(i + 1, I[i + 1]);
  ll n, k, a, b;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll tmp = i * a;
    tmp = k - tmp;
    if (tmp % b)
      continue;
    tmp /= b;
    ans = sum(ans, mul(C(i, n), C(tmp, n)));
  }
  cout << ans;

  return (0);
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 6e5 + 30, Mod = 998244353;
const ll SQ = 330;

ll F[N], I[N];
inline ll sum(ll a, ll b) { return (a + b) % Mod; }
inline ll mul(ll a, ll b) { return (a * b) % Mod; }
inline ll pw(ll x, ll y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      res = mul(res, x);
    x = mul(x, x);
    y >>= 1;
  }
  return res;
}
inline ll C(ll r, ll n) {
  if (r < 0 || r > n)
    return 0;
  return mul(F[n], mul(I[r], I[n - r]));
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  F[0] = 1;
  for (int i = 1; i < N; i++)
    F[i] = mul(i, F[i - 1]);
  I[N - 1] = pw(F[N - 1], Mod - 2);
  for (int i = N - 2; i >= 0; i--)
    I[i] = mul(i + 1, I[i + 1]);
  ll n, k, a, b;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll tmp = i * a;
    tmp = k - tmp;
    if (tmp % b)
      continue;
    tmp /= b;
    ans = sum(ans, mul(C(i, n), C(tmp, n)));
  }
  cout << ans;

  return (0);
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define INF 1e+18
#define MOD 998244353
using namespace std;

int mod_inv(int X) {
  int a = X, b = MOD, u = 1, v = 0;
  while (b) {
    int t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  if (u < 0)
    u += MOD;
  return u;
}

vector<int> fact, factinv;

void nCr_init(int N) {
  N = min(N, (int)MOD);
  fact.resize(N + 1);
  factinv.resize(N + 1);
  fact[0] = 1;
  for (int i = 1; i <= N; i++)
    fact[i] = fact[i - 1] * i % MOD;
  factinv[N] = mod_inv(fact[N]);
  for (int i = N; i >= 1; i--)
    factinv[i - 1] = factinv[i] * i % MOD;
}

int nCr(int ncr_n, int ncr_r) {
  if (ncr_n >= MOD)
    return nCr(ncr_n % MOD, ncr_r % MOD) * nCr(ncr_n / MOD, ncr_r / MOD) % MOD;
  return ncr_r > ncr_n ? 0
                       : fact[ncr_n] * factinv[ncr_n - ncr_r] % MOD *
                             factinv[ncr_r] % MOD;
}

signed main() {
  int n, a, b, k, ans = 0;
  cin >> n >> a >> b >> k;
  nCr_init(n + 5);
  for (int i = 0; i <= n; i++) {
    if ((k - a * i) % b == 0) {
      (ans += nCr(n, i) * nCr(n, (k - a * i) / b) % MOD) %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define INF 1e+18
#define MOD 998244353
using namespace std;

int mod_inv(int X) {
  int a = X, b = MOD, u = 1, v = 0;
  while (b) {
    int t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  if (u < 0)
    u += MOD;
  return u;
}

vector<int> fact, factinv;

void nCr_init(int N) {
  N = min(N, (int)MOD);
  fact.resize(N + 1);
  factinv.resize(N + 1);
  fact[0] = 1;
  for (int i = 1; i <= N; i++)
    fact[i] = fact[i - 1] * i % MOD;
  factinv[N] = mod_inv(fact[N]);
  for (int i = N; i >= 1; i--)
    factinv[i - 1] = factinv[i] * i % MOD;
}

int nCr(int ncr_n, int ncr_r) {
  if (ncr_n >= MOD)
    return nCr(ncr_n % MOD, ncr_r % MOD) * nCr(ncr_n / MOD, ncr_r / MOD) % MOD;
  return ncr_r > ncr_n ? 0
                       : fact[ncr_n] * factinv[ncr_n - ncr_r] % MOD *
                             factinv[ncr_r] % MOD;
}

signed main() {
  int n, a, b, k, ans = 0;
  cin >> n >> a >> b >> k;
  nCr_init(n + 5);
  for (int i = 0; i <= n; i++) {
    if (k >= a * i && (k - a * i) % b == 0) {
      (ans += nCr(n, i) * nCr(n, (k - a * i) / b) % MOD) %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03332 (C++)

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

constexpr ll MOD = 998244353;

vector<ll> fact, inv_fact;

ll combination(ll n, ll m) {
  return fact[n] * inv_fact[n - m] % MOD * inv_fact[m] % MOD;
}

ll POW(ll n, ll m) {
  ll result = 1;
  while (m) {
    if (m & 1) {
      result *= n;
      result %= MOD;
    }

    m /= 2;
    n *= n;
    n %= MOD;
  }
  return result;
}

int main() {
  ll N, A, B, K;
  cin >> N >> A >> B >> K;

  // 緑→紫として紫は赤と青が同時に塗られている場所とすると
  // N個のブロックから赤をi個,青をj個それぞれ独立に選んで色
  // を塗ることとして良い

  // fact, inv_factの準備
  fact.resize(N + 1, 1);
  inv_fact.resize(N + 1, 1);
  for (ll i = 2; i <= N; i++) {
    fact[i] = i * fact[i - 1] % MOD;
    inv_fact[i] = POW(fact[i], MOD - 2);
    assert(fact[i] * inv_fact[i] % MOD == 1);
  }

  ll ans = 0;
  for (ll i = 0; i <= N; i++) {
    if (i * A > K) {
      continue;
    }

    if ((K - i * A) % B == 0) {
      ll j = (K - i * A) / B;
      ans += combination(N, i) * combination(N, j) % MOD;
      ans %= MOD;
    }
  }

  cout << ans << endl;
}

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

constexpr ll MOD = 998244353;

vector<ll> fact, inv_fact;

ll combination(ll n, ll m) {
  return fact[n] * inv_fact[n - m] % MOD * inv_fact[m] % MOD;
}

ll POW(ll n, ll m) {
  ll result = 1;
  while (m) {
    if (m & 1) {
      result *= n;
      result %= MOD;
    }

    m /= 2;
    n *= n;
    n %= MOD;
  }
  return result;
}

int main() {
  ll N, A, B, K;
  cin >> N >> A >> B >> K;

  // 緑→紫として紫は赤と青が同時に塗られている場所とすると
  // N個のブロックから赤をi個,青をj個それぞれ独立に選んで色
  // を塗ることとして良い

  // fact, inv_factの準備
  fact.resize(N + 1, 1);
  inv_fact.resize(N + 1, 1);
  for (ll i = 2; i <= N; i++) {
    fact[i] = i * fact[i - 1] % MOD;
    inv_fact[i] = POW(fact[i], MOD - 2);
    assert(fact[i] * inv_fact[i] % MOD == 1);
  }

  ll ans = 0;
  for (ll i = 0; i <= N; i++) {
    if (i * A > K) {
      continue;
    }

    if ((K - i * A) % B == 0) {
      ll j = (K - i * A) / B;
      if (j > N) {
        continue;
      }
      ans += combination(N, i) * combination(N, j) % MOD;
      ans %= MOD;
    }
  }

  cout << ans << endl;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll kai[300001];
ll mokai[300001];

ll mod_pow(ll x, ll y) {
  ll ret = 1;
  while (y) {
    if (y & 1)
      ret = ret * x % MOD;
    x = x * x % MOD;
    y /= 2;
  }
  return ret;
}

void init(int _n) {
  kai[0] = 1;
  for (int i = 1; i <= _n; i++)
    kai[i] = kai[i - 1] * i % MOD;
  for (int i = 0; i <= _n; i++)
    mokai[i] = mod_pow(kai[i], MOD - 2);
}

ll conb(ll x, ll y) {
  ll z = x - y;
  ll ret = kai[x] * mokai[y] % MOD;
  ret = ret * mokai[z] % MOD;
  return ret;
}

ll n, a, b, k;

int main() {
  init(300000);
  cin >> n >> a >> b >> k;
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    ll j = k - a * i;
    if (j < 0 || j % b != 0)
      continue;
    j /= b;
    ans = (ans + conb(n, i) * conb(n, j)) % MOD;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll kai[300001];
ll mokai[300001];

ll mod_pow(ll x, ll y) {
  ll ret = 1;
  while (y) {
    if (y & 1)
      ret = ret * x % MOD;
    x = x * x % MOD;
    y /= 2;
  }
  return ret;
}

void init(int _n) {
  kai[0] = 1;
  for (int i = 1; i <= _n; i++)
    kai[i] = kai[i - 1] * i % MOD;
  for (int i = 0; i <= _n; i++)
    mokai[i] = mod_pow(kai[i], MOD - 2);
}

ll conb(ll x, ll y) {
  ll z = x - y;
  ll ret = kai[x] * mokai[y] % MOD;
  ret = ret * mokai[z] % MOD;
  return ret;
}

ll n, a, b, k;

int main() {
  init(300000);
  cin >> n >> a >> b >> k;
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    ll j = k - a * i;
    if (j < 0 || j % b != 0)
      continue;
    j /= b;
    if (j > n)
      continue;
    ans = (ans + conb(n, i) * conb(n, j)) % MOD;
  }
  cout << ans << endl;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int N, A, B;
long long K;
const int MOD = 998244353;
int Fact[300005], Inv[300005];
int ans;
int power(int n, int p) {
  int sol = 1;
  while (p) {
    if (p % 2 == 1) {
      sol = (1LL * sol * n) % MOD;
    }
    p /= 2;
    n = (1LL * n * n) % MOD;
  }
  return sol;
}

void precalcFact() {
  Fact[0] = 1;
  for (int i = 1; i <= N; i++)
    Fact[i] = (1LL * Fact[i - 1] * i) % MOD;
  Inv[N] = power(Fact[N], MOD - 2);
  for (int i = N - 1; i >= 0; i--) {
    Inv[i] = (1LL * Inv[i + 1] * (i + 1)) % MOD;
  }
}

int Comb(int n, int k) {
  return (((1LL * Fact[n] * Inv[n - k]) % MOD) * Inv[k]) % MOD;
}
void Read() { cin >> N >> A >> B >> K; }
int main() {
  Read();
  precalcFact();
  for (int i = 0; i <= N; i++) {
    long long sum = (1LL * i * A);
    long long rem = K - sum;
    if (rem % B != 0 || rem / B > N)
      continue;
    ans += (1LL * Comb(N, i) * Comb(N, rem / B)) % MOD;
    if (ans >= MOD)
      ans -= MOD;
  }
  cout << ans << "\n";
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int N, A, B;
long long K;
const int MOD = 998244353;
int Fact[300005], Inv[300005];
int ans;
int power(int n, int p) {
  int sol = 1;
  while (p) {
    if (p % 2 == 1) {
      sol = (1LL * sol * n) % MOD;
    }
    p /= 2;
    n = (1LL * n * n) % MOD;
  }
  return sol;
}

void precalcFact() {
  Fact[0] = 1;
  for (int i = 1; i <= N; i++)
    Fact[i] = (1LL * Fact[i - 1] * i) % MOD;
  Inv[N] = power(Fact[N], MOD - 2);
  for (int i = N - 1; i >= 0; i--) {
    Inv[i] = (1LL * Inv[i + 1] * (i + 1)) % MOD;
  }
}

int Comb(int n, int k) {
  return (((1LL * Fact[n] * Inv[n - k]) % MOD) * Inv[k]) % MOD;
}
void Read() { cin >> N >> A >> B >> K; }
int main() {
  Read();
  precalcFact();
  for (int i = 0; i <= N; i++) {
    long long sum = (1LL * i * A);
    long long rem = K - sum;
    if (rem < 0 || rem % B != 0 || rem / B > N)
      continue;
    ans += (1LL * Comb(N, i) * Comb(N, rem / B)) % MOD;
    if (ans >= MOD)
      ans -= MOD;
  }
  cout << ans << "\n";
  return 0;
}
Problem p03332 (C++)

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> ii;

const int N = 5e5 + 5;
const int mod = 998244353;

int fac[N], inv[N], ans;
ll n, k, a, b;

inline int mul(int x, int y) { return (ll)x * y % mod; }

inline int add(int x, int y) { return (x + y) % mod; }

inline int comb(int n, int r) { return mul(fac[n], mul(inv[n - r], inv[r])); }

int fast_pow(int x, int y) {
  if (y == 0)
    return 1;
  int res = fast_pow(x, y / 2);
  res = mul(res, res);
  if (y % 2 == 1)
    res = mul(res, x);
  return res;
}

void furkan_i_love_u() {
  fac[0] = inv[0] = 1;
  for (int i = 1; i < N; i++) {
    fac[i] = mul(fac[i - 1], i);
    inv[i] = fast_pow(fac[i], mod - 2);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  furkan_i_love_u();
  cin >> n >> a >> b >> k;
  for (int i = 0; i <= n; i++) {
    if ((k - i * a) % b == 0) {
      int j = (k - i * a) / b;
      if (j > n)
        continue;
      ans = add(ans, mul(comb(n, i), comb(n, j)));
    }
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> ii;

const int N = 5e5 + 5;
const int mod = 998244353;

int fac[N], inv[N], ans;
ll n, k, a, b;

inline int mul(int x, int y) { return (ll)x * y % mod; }

inline int add(int x, int y) { return (x + y) % mod; }

inline int comb(int n, int r) { return mul(fac[n], mul(inv[n - r], inv[r])); }

int fast_pow(int x, int y) {
  if (y == 0)
    return 1;
  int res = fast_pow(x, y / 2);
  res = mul(res, res);
  if (y % 2 == 1)
    res = mul(res, x);
  return res;
}

void furkan_i_love_u() {
  fac[0] = inv[0] = 1;
  for (int i = 1; i < N; i++) {
    fac[i] = mul(fac[i - 1], i);
    inv[i] = fast_pow(fac[i], mod - 2);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  furkan_i_love_u();
  cin >> n >> a >> b >> k;
  for (int i = 0; i <= n; i++) {
    if ((k - i * a) % b == 0 && k >= i * a) {
      int j = (k - i * a) / b;
      if (j > n)
        continue;
      ans = add(ans, mul(comb(n, i), comb(n, j)));
    }
  }
  cout << ans << endl;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 998244353;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

ll Pow(ll n, ll p) {
  ll r = 1;
  for (; p > 0; p >>= 1) {
    if (p & 1)
      r = (r * n) % mod;
    n = (n * n) % mod;
  }
  return r;
}

const int M = 100005;
ll F[M];

void Init() {
  F[0] = 1;
  for (int i = 1; i < M; i++)
    F[i] = F[i - 1] * i % mod;
}

ll Div(ll n, ll m) { return n * Pow(m, mod - 2) % mod; }

ll nCk(ll n, ll k) { return Div(F[n], F[n - k] * F[k] % mod); }

ll n, A, B, m;

int main() {
  Init();
  cin >> n >> A >> B >> m;
  ll res = 0;
  for (ll i = 0; i <= n; i++) {
    ll m_ = m - A * i;
    if (m_ >= 0 && m_ % B == 0) {
      ll x = i, y = m_ / B;
      if (x > n || y > n)
        continue;
      (res += nCk(n, x) * nCk(n, y)) %= mod;
    }
  }
  cout << res << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 998244353;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

ll Pow(ll n, ll p) {
  ll r = 1;
  for (; p > 0; p >>= 1) {
    if (p & 1)
      r = (r * n) % mod;
    n = (n * n) % mod;
  }
  return r;
}

const int M = 500005;
ll F[M];

void Init() {
  F[0] = 1;
  for (int i = 1; i < M; i++)
    F[i] = F[i - 1] * i % mod;
}

ll Div(ll n, ll m) { return n * Pow(m, mod - 2) % mod; }

ll nCk(ll n, ll k) { return Div(F[n], F[n - k] * F[k] % mod); }

ll n, A, B, m;

int main() {
  Init();
  cin >> n >> A >> B >> m;
  ll res = 0;
  for (ll i = 0; i <= n; i++) {
    ll m_ = m - A * i;
    if (m_ >= 0 && m_ % B == 0) {
      ll x = i, y = m_ / B;
      if (x > n || y > n)
        continue;
      (res += nCk(n, x) * nCk(n, y)) %= mod;
    }
  }
  cout << res << endl;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template <typename T> void readvec(vector<T> &a);
void readindex(vector<int> &a);

int extgcd(int a, int b, int &x, int &y) {
  int d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

int mod_inverse(int a, int m) {
  int x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}

signed main() {

  int M = 998244353;
  int N, A, B, K;
  cin >> N >> A >> B >> K;

  int ans = 0;
  vector<int> fact(N + 1, 1);
  FOR(i, 1, N + 1) { fact[i] = (fact[i - 1] * i) % M; }
  REP(a, N + 1) {
    if ((K - a * A) % B == 0) {
      int b = (K - a * A) / B;
      if (b > N)
        continue;
      int tmp1 = (((fact[N] * mod_inverse(fact[a], M)) % M) *
                  mod_inverse(fact[N - a], M)) %
                 M;
      int tmp2 = (((fact[N] * mod_inverse(fact[b], M)) % M) *
                  mod_inverse(fact[N - b], M)) %
                 M;
      ans = (ans + tmp1 * tmp2) % M;
    }
  }

  cout << ans;

  return 0;
}

template <typename T> void readvec(vector<T> &a) {
  REP(i, a.size()) { cin >> a[i]; }
}
void readindex(vector<int> &a) {
  REP(i, a.size()) {
    cin >> a[i];
    a[i]--;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template <typename T> void readvec(vector<T> &a);
void readindex(vector<int> &a);

int extgcd(int a, int b, int &x, int &y) {
  int d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

int mod_inverse(int a, int m) {
  int x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}

signed main() {

  int M = 998244353;
  int N, A, B, K;
  cin >> N >> A >> B >> K;

  int ans = 0;
  vector<int> fact(N + 1, 1);
  FOR(i, 1, N + 1) { fact[i] = (fact[i - 1] * i) % M; }
  REP(a, N + 1) {
    if ((K - a * A) % B == 0) {
      int b = (K - a * A) / B;
      if (b < 0 || b > N)
        continue;
      int tmp1 = (((fact[N] * mod_inverse(fact[a], M)) % M) *
                  mod_inverse(fact[N - a], M)) %
                 M;
      int tmp2 = (((fact[N] * mod_inverse(fact[b], M)) % M) *
                  mod_inverse(fact[N - b], M)) %
                 M;
      ans = (ans + tmp1 * tmp2) % M;
    }
  }

  cout << ans;

  return 0;
}

template <typename T> void readvec(vector<T> &a) {
  REP(i, a.size()) { cin >> a[i]; }
}
void readindex(vector<int> &a) {
  REP(i, a.size()) {
    cin >> a[i];
    a[i]--;
  }
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

ll MOD = 998244353;
ll F[300010];
ll I[300010];

ll power(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b % 2) {
      res *= a;
      res %= MOD;
    }
    a *= a;
    a %= MOD;
    b /= 2;
  }
  return res;
}

void init() {
  F[0] = 1;
  for (int i = 1; i <= 300000; i++) {
    F[i] = (F[i - 1] * i) % MOD;
  }
  I[300000] = power(F[300000], MOD - 2);
  for (int i = 299999; i >= 0; i--) {
    I[i] = (I[i + 1] * (i + 1)) % MOD;
  }
  return;
}

ll nchoosek(ll a, ll b) {
  ll d = (I[b] * I[a - b]) % MOD;
  return (F[a] * d) % MOD;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  init();
  ll res = 0;
  int N;
  ll A, B, K;
  cin >> N >> A >> B >> K;
  for (int i = 0; i <= N; i++) {
    if ((K - A * i) % B != 0)
      continue;
    ll num = (K - A * i) / B;
    if (num > N)
      continue;
    res += (nchoosek(N, i) * nchoosek(N, num)) % MOD;
    res %= MOD;
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

ll MOD = 998244353;
ll F[300010];
ll I[300010];

ll power(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b % 2) {
      res *= a;
      res %= MOD;
    }
    a *= a;
    a %= MOD;
    b /= 2;
  }
  return res;
}

void init() {
  F[0] = 1;
  for (int i = 1; i <= 300000; i++) {
    F[i] = (F[i - 1] * i) % MOD;
  }
  I[300000] = power(F[300000], MOD - 2);
  for (int i = 299999; i >= 0; i--) {
    I[i] = (I[i + 1] * (i + 1)) % MOD;
  }
  return;
}

ll nchoosek(ll a, ll b) {
  ll d = (I[b] * I[a - b]) % MOD;
  return (F[a] * d) % MOD;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  init();
  ll res = 0;
  int N;
  ll A, B, K;
  cin >> N >> A >> B >> K;
  for (int i = 0; i <= N; i++) {
    if (A * i > K)
      continue;
    if ((K - A * i) % B != 0)
      continue;
    ll num = (K - A * i) / B;
    if (num > N)
      continue;
    res += (nchoosek(N, i) * nchoosek(N, num)) % MOD;
    res %= MOD;
  }
  cout << res << endl;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
// #include <bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repp(i, m, n) for (int i = m; i < (int)n; i++)
#define reps(i, n) for (int i = 1; i <= (int)n; i++)
#define pb push_back
const int INF = 100000000;
const double EPS = 1e-10;
const long long MOD = 998244353;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;

ll kaijo[100010], inv[100010];

ll beki(ll a, ll b) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0) {
    ll tmp = beki(a, b / 2);
    return (tmp * tmp) % MOD;
  } else
    return (beki(a, b - 1) * a) % MOD;
}

ll inv_(ll a) { return beki(a, MOD - 2); }

ll comb(ll a, ll b) { return (kaijo[a] * inv[b]) % MOD * inv[a - b] % MOD; }

int main() {
  ll n, a, b, k;
  cin >> n >> a >> b >> k;

  kaijo[0] = 1;
  inv[0] = 1;
  reps(i, n) {
    kaijo[i] = ((ll)kaijo[i - 1] * (ll)i) % MOD;
    inv[i] = inv_(kaijo[i]);
  }

  ll ans = 0;

  rep(i, n + 1) {
    ll t = k - (ll)i * a;
    if (t >= 0 && t % b == 0 && t / b <= n) {
      ll tt = comb(n, (ll)i) * comb(n, t / b) % MOD;
      ans = (ans + tt) % MOD;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
// #include <bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repp(i, m, n) for (int i = m; i < (int)n; i++)
#define reps(i, n) for (int i = 1; i <= (int)n; i++)
#define pb push_back
const int INF = 100000000;
const double EPS = 1e-10;
const long long MOD = 998244353;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;

ll kaijo[300010], inv[300010];

ll beki(ll a, ll b) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0) {
    ll tmp = beki(a, b / 2);
    return (tmp * tmp) % MOD;
  } else
    return (beki(a, b - 1) * a) % MOD;
}

ll inv_(ll a) { return beki(a, MOD - 2); }

ll comb(ll a, ll b) { return (kaijo[a] * inv[b]) % MOD * inv[a - b] % MOD; }

int main() {
  ll n, a, b, k;
  cin >> n >> a >> b >> k;

  kaijo[0] = 1;
  inv[0] = 1;
  reps(i, n) {
    kaijo[i] = ((ll)kaijo[i - 1] * (ll)i) % MOD;
    inv[i] = inv_(kaijo[i]);
  }

  ll ans = 0;

  rep(i, n + 1) {
    ll t = k - (ll)i * a;
    if (t >= 0 && t % b == 0 && t / b <= n) {
      ll tt = comb(n, (ll)i) * comb(n, t / b) % MOD;
      ans = (ans + tt) % MOD;
    }
  }
  cout << ans << endl;
  return 0;
}