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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e5 + 6;
const int M = 998244353;
const int inf = 1e9;
ll iv[N], f1[N], f2[N];
ll nck(int n, int k) { return f1[n] * f2[k] % M * f2[n - k] % M; }
void solve() {
  iv[1] = 1;
  for (int i = 2; i < N; ++i)
    iv[i] = M - M / i * iv[M % i] % M;
  f1[0] = f2[0] = 1;
  for (int i = 1; i < N; ++i) {
    f1[i] = f1[i - 1] * i % M;
    f2[i] = f2[i - 1] * iv[i] % M;
  }
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    ll kk = k - i * a;
    if (kk < 0)
      continue;
    if (kk % b)
      continue;
    int j = kk / b;
    ans += nck(n, i) * nck(n, j);
    ans %= M;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  //    cin>>t;
  while (t--)
    solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e5 + 6;
const int M = 998244353;
const int inf = 1e9;
ll iv[N], f1[N], f2[N];
ll nck(int n, int k) { return f1[n] * f2[k] % M * f2[n - k] % M; }
void solve() {
  iv[1] = 1;
  for (int i = 2; i < N; ++i)
    iv[i] = M - M / i * iv[M % i] % M;
  f1[0] = f2[0] = 1;
  for (int i = 1; i < N; ++i) {
    f1[i] = f1[i - 1] * i % M;
    f2[i] = f2[i - 1] * iv[i] % M;
  }
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    ll kk = k - i * a;
    if (kk < 0)
      continue;
    if (kk % b)
      continue;
    int j = kk / b;
    if (j > n)
      continue;
    ans += nck(n, i) * nck(n, j);
    ans %= M;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  //    cin>>t;
  while (t--)
    solve();
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#define LL long long
#define MAXN 300005
#define p 998244353
using namespace std;

LL n, a, b, k, ans, fac[MAXN], inv[MAXN];

LL ksm(LL x, LL y) {
  LL sum = 1;
  while (y) {
    if (y & 1)
      sum = (x * sum) % p;
    x = (x * x) % p;
    y >>= 1;
  }
  return sum;
}

void init() {
  fac[0] = fac[1] = 1;
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= n; i++)
    inv[i] = (p - p / i) * inv[p % i] % p;
  for (int i = 2; i <= n; i++)
    fac[i] = fac[i - 1] * i % p;
  for (int i = 2; i <= n; i++)
    inv[i] = inv[i - 1] * inv[i] % p;
}

LL com(int n, int m) { return fac[n] * inv[n - m] % p * inv[m] % p; }

int main() {
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  if (k == 0) {
    printf("1\n");
    return 0;
  }
  init();
  for (int i = 1; a * i <= k && i <= n; i++) {
    if ((k - a * i) % b != 0)
      continue;
    int j = (k - a * i) / b;
    ans = (com(n, i) * com(n, j) % p + ans) % p;
  }
  printf("%lld\n", ans);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#define LL long long
#define MAXN 300005
#define p 998244353
using namespace std;

LL n, a, b, k, ans, fac[MAXN], inv[MAXN];

LL ksm(LL x, LL y) {
  LL sum = 1;
  while (y) {
    if (y & 1)
      sum = (x * sum) % p;
    x = (x * x) % p;
    y >>= 1;
  }
  return sum;
}

void init() {
  fac[0] = fac[1] = 1;
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= n; i++)
    inv[i] = (p - p / i) * inv[p % i] % p;
  for (int i = 2; i <= n; i++)
    fac[i] = fac[i - 1] * i % p;
  for (int i = 2; i <= n; i++)
    inv[i] = inv[i - 1] * inv[i] % p;
}

LL com(int n, int m) {
  if (m > n)
    return 0;
  return fac[n] * inv[n - m] % p * inv[m] % p;
}

int main() {
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  if (k == 0) {
    printf("1\n");
    return 0;
  }
  init();
  for (int i = 1; a * i <= k && i <= n; i++) {
    if ((k - a * i) % b != 0)
      continue;
    int j = (k - a * i) / b;
    ans = (com(n, i) * com(n, j) % p + ans) % p;
  }
  printf("%lld\n", ans);
}
Problem p03332 (C++)

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

const int MAX_N = 100005;
const int mod = 998244353;

int N, A, B, K;

int NN[MAX_N];

int hou(int k) {
  int ret = 1;
  int tmp = k;

  int kk = mod - 2;

  while (kk > 0) {
    if (kk & 1) {
      ret *= tmp;
      ret %= mod;
    }
    kk >>= 1;
    tmp *= tmp;
    tmp %= mod;
  }

  return ret;
}

int myTimes(int a, int b) { return (a * b) % mod; }

signed main() {
  cin >> N >> A >> B >> K;

  NN[0] = NN[1] = 1;
  for (int i = 1; i < MAX_N - 1; i++) {
    NN[i + 1] = (NN[i] * (i + 1)) % mod;
  }

  int ans = 0;
  for (int i = 0; i <= N; i++) {
    int j = (K - A * i) / B;
    if (0 <= j && j <= N && i * A + B * j == K) {
      ans += myTimes(myTimes(NN[N], myTimes(hou(NN[j]), hou(NN[N - j]))),
                     myTimes(NN[N], myTimes(hou(NN[i]), hou(NN[N - i]))));
      ans %= mod;
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

const int MAX_N = 300005;
const int mod = 998244353;

int N, A, B, K;

int NN[MAX_N];

int hou(int k) {
  int ret = 1;
  int tmp = k;

  int kk = mod - 2;

  while (kk > 0) {
    if (kk & 1) {
      ret *= tmp;
      ret %= mod;
    }
    kk >>= 1;
    tmp *= tmp;
    tmp %= mod;
  }

  return ret;
}

int myTimes(int a, int b) { return (a * b) % mod; }

signed main() {
  cin >> N >> A >> B >> K;

  NN[0] = NN[1] = 1;
  for (int i = 1; i < MAX_N - 1; i++) {
    NN[i + 1] = (NN[i] * (i + 1)) % mod;
  }

  int ans = 0;
  for (int i = 0; i <= N; i++) {
    int j = (K - A * i) / B;
    if (0 <= j && j <= N && i * A + B * j == K) {
      ans += myTimes(myTimes(NN[N], myTimes(hou(NN[j]), hou(NN[N - j]))),
                     myTimes(NN[N], myTimes(hou(NN[i]), hou(NN[N - i]))));
      ans %= mod;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

/**
 *
 *
 * 考虑把绿色视为红色加蓝色
 * 那么题目就转化成了给每一层涂两种颜色，可以全涂红色（贡献为 A）、蓝色（贡献为
 * B）、涂红色和蓝色（贡献为 C = A + B）、不涂颜色（贡献为 0） 设 a
 * 层涂了红色，b 层涂了蓝色，则答案为 sum{ C(a, N) * C(b, N) | (0 <= a, b <= N,
 * A * a + B * b = K) }
 *
 */

const int MAXN = 4 * 1e5 + 10;
const int HA = 998244353;

long long int fac[MAXN], inv[MAXN], N, A, B, K;

long long int fastPow(long long int a, long long int b) {
  if (b == 0)
    return 1;
  if (b == 1)
    return a % HA;
  long long int ret = 1;
  while (b) {
    if (b & 1)
      ret = (ret * a) % HA;
    a = a * a % HA;
    b >>= 1;
  }
  return ret;
}

long long int C(long long int m, long long int n) {
  return fac[n] * inv[m] % HA * inv[n - m] % HA;
}

int main() {
  std::ios::sync_with_stdio(false);
  cin >> N >> A >> B >> K;
  fac[0] = 1;
  inv[0] = 1;
  for (long long int i = 1; i <= N; ++i) {
    fac[i] = fac[i - 1] * i % HA;
    inv[i] = fastPow(fac[i], HA - 2);
  }
  long long int ans = 0;
  for (long long int a = 0; a <= N; ++a) {
    // A * a + B * b = K
    // cout << "((K - A * a) % B + B) % B = " << ((K - A * a) % B + B) % B <<
    // endl;
    if (((K - A * a) % B + B) % B != 0)
      continue;
    long long int b = (K - A * a) / B;
    (ans += (C(a, N) * C(b, N)) % HA) %= HA;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

/**
 *
 *
 * 考虑把绿色视为红色加蓝色
 * 那么题目就转化成了给每一层涂两种颜色，可以全涂红色（贡献为 A）、蓝色（贡献为
 * B）、涂红色和蓝色（贡献为 C = A + B）、不涂颜色（贡献为 0） 设 a
 * 层涂了红色，b 层涂了蓝色，则答案为 sum{ C(a, N) * C(b, N) | (0 <= a, b <= N,
 * A * a + B * b = K) }
 *
 */

const int MAXN = 3 * 1e6 + 10;
const int HA = 998244353;

long long int fac[MAXN], inv[MAXN], N, A, B, K;

long long int fastPow(long long int a, long long int b) {
  if (b == 0)
    return 1;
  if (b == 1)
    return a % HA;
  long long int ret = 1;
  while (b) {
    if (b & 1)
      ret = (ret * a) % HA;
    a = a * a % HA;
    b >>= 1;
  }
  return ret;
}

long long int C(long long int m, long long int n) {
  return fac[n] * inv[m] % HA * inv[n - m] % HA;
}

int main() {
  std::ios::sync_with_stdio(false);
  cin >> N >> A >> B >> K;
  fac[0] = 1;
  inv[0] = 1;
  for (long long int i = 1; i <= N; ++i) {
    fac[i] = fac[i - 1] * i % HA;
    inv[i] = fastPow(fac[i], HA - 2);
  }
  long long int ans = 0;
  for (long long int a = 0; a <= N; ++a) {
    // A * a + B * b = K
    // cout << "((K - A * a) % B + B) % B = " << ((K - A * a) % B + B) % B <<
    // endl;
    if (((K - A * a) % B + B) % B != 0)
      continue;
    long long int b = (K - A * a) / B;
    (ans += (C(a, N) * C(b, N)) % HA) %= HA;
  }
  cout << ans << endl;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define fi first
#define se second
#define mp make_pair
#define int int64_t

using namespace std;

const int N = int(3e5) + 7;
const int mod = 998244353;

int fac[N], rev[N], n, a, b, k, res, cur, t;

int Pow(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = res * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return res;
}
int nCk(int n, int k) { return fac[n] * rev[k] % mod * rev[n - k] % mod; }

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
#define Task "test"
  if (fopen(Task ".inp", "r")) {
    freopen(Task ".inp", "r", stdin);
    freopen(Task ".out", "w", stdout);
  }
  cin >> n >> a >> b >> k;
  fac[0] = rev[0] = 1;
  for (int i = 1; i <= n; ++i)
    fac[i] = fac[i - 1] * i % mod;
  rev[n] = Pow(fac[n], mod - 2);
  for (int i = n - 1; i > 0; --i)
    rev[i] = rev[i + 1] * (i + 1) % mod;
  for (int i = 0; i <= n; ++i) {
    if (a * i > k)
      break;
    cur = k - a * i;
    if (cur % b != 0)
      continue;
    res += nCk(n, i) * nCk(n, cur / b) % mod;
  }
  cout << res % mod;
}


Fixed submission:
#include <bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define fi first
#define se second
#define mp make_pair
#define int int64_t

using namespace std;

const int N = int(3e5) + 7;
const int mod = 998244353;

int fac[N], rev[N], n, a, b, k, res, cur, t;

int Pow(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = res * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return res;
}
int nCk(int n, int k) { return fac[n] * rev[k] % mod * rev[n - k] % mod; }

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
#define Task "test"
  if (fopen(Task ".inp", "r")) {
    freopen(Task ".inp", "r", stdin);
    freopen(Task ".out", "w", stdout);
  }
  cin >> n >> a >> b >> k;
  fac[0] = rev[0] = 1;
  for (int i = 1; i <= n; ++i)
    fac[i] = fac[i - 1] * i % mod;
  rev[n] = Pow(fac[n], mod - 2);
  for (int i = n - 1; i > 0; --i)
    rev[i] = rev[i + 1] * (i + 1) % mod;
  for (int i = 0; i <= n; ++i) {
    if (a * i > k)
      break;
    cur = k - a * i;
    if (cur % b != 0 || cur / b > n)
      continue;
    res += nCk(n, i) * nCk(n, cur / b) % mod;
  }
  cout << res % mod;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL N = 3e5 + 10;
const LL p = 998244353;
LL n, a, b, k;
LL fac[N], inv[N];
inline LL pw(LL x, LL y) {
  LL ans = 1;
  while (y) {
    if (y & 1)
      (ans *= x) %= p;
    x = x * x % p;
    y >>= 1;
  }
  return ans;
}
inline LL C(LL n, LL m) {
  return m > n ? 0 : fac[n] * inv[m] % p * inv[n - m] % p;
}
int main() {
  fac[0] = inv[0] = 1;
  for (int i = 1; i < N; ++i)
    fac[i] = fac[i - 1] * i % p, inv[i] = pw(fac[i], p - 2);
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  LL ans = 0;
  for (LL i = 0; i <= n; ++i) {
    LL j = (k - a * i) / b;
    if (a * i + b * j == k)
      ans = (ans + C(n, i) * C(n, j) % p) % p;
  }
  printf("%lld", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL N = 3e5 + 10;
const LL p = 998244353;
LL n, a, b, k;
LL fac[N], inv[N];
inline LL pw(LL x, LL y) {
  LL ans = 1;
  while (y) {
    if (y & 1)
      (ans *= x) %= p;
    x = x * x % p;
    y >>= 1;
  }
  return ans;
}
inline LL C(LL n, LL m) {
  return m > n ? 0 : fac[n] * inv[m] % p * inv[n - m] % p;
}
int main() {
  fac[0] = inv[0] = 1;
  for (int i = 1; i < N; ++i)
    fac[i] = fac[i - 1] * i % p, inv[i] = pw(fac[i], p - 2);
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  LL ans = 0;
  for (LL i = 0; i <= n; ++i) {
    LL j = (k - a * i) / b;
    if (a * i + b * j == k && j >= 0)
      ans = (ans + C(n, i) * C(n, j) % p) % p;
  }
  printf("%lld", ans);
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

const int MOD = 998244353;

long long f[300005];

int poww(int base, int to) {
  long long cur = base, res = 1;
  while (to) {
    if (to & 1)
      res *= cur, res %= MOD;
    cur *= cur, cur %= MOD;
    to >>= 1;
  }
  return (int)res;
}

long long choose(int a, int b) {
  long long res = (f[a] * poww(f[b], MOD - 2)) % MOD;
  res = (res * poww(f[a - b], MOD - 2)) % MOD;
  return res;
}

int main() {
  int N;
  long long A, B, K;
  scanf("%d%lld%lld%lld", &N, &A, &B, &K);
  f[0] = 1;
  for (int i = 1; i <= N; i++)
    f[i] = (f[i - 1] * i) % MOD;
  long long res = 0;
  for (int A_cnt = 0; A_cnt <= N; A_cnt++) {
    long long cur = A_cnt * A;
    if (cur > K)
      break;
    cur = K - cur;
    if (cur % B == 0) {
      res += (choose(N, A_cnt) * choose(N, cur / B)) % MOD;
      res %= MOD;
    }
  }
  printf("%lld", res);
  return 0;
}


Fixed submission:
#include <stdio.h>

const int MOD = 998244353;

long long f[300005];

int poww(int base, int to) {
  long long cur = base, res = 1;
  while (to) {
    if (to & 1)
      res *= cur, res %= MOD;
    cur *= cur, cur %= MOD;
    to >>= 1;
  }
  return (int)res;
}

long long choose(int a, int b) {
  long long res = (f[a] * poww(f[b], MOD - 2)) % MOD;
  res = (res * poww(f[a - b], MOD - 2)) % MOD;
  return res;
}

int main() {
  int N;
  long long A, B, K;
  scanf("%d%lld%lld%lld", &N, &A, &B, &K);
  f[0] = 1;
  for (int i = 1; i <= N; i++)
    f[i] = (f[i - 1] * i) % MOD;
  long long res = 0;
  for (int A_cnt = 0; A_cnt <= N; A_cnt++) {
    long long cur = A_cnt * A;
    if (cur > K)
      break;
    cur = K - cur;
    if (cur % B == 0 && cur / B <= N) {
      res += (choose(N, A_cnt) * choose(N, cur / B)) % MOD;
      res %= MOD;
    }
  }
  printf("%lld", res);
  return 0;
}
Problem p03332 (C++)

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

constexpr Int mod = 998244353;
vector<Int> fact, ifact, comb;
Int inv(Int n) {
  Int p = mod - 2;
  Int t = n;
  Int res = 1;
  for (; p > 0; p >>= 1) {
    if (p & 1)
      res = res * t % mod;
    t = t * t % mod;
  }
  return res;
}

int main() {
  Int n, a, b, k;
  cin >> n >> a >> b >> k;
  fact.resize(n + 1);
  fact[0] = 1;
  for (Int i = 1; i <= n; ++i)
    fact[i] = i * fact[i - 1] % mod;
  ifact.resize(n + 1);
  for (Int i = 1; i <= n; ++i)
    ifact[i] = inv(fact[i]);
  //    for(Int i=1; i<=n; ++i) cout << i << " " << ifact[i] << "\n";
  comb.resize(n + 1);
  comb[0] = 1;
  for (Int i = 1; i <= n - 1; ++i)
    comb[i] = fact[n] * ifact[i] % mod * ifact[n - i] % mod;
  //    for(Int i=1; i<=n-1; ++i) cout << i << " " << comb[i] << "\n";
  comb[n] = 1;
  Int ans = 0;
  for (Int i = 0; i <= n; ++i) {
    if (k - i * a >= 0 && (k - i * a) % b == 0) {
      Int j = (k - i * a) / b;
      ans = (ans + comb[i] * comb[j] % mod) % mod;
      //            cout << i << " " << j << " " << ans << "\n";
    }
  }
  cout << ans << "\n";
  //    cout << inv(1) << " " << inv(2) << " " << inv(998244352) << "\n";
}

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

constexpr Int mod = 998244353;
vector<Int> fact, ifact, comb;
Int inv(Int n) {
  Int p = mod - 2;
  Int t = n;
  Int res = 1;
  for (; p > 0; p >>= 1) {
    if (p & 1)
      res = res * t % mod;
    t = t * t % mod;
  }
  return res;
}

int main() {
  Int n, a, b, k;
  cin >> n >> a >> b >> k;
  fact.resize(n + 1);
  fact[0] = 1;
  for (Int i = 1; i <= n; ++i)
    fact[i] = i * fact[i - 1] % mod;
  ifact.resize(n + 1);
  for (Int i = 1; i <= n; ++i)
    ifact[i] = inv(fact[i]);
  //    for(Int i=1; i<=n; ++i) cout << i << " " << ifact[i] << "\n";
  comb.resize(n + 1);
  comb[0] = 1;
  for (Int i = 1; i <= n - 1; ++i)
    comb[i] = fact[n] * ifact[i] % mod * ifact[n - i] % mod;
  //    for(Int i=1; i<=n-1; ++i) cout << i << " " << comb[i] << "\n";
  comb[n] = 1;
  Int ans = 0;
  for (Int i = 0; i <= n; ++i) {
    if (k - i * a >= 0 && (k - i * a) % b == 0) {
      Int j = (k - i * a) / b;
      if (j > n)
        continue;
      ans = (ans + comb[i] * comb[j] % mod) % mod;
      //            cout << i << " " << j << " " << ans << "\n";
    }
  }
  cout << ans << "\n";
  //    cout << inv(1) << " " << inv(2) << " " << inv(998244352) << "\n";
}
Problem p03332 (C++)

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for (int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for (int i = int(ini); i >= int(lim); i--)

using namespace std;

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

const int MAX = 3e5 + 5;
const int MOD = 998244353;
int fat[MAX];

inline int add(int a, int b) {
  a += b;
  if (a >= MOD) {
    a -= MOD;
  }
  return a;
}

inline int mult(int a, int b) { return (1LL * a * b) % MOD; }

int f_exp(int x, int exp) {
  if (exp == 0) {
    return 1;
  } else if (exp & 1) {
    return mult(x, f_exp(x, exp - 1));
  }
  return f_exp(mult(x, x), exp / 2);
}

inline int inv(int x) { return f_exp(x, MOD - 2); }

inline int comb(int n, int k) {
  return mult(fat[n], mult(inv(fat[k]), inv(fat[n - k])));
}

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

  fat[0] = 1;
  fori(i, 1, MAX) { fat[i] = mult(fat[i - 1], i); }

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

  int ans = 0;

  for (ll A = 0; A <= n; A++) {
    ll cur_k = k - A * a;

    if (cur_k % b == 0) {
      ll B = cur_k / b;

      if (A > n || B > n) {
        continue;
      }

      ans = add(ans, mult(comb(n, A), comb(n, B)));
    }
  }

  cout << ans << '\n';

  return 0;
}


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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for (int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for (int i = int(ini); i >= int(lim); i--)

using namespace std;

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

const int MAX = 3e5 + 5;
const int MOD = 998244353;
int fat[MAX];

inline int add(int a, int b) {
  a += b;
  if (a >= MOD) {
    a -= MOD;
  }
  return a;
}

inline int mult(int a, int b) { return (1LL * a * b) % MOD; }

int f_exp(int x, int exp) {
  if (exp == 0) {
    return 1;
  } else if (exp & 1) {
    return mult(x, f_exp(x, exp - 1));
  }
  return f_exp(mult(x, x), exp / 2);
}

inline int inv(int x) { return f_exp(x, MOD - 2); }

inline int comb(int n, int k) {
  return mult(fat[n], mult(inv(fat[k]), inv(fat[n - k])));
}

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

  fat[0] = 1;
  fori(i, 1, MAX) { fat[i] = mult(fat[i - 1], i); }

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

  int ans = 0;

  for (ll A = 0; A <= n; A++) {
    ll cur_k = k - A * a;

    if (cur_k >= 0 && cur_k % b == 0) {
      ll B = cur_k / b;

      if (A > n || B > n) {
        continue;
      }

      ans = add(ans, mult(comb(n, A), comb(n, B)));
    }
  }

  cout << ans << '\n';

  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define dbg(x) cout << #x << ":" << x << endl
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
const ll MOD = 998244353;
const ll N = 555555;

// a^(p-2)=a^(-1) (mod p)
//(x^n)%mod
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0)
    return 1;
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if (n & 1)
    res = res * x % mod;
  return res;
}

ll fact[N];
ll infact[N];

void make_factorial(void) {
  fact[0] = 1;
  for (ll i = 1; i < N; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
  }
  for (ll i = 0; i < N; i++) {
    infact[i] = mod_pow(fact[i], MOD - 2, MOD);
  }
}

ll comb(ll a, ll b) {
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = infact[a - b] * infact[b] % MOD;
  return tmp * fact[a] % MOD;
}

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

  if (k == 0) {
    cout << 1 << endl;
    return 0;
  }

  make_factorial();

  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    if ((k - i * a) % b)
      continue;
    ll x = i;
    ll y = (k - i * a) / b;

    ans += (comb(n, x) * comb(n, y)) % MOD;
    ans %= MOD;
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define dbg(x) cout << #x << ":" << x << endl
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
const ll MOD = 998244353;
const ll N = 555555;

// a^(p-2)=a^(-1) (mod p)
//(x^n)%mod
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0)
    return 1;
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if (n & 1)
    res = res * x % mod;
  return res;
}

ll fact[N];
ll infact[N];

void make_factorial(void) {
  fact[0] = 1;
  for (ll i = 1; i < N; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
  }
  for (ll i = 0; i < N; i++) {
    infact[i] = mod_pow(fact[i], MOD - 2, MOD);
  }
}

ll comb(ll a, ll b) {
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = infact[a - b] * infact[b] % MOD;
  return tmp * fact[a] % MOD;
}

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

  if (k == 0) {
    cout << 1 << endl;
    return 0;
  }

  make_factorial();

  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    if (k < a * i)
      continue;
    if ((k - i * a) % b)
      continue;
    ll x = i;
    ll y = (k - i * a) / b;

    ans += (comb(n, x) * comb(n, y)) % MOD;
    ans %= MOD;
  }

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

Buggy submission (status: Runtime Error):
#include <functional>
#include <iostream>
using namespace std;

const long long MOD = 998244353;

int main() {
  long long n, a, b, k, result = 0;
  cin >> n >> a >> b >> k;
  long long factorial[n + 1], inv[n + 1], ifactorial[n + 1];
  factorial[0] = 1;
  ifactorial[0] = 1;
  factorial[1] = 1;
  ifactorial[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i <= n; i++) {
    factorial[i] = factorial[i - 1] * i % MOD;
    inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
    ifactorial[i] = inv[i] * ifactorial[i - 1] % MOD;
  }
  function<long long(long long, long long)> C = [&](long long n, long long k) {
    return factorial[n] * ifactorial[k] % MOD * ifactorial[n - k] % MOD;
  };
  for (long long i = 0; i <= n; i++) {
    if ((k - i * a) % b == 0) {
      long long j = (k - i * a) / b;
      if (j <= n) {
        result = (result + C(n, i) * C(n, j)) % MOD;
      }
    }
  }
  cout << result;
  return 0;
}


Fixed submission:
#include <functional>
#include <iostream>
using namespace std;

const long long MOD = 998244353;

int main() {
  long long n, a, b, k, result = 0;
  cin >> n >> a >> b >> k;
  long long factorial[n + 1], inv[n + 1], ifactorial[n + 1];
  factorial[0] = 1;
  ifactorial[0] = 1;
  factorial[1] = 1;
  ifactorial[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i <= n; i++) {
    factorial[i] = factorial[i - 1] * i % MOD;
    inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
    ifactorial[i] = inv[i] * ifactorial[i - 1] % MOD;
  }
  function<long long(long long, long long)> C = [&](long long n, long long k) {
    return factorial[n] * ifactorial[k] % MOD * ifactorial[n - k] % MOD;
  };
  for (long long i = 0; i <= n && i * a <= k; i++) {
    if ((k - i * a) % b == 0) {
      long long j = (k - i * a) / b;
      if (j <= n) {
        result = (result + C(n, i) * C(n, j)) % MOD;
      }
    }
  }
  cout << result;
  return 0;
}
Problem p03332 (C++)

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

using namespace std;

#define MAXN 300001
#define MOD 998244353
typedef long long ll;

inline int mul(int a, int b) { return (int)((ll)a * b % MOD); }

inline int power(int a, ll b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

int inv(int a) { return power(a % MOD, MOD - 2); }

vector<ll> fact(MAXN + 1, 1);
void precalc() {
  for (int i = 2; i <= MAXN; ++i) {
    fact[i] = (fact[i - 1] * i) % MOD;
  }
}

ll nCk(int n, int k) {
  return (fact[n] * (((ll)inv(fact[k]) * inv(fact[n - k])) % MOD)) % MOD;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  precalc();
  ll n, a, b, k, ans = 0;
  cin >> n >> a >> b >> k;
  for (int x = 0; x <= n; ++x) {
    if (k - x * a < 0 || (k - x * a) % b)
      continue;
    int y = (k - x * a) / b;
    ans += nCk(n, x) * nCk(n, y);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define MAXN 300001
#define MOD 998244353
typedef long long ll;

inline int mul(int a, int b) { return (int)((ll)a * b % MOD); }

inline int power(int a, ll b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

int inv(int a) { return power(a % MOD, MOD - 2); }

vector<ll> fact(MAXN + 1, 1);
void precalc() {
  for (int i = 2; i <= MAXN; ++i) {
    fact[i] = (fact[i - 1] * i) % MOD;
  }
}

ll nCk(int n, int k) {
  return (fact[n] * (((ll)inv(fact[k]) * inv(fact[n - k])) % MOD)) % MOD;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  precalc();
  ll n, a, b, k, ans = 0;
  cin >> n >> a >> b >> k;
  for (int x = 0; x <= n; ++x) {
    if (k - x * a < 0 || (k - x * a) % b)
      continue;
    int y = (k - x * a) / b;
    if (y > n)
      continue;
    ans += nCk(n, x) * nCk(n, y);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p03332 (C++)

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

using namespace std;

#define int long long

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

int binpow(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1)
      (res *= a) %= mod, n--;
    else
      (a *= a) %= mod, n >>= 1;
  }
  return res;
}

int inverse(int x) { return binpow(x, mod - 2); }

vector<int> fact(N, 1), inv(N, 1);

void preset() {
  fact[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = (inv[i - 1] * inverse(i)) % mod;
  }
}

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

signed main() {
  int n, a, b, k, ans = 0;
  cin >> n >> a >> b >> k;
  preset();
  for (int x = 0; x <= n; x++) {
    if ((k - x * a) % b == 0) {
      int y = (k - x * a) / b;
      if (y <= n) {
        (ans += nCk(n, x) * nCk(n, y) % mod) %= mod;
      }
    }
  }
  cout << ans;
}

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

using namespace std;

#define int long long

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

int binpow(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1)
      (res *= a) %= mod, n--;
    else
      (a *= a) %= mod, n >>= 1;
  }
  return res;
}

int inverse(int x) { return binpow(x, mod - 2); }

vector<int> fact(N, 1), inv(N, 1);

void preset() {
  fact[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = (inv[i - 1] * inverse(i)) % mod;
  }
}

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

signed main() {
  int n, a, b, k, ans = 0;
  cin >> n >> a >> b >> k;
  preset();
  for (int x = 0; x <= n; x++) {
    if ((k - x * a) % b == 0) {
      int y = (k - x * a) / b;
      if (y <= n && y >= 0) {
        ans += nCk(n, x) * nCk(n, y) % mod;
        ans %= mod;
      }
    }
  }
  cout << ans;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define N 300005
using namespace std;
typedef long long ll;
ll n, a, b, k, ans, M = 998244353;
ll fac[N] = {1, 1}, inv[N] = {1, 1}, fiv[N] = {1, 1};

ll c(ll p) { return fac[n] * fiv[n - p] % M * fiv[p] % M; }

int main() {
  cin >> n >> a >> b >> k;
  ll i;
  for (i = 2; i <= n; i++) {
    fac[i] = fac[i - 1] * i % M;
    inv[i] = inv[M % i] * (M - M / i) % M;
    fiv[i] = fiv[i - 1] * inv[i] % M;
  }
  for (i = 0; i <= n && a * i <= k; i++) {
    if ((k - a * i) % b == 0)
      ans += c(i) * c((k - a * i) / b) % M;
  }
  cout << ans % M;
  return 0;
}

Fixed submission:
#include <iostream>
#define N 300005
using namespace std;
typedef long long ll;
ll n, a, b, k, ans, M = 998244353;
ll fac[N] = {1, 1}, inv[N] = {1, 1}, fiv[N] = {1, 1};

ll c(ll p) {
  if (p > n)
    return 0;
  return fac[n] * fiv[n - p] % M * fiv[p] % M;
}

int main() {
  cin >> n >> a >> b >> k;
  ll i;
  for (i = 2; i <= n; i++) {
    fac[i] = fac[i - 1] * i % M;
    inv[i] = inv[M % i] * (M - M / i) % M;
    fiv[i] = fiv[i - 1] * inv[i] % M;
  }
  for (i = 0; i <= n && a * i <= k; i++) {
    if ((k - a * i) % b == 0)
      ans += c(i) * c((k - a * i) / b) % M;
  }
  cout << ans % M;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define N 300005
using namespace std;
typedef long long ll;
ll n, a, b, k, ans, M = 998244353;
ll fac[N] = {1, 1}, inv[N] = {1, 1}, fiv[N] = {1, 1};
ll c(ll p) { return fac[n] * fiv[n - p] % M * fiv[p] % M; }

int main() {
  cin >> n >> a >> b >> k;
  ll i, t;
  for (i = 2; i <= n; i++) {
    fac[i] = fac[i - 1] * i % M;
    inv[i] = inv[M % i] * (M - M / i) % M;
    fiv[i] = fiv[i - 1] * inv[i] % M;
  }
  for (i = 0; i <= n; i++) {
    t = k - a * i;
    if (t < 0)
      break;
    if (t % b == 0)
      ans += c(i) * c(t / b) % M;
  }
  cout << ans % M;
  return 0;
}

Fixed submission:
#include <iostream>
#define N 300005
using namespace std;
typedef long long ll;
ll n, a, b, k, ans, M = 998244353;
ll fac[N] = {1, 1}, inv[N] = {1, 1}, fiv[N] = {1, 1};
ll c(ll p) { return fac[n] * fiv[n - p] % M * fiv[p] % M; }

int main() {
  cin >> n >> a >> b >> k;
  ll i, t;
  for (i = 2; i <= n; i++) {
    fac[i] = fac[i - 1] * i % M;
    inv[i] = inv[M % i] * (M - M / i) % M;
    fiv[i] = fiv[i - 1] * inv[i] % M;
  }
  for (i = 0; i <= n; i++) {
    t = k - a * i;
    if (t < 0)
      break;
    if (t % b == 0 && t / b <= n)
      ans += c(i) * c(t / b) % M;
  }
  cout << ans % M;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int, int>
#define MA make_pair
#define LLI long long int
#define FOR(i, a, b) for (LLI i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
#define POS(i) cout << (i ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Pos(i) cout << (i ? "Possible" : "Impossible") << endl
#define co(i) cout << i << endl
using namespace std;
//
const int INF = 1e9 + 7;
const int MOD = 998244353;
//
LLI modpow(LLI a, LLI b, LLI m) {
  LLI ret = 1;
  while (b > 0) {
    if (b & 1)
      (ret *= a) %= m;
    (a *= a) %= m;
    b >>= 1;
  }
  return ret;
}

vector<LLI> kaijo[2];
vector<LLI> gyaku[2];
void comb1(int k, LLI n, LLI m) {
  kaijo[k].PB(1);
  FOR(i, 1, n + 1) { kaijo[k].PB((kaijo[k][i - 1] * i) % m); }
  FOR(i, 0, n + 1) { gyaku[k].PB(modpow(kaijo[k][i], m - 2, m)); }
}
LLI comb2(int k, LLI n, LLI r, LLI m) {
  return (((kaijo[k][n] * gyaku[k][n - r]) % m) * gyaku[k][r]) % m;
}

int main(void) {
  LLI n, a, b, k;
  cin >> n >> a >> b >> k;
  LLI ans = 0;
  comb1(0, n, MOD);
  FOR(x, 0, n + 1) {
    LLI y = (k - a * x) / b;
    if (a * x + b * y == k) {
      ans += (comb2(0, n, x, MOD) * comb2(0, n, y, MOD)) % MOD;
    }
  }
  co(ans);
}


Fixed submission:
#include <bits/stdc++.h>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int, int>
#define MA make_pair
#define LLI long long int
#define FOR(i, a, b) for (LLI i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
#define POS(i) cout << (i ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Pos(i) cout << (i ? "Possible" : "Impossible") << endl
#define co(i) cout << i << endl
using namespace std;
//
const int INF = 1e9 + 7;
const int MOD = 998244353;
//
LLI modpow(LLI a, LLI b, LLI m) {
  LLI ret = 1;
  while (b > 0) {
    if (b & 1)
      (ret *= a) %= m;
    (a *= a) %= m;
    b >>= 1;
  }
  return ret;
}

vector<LLI> kaijo[2];
vector<LLI> gyaku[2];
void comb1(int k, LLI n, LLI m) {
  kaijo[k].PB(1);
  FOR(i, 1, n + 1) { kaijo[k].PB((kaijo[k][i - 1] * i) % m); }
  FOR(i, 0, n + 1) { gyaku[k].PB(modpow(kaijo[k][i], m - 2, m)); }
}
LLI comb2(int k, LLI n, LLI r, LLI m) {
  return (((kaijo[k][n] * gyaku[k][n - r]) % m) * gyaku[k][r]) % m;
}

int main(void) {
  LLI n, a, b, k;
  cin >> n >> a >> b >> k;
  LLI ans = 0;
  comb1(0, n, MOD);
  FOR(x, 0, n + 1) {
    LLI y = (k - a * x) / b;
    if (0 <= y && y <= n && a * x + b * y == k) {
      ans = (ans + comb2(0, n, x, MOD) * comb2(0, n, y, MOD)) % MOD;
    }
  }
  co(ans);
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#define N_MAX 300010
#define ll long long
#define CONST 998244353

ll C[N_MAX];

ll ext_gcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll q = a / b;
  ll g = ext_gcd(b, a - q * b, x, y);
  ll z = x - q * y;
  x = y;
  y = z;
  return g;
}

ll invmod(ll a, ll m) {
  ll x, y;
  ext_gcd(a, m, x, y);
  x %= m;
  if (x < 0)
    x += m;
  return x % CONST;
}

int main(void) {
  ll N, A, B, K;
  scanf("%lld", &N);
  scanf("%lld", &A);
  scanf("%lld", &B);
  scanf("%lld", &K);

  C[0] = 1;
  for (ll i = 1; i <= N; i++) {
    C[i] = ((C[i - 1] * (N - i + 1)) % CONST * invmod(i, CONST)) % CONST;
    // printf("%lld %lld\n", i, C[i]);
  }

  ll sum = 0;
  for (ll n1 = 0; n1 < N; n1++) {
    if ((K - A * n1) % B != 0) {
      continue;
    }
    ll n2 = (K - A * n1) / B;
    if (n2 > N) {
      continue;
    }
    sum += C[n1] * C[n2];
    sum = sum % CONST;
  }

  printf("%lld\n", sum);
}


Fixed submission:
#include <stdio.h>
#define N_MAX 300010
#define ll long long
#define CONST 998244353

ll C[N_MAX];

ll ext_gcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll q = a / b;
  ll g = ext_gcd(b, a - q * b, x, y);
  ll z = x - q * y;
  x = y;
  y = z;
  return g;
}

ll invmod(ll a, ll m) {
  ll x, y;
  ext_gcd(a, m, x, y);
  x %= m;
  if (x < 0)
    x += m;
  return x % CONST;
}

int main(void) {
  ll N, A, B, K;
  scanf("%lld", &N);
  scanf("%lld", &A);
  scanf("%lld", &B);
  scanf("%lld", &K);

  C[0] = 1;
  for (ll i = 1; i <= N; i++) {
    C[i] = ((C[i - 1] * (N - i + 1)) % CONST * invmod(i, CONST)) % CONST;
    // printf("%lld %lld\n", i, C[i]);
  }

  ll sum = 0;
  for (ll n1 = 0; n1 <= N; n1++) {
    if ((K - A * n1) < 0) {
      break;
    }
    if ((K - A * n1) % B != 0) {
      continue;
    }
    ll n2 = (K - A * n1) / B;
    if (n2 > N) {
      continue;
    }
    sum += C[n1] * C[n2];
    sum = sum % CONST;
  }

  printf("%lld\n", sum);
}
Problem p03332 (C++)

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

const int N = 3e5 + 5, MOD = 998244353;

using i64 = long long;

i64 fact[N], inv[N];

i64 ant, k, a, b;
int n;

static i64 expow(i64 b, i64 e) {
  i64 ant = 1;
  for (; e > 0; e /= 2) {
    if (e % 2)
      ant = ant * b % MOD;
    b = b * b % MOD;
  }
  return ant;
}

static i64 comb(int n, int k) {
  return fact[n] * inv[k] % MOD * inv[n - k] % MOD;
}

int main() {
#ifdef HOME
  freopen("agc25b.in", "r", stdin);
  freopen("agc25b.out", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);

  fact[0] = 1;
  for (int i = 1; i < N; ++i)
    fact[i] = fact[i - 1] * i % MOD;
  inv[N - 1] = expow(fact[N - 1], MOD - 2);
  for (int i = N - 2; i >= 0; --i)
    inv[i] = inv[i + 1] * (i + 1) % MOD;

  cin >> n >> a >> b >> k;

  for (int i = 0; i <= n && i * a <= k; ++i)
    if ((k - i * a) % b == 0)
      ant = (ant + comb(n, i) * comb(n, (k - i * a) / b)) % MOD;

  cout << ant << endl;

  return 0;
}


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

const int N = 3e5 + 5, MOD = 998244353;

using i64 = long long;

i64 fact[N], inv[N];

i64 ant, k, a, b;
int n;

static i64 expow(i64 b, i64 e) {
  i64 ant = 1;
  for (; e > 0; e /= 2) {
    if (e % 2)
      ant = ant * b % MOD;
    b = b * b % MOD;
  }
  return ant;
}

static i64 comb(int n, int k) {
  return fact[n] * inv[k] % MOD * inv[n - k] % MOD;
}

int main() {
#ifdef HOME
  freopen("agc25b.in", "r", stdin);
  freopen("agc25b.out", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);

  fact[0] = 1;
  for (int i = 1; i < N; ++i)
    fact[i] = fact[i - 1] * i % MOD;
  inv[N - 1] = expow(fact[N - 1], MOD - 2);
  for (int i = N - 2; i >= 0; --i)
    inv[i] = inv[i + 1] * (i + 1) % MOD;

  cin >> n >> a >> b >> k;

  for (int i = 0; i <= n && i * a <= k; ++i)
    if ((k - i * a) % b == 0 && (k - i * a) / b <= n)
      ant = (ant + comb(n, i) * comb(n, (k - i * a) / b)) % MOD;

  cout << ant << endl;

  return 0;
}
Problem p03332 (C++)

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

typedef long long ll;

using namespace std;

const ll mod = 998244353;
ll n;
ll a, b;
ll k, g, f, x, y, bruh;
ll fakt[300001];
ll mul(ll x, ll y) {
  x *= y;
  return x % mod;
}

ll pot(ll z, ll u) {
  if (u == 0)
    return 1;
  if (u == 1)
    return z;
  if (u % 2 == 0) {
    ll x = pot(z, u / 2);
    return mul(x, x);
  }
  return mul(pot(z, u - 1), z);
}

ll dvd(ll z, ll u) {
  u = pot(u, mod - 2);
  z *= u;
  return z % mod;
}

ll pov(ll z) { return dvd(fakt[n], mul(fakt[z], fakt[n - z])) % mod; }

int main() {
  cin >> n >> a >> b >> k;
  fakt[0] = 1;
  for (int i = 1; i < 300001; i++) {
    fakt[i] = mul(fakt[i - 1], i);
  }
  for (int i = 0; i <= n; i++) {
    if ((k - (a * i)) % b == 0 && (k - (a * i)) / b <= n) {
      bruh = (k - (a * i)) / b;
      g += mul(pov(i), pov(bruh));
    }
  }
  cout << g % mod;
}


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

typedef long long ll;

using namespace std;

const ll mod = 998244353;
ll n;
ll a, b;
ll k, g, f, x, y, bruh;
ll fakt[300001];
ll mul(ll x, ll y) {
  x *= y;
  return x % mod;
}

ll pot(ll z, ll u) {
  if (u == 0)
    return 1;
  if (u == 1)
    return z;
  if (u % 2 == 0) {
    ll x = pot(z, u / 2);
    return mul(x, x);
  }
  return mul(pot(z, u - 1), z);
}

ll dvd(ll z, ll u) {
  u = pot(u, mod - 2);
  z *= u;
  return z % mod;
}

ll pov(ll z) { return dvd(fakt[n], mul(fakt[z], fakt[n - z])) % mod; }

int main() {
  cin >> n >> a >> b >> k;
  fakt[0] = 1;
  for (int i = 1; i < 300001; i++) {
    fakt[i] = mul(fakt[i - 1], i);
  }
  for (int i = 0; i <= n; i++) {
    if ((k - (a * i)) % b == 0 && (k - (a * i)) / b <= n) {
      bruh = (k - (a * i)) / b;
      if (bruh >= 0) {
        g += mul(pov(i), pov(bruh));
      }
    }
  }
  cout << g % mod;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define mt(a, b, c) make_tuple((a), (b), (c))
#define MOD 998244353
typedef long long ll;
long long modinv(long long a, long long m = MOD) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}
vector<ll> fact(400005);
long long comb(long long n, long long r, long long m = MOD) {
  if (n < r)
    return 0;
  return (((fact[n] * modinv(fact[n - r])) % m) * modinv(fact[r])) % m;
}

int main() {
  fact[0] = 1;
  FOR(i, 1, 400002) fact[i] = (fact[i - 1] * i) % MOD;
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  rep(i, n + 1) {
    if ((k - i * a) % b == 0) {
      ll y = (k - i * a) / b;
      ans += (comb(n, i) * comb(n, y)) % MOD;
      ans %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define mt(a, b, c) make_tuple((a), (b), (c))
#define MOD 998244353
typedef long long ll;
long long modinv(long long a, long long m = MOD) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}
vector<ll> fact(400005);
long long comb(long long n, long long r, long long m = MOD) {
  if (n < r)
    return 0;
  if (r < 0)
    return 0;
  return (((fact[n] * modinv(fact[n - r])) % m) * modinv(fact[r])) % m;
}

int main() {
  fact[0] = 1;
  FOR(i, 1, 400002) fact[i] = (fact[i - 1] * i) % MOD;
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  rep(i, n + 1) {
    if ((k - i * a) % b == 0) {
      ll y = (k - i * a) / b;
      ans += (comb(n, i) * comb(n, y)) % MOD;
      ans %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03332 (C++)

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

typedef long long ll;
const ll mod = 998244353;
const int N = 3e5 + 10;
ll n, a, b, k, ans, fac[N];

ll ksm(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      (res *= a) %= mod;
    (a *= a) %= mod;
    b >>= 1;
  }
  return res;
}

ll C(ll n, ll m) {
  return fac[n] * ksm(fac[m], mod - 2) % mod * ksm(fac[n - m], mod - 2) % mod;
}

int main() {
  fac[0] = fac[1] = 1;
  For(i, 2, N - 5) fac[i] = 1ll * i * fac[i - 1] % mod;
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  if (k == 0)
    return printf("1\n"), 0;
  if (a == 0 && b == 0)
    return printf("0\n"), 0;
  if (a == 0 || b == 0) {
    if (b == 0)
      swap(a, b);
    ll u = k / b;
    if (k % b == 0)
      return printf("%lld\n", C(n, u));
    else
      return printf("0\n"), 0;
  }
  For(i, 0, n) {
    ll u = 1ll * i, res = k - u * a, v = res / b;
    if (res < 0)
      break;
    if (res % b != 0)
      continue;
    (ans += C(n, u) * C(n, v) % mod) %= mod;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define For(i, h, j) for (int i = h; i <= j; ++i)
using namespace std;

typedef long long ll;
const ll mod = 998244353;
const int N = 3e5 + 10;
ll n, a, b, k, ans, fac[N];

ll ksm(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      (res *= a) %= mod;
    (a *= a) %= mod;
    b >>= 1;
  }
  return res;
}

ll C(ll n, ll m) {
  if (n < m)
    return 0;
  return fac[n] * ksm(fac[m], mod - 2) % mod * ksm(fac[n - m], mod - 2) % mod;
}

int main() {
  fac[0] = fac[1] = 1;
  For(i, 2, N - 5) fac[i] = 1ll * i * fac[i - 1] % mod;
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  if (k == 0)
    return printf("1\n"), 0;
  if (a == 0 && b == 0)
    return printf("0\n"), 0;
  if (a == 0 || b == 0) {
    if (b == 0)
      swap(a, b);
    ll u = k / b;
    if (k % b == 0)
      return printf("%lld\n", C(n, u));
    else
      return printf("0\n"), 0;
  }
  For(i, 0, n) {
    ll u = 1ll * i, res = k - u * a, v = res / b;
    if (res < 0)
      break;
    if (res % b != 0)
      continue;
    (ans += C(n, u) * C(n, v) % mod) %= mod;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03332 (C++)

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

const int MAXN = 300005, mod = 998244353;

long long n, A, B, K;

int fac[MAXN], ifac[MAXN], inv[MAXN];

int main() {
  cin >> n >> A >> B >> K;
  fac[0] = 1, ifac[0] = 1, inv[1] = 1;
  for (int i = 2; i <= n; i++)
    inv[i] = (mod - (long long)mod / i * inv[mod % i] % mod) % mod;
  for (int i = 1; i <= n; i++) {
    fac[i] = (long long)fac[i - 1] * i % mod;
    ifac[i] = (long long)ifac[i - 1] * inv[i] % mod;
  }
  auto choose = [](int n, int m) {
    return (long long)fac[n] * ifac[m] % mod * ifac[n - m] % mod;
  };
  int ans = 0;
  for (int i = 0; i <= n && K >= A * i; i++) {
    if ((K - A * i) % B != 0)
      continue;
    int j = (K - A * i) / B;
    ans = (ans + (long long)choose(n, i) * choose(n, j)) % mod;
  }
  cout << ans << endl;
  return 0;
}


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

const int MAXN = 300005, mod = 998244353;

long long n, A, B, K;

int fac[MAXN], ifac[MAXN], inv[MAXN];

int main() {
  cin >> n >> A >> B >> K;
  fac[0] = 1, ifac[0] = 1, inv[1] = 1;
  for (int i = 2; i <= n; i++)
    inv[i] = (mod - (long long)mod / i * inv[mod % i] % mod) % mod;
  for (int i = 1; i <= n; i++) {
    fac[i] = (long long)fac[i - 1] * i % mod;
    ifac[i] = (long long)ifac[i - 1] * inv[i] % mod;
  }
  auto choose = [](int n, int m) {
    return (long long)fac[n] * ifac[m] % mod * ifac[n - m] % mod;
  };
  int ans = 0;
  for (int i = 0; i <= n && K >= A * i; i++) {
    if ((K - A * i) % B != 0)
      continue;
    int j = (K - A * i) / B;
    if (i <= n && j <= n)
      ans = (ans + (long long)choose(n, i) * choose(n, j)) % mod;
  }
  cout << ans << endl;
  return 0;
}