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

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MAX = 100005;
const ll INF = 0x3f3f3f3f;
const ll MOD = 998244353;
ll n, ans, fact[MAX], finv[MAX], a, b, k;
ll power(ll x, ll y) {
  if (y == 0)
    return 1;
  ll t = power(x, y / 2);
  if (y % 2)
    return t * t % MOD * x % MOD;
  return t * t % MOD;
}
ll comb(ll x, ll y) { return fact[x] * finv[x - y] % MOD * finv[y] % MOD; }
int main() {
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  fact[0] = 1;
  for (ll i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * i % MOD;
  for (ll i = 0; i <= n; i++)
    finv[i] = power(fact[i], MOD - 2);
  for (ll i = 0; a * i <= k && i <= n; i++)
    if ((k - a * i) % b == 0 && (k - a * i) / b <= n) {
      ll t1 = i, t2 = (k - a * i) / b;
      ans += comb(n, t1) * comb(n, t2), ans %= MOD;
    }
  printf("%lld\n", ans);
}


Fixed submission:
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MAX = 300005;
const ll INF = 0x3f3f3f3f;
const ll MOD = 998244353;
ll n, ans, fact[MAX], finv[MAX], a, b, k;
ll power(ll x, ll y) {
  if (y == 0)
    return 1;
  ll t = power(x, y / 2);
  if (y % 2)
    return t * t % MOD * x % MOD;
  return t * t % MOD;
}
ll comb(ll x, ll y) { return fact[x] * finv[x - y] % MOD * finv[y] % MOD; }
int main() {
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  fact[0] = 1;
  for (ll i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * i % MOD;
  for (ll i = 0; i <= n; i++)
    finv[i] = power(fact[i], MOD - 2);
  for (ll i = 0; a * i <= k && i <= n; i++)
    if ((k - a * i) % b == 0 && (k - a * i) / b <= n) {
      ll t1 = i, t2 = (k - a * i) / b;
      ans += comb(n, t1) * comb(n, t2), ans %= MOD;
    }
  printf("%lld\n", ans);
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;
const long long mod = 998244353;
const int N = 3e5 + 12;
long long n, k, a, b, g, t1, t2, ans, fac[N], inv[N];
long long qpow(long long x, long long y) {
  long long ret = 1;
  while (y) {
    if (y & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long C(int n, int m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }
int main() {
  if (a > b)
    swap(a, b);
  scanf("%lld %lld %lld %lld", &n, &a, &b, &k);
  g = a / gcd(a, b) * b;
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = 1LL * fac[i - 1] * i % mod;
  inv[n] = qpow(fac[n], mod - 2);
  for (int i = n - 1; ~i; i--)
    inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
  while ((k - t2 * b) % a && t2 <= n)
    t2++;
  t1 = (k - t2 * b) / a;
  if (t2 > n) {
    puts("0");
    return 0;
  }
  while (t1 >= 0 && t2 <= n) {
    (ans += 1LL * C(n, t1) * C(n, t2) % mod) %= mod;
    t2 += (g / b);
    t1 -= (g / a);
  }
  printf("%lld\n", ans);
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
const long long mod = 998244353;
const int N = 3e5 + 12;
long long n, k, a, b, g, t1, t2, ans, fac[N], inv[N];
long long qpow(long long x, long long y) {
  long long ret = 1;
  while (y) {
    if (y & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long C(int n, int m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }
int main() {
  if (a > b)
    swap(a, b);
  scanf("%lld %lld %lld %lld", &n, &a, &b, &k);
  g = a / gcd(a, b) * b;
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = 1LL * fac[i - 1] * i % mod;
  inv[n] = qpow(fac[n], mod - 2);
  for (int i = n - 1; ~i; i--)
    inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
  while ((k - t2 * b) % a && t2 <= n)
    t2++;
  t1 = (k - t2 * b) / a;
  if (t2 > n) {
    puts("0");
    return 0;
  }
  while (t1 >= 0 && t2 <= n) {
    if (t1 <= n)
      (ans += C(n, t1) * C(n, t2) % mod) %= mod;
    t2 += (g / b);
    t1 -= (g / a);
  }
  printf("%lld\n", ans);
}
Problem p03332 (C++)

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

#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define mp make_pair
#define iii pair<int, pair<int, ii>>
#define ll long long
#define FOR(a, b, c) for (int a = b; a <= c; ++a)
const int N = 5 * 1e5 + 10;
const int oo = 1e6;
const ll mod = 998244353;
const double PI = acos(-1);
int n, A, B, k;
ll fac[N], facw[N];
ll powe(ll x, ll y) {
  if (y == 0)
    return 1ll;
  ll mid = powe(x, y / 2);
  if (y % 2)
    return mid * mid % mod * x % mod;
  else
    return mid * mid % mod;
}
ll getC(int k, int n) {
  if (k > n)
    return 0ll;
  ll res = fac[n];
  res = (res * (facw[k] * facw[n - k] % mod) % mod);
  return res;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> A >> B >> k;
  ll sum = 0ll;
  fac[0] = 1;
  for (int i = 1; i <= 3 * 100000; ++i)
    fac[i] = (fac[i - 1] * i) % mod;
  facw[0] = 1;
  for (int i = 1; i <= 3 * 100000; ++i)
    facw[i] = powe(fac[i], mod - 2);
  for (int i = 0; i <= n; ++i)
    if (k >= A * i && (k - A * i) % B == 0) {
      int j = (k - A * i) / B;
      sum += (getC(i, n) * getC(j, n) % mod);
      sum %= mod;
    }
  cout << sum;
}


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

#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define mp make_pair
#define iii pair<int, pair<int, ii>>
#define ll long long
#define FOR(a, b, c) for (int a = b; a <= c; ++a)
const int N = 5 * 1e5 + 10;
const int oo = 1e6;
const ll mod = 998244353;
const double PI = acos(-1);
ll n, A, B, k;
ll fac[N], facw[N];
ll powe(ll x, ll y) {
  if (y == 0)
    return 1ll;
  ll mid = powe(x, y / 2);
  if (y % 2)
    return mid * mid % mod * x % mod;
  else
    return mid * mid % mod;
}
ll getC(int k, int n) {
  if (k > n)
    return 0ll;
  ll res = fac[n];
  res = (res * (facw[k] * facw[n - k] % mod) % mod);
  return res;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> A >> B >> k;
  ll sum = 0ll;
  fac[0] = 1;
  for (int i = 1; i <= 3 * 100000; ++i)
    fac[i] = (fac[i - 1] * i) % mod;
  facw[0] = 1;
  for (int i = 1; i <= 3 * 100000; ++i)
    facw[i] = powe(fac[i], mod - 2);
  for (int i = 0; i <= n; ++i)
    if (k >= A * i && (k - A * i) % B == 0) {
      int j = (k - A * i) / B;
      sum += (getC(i, n) * getC(j, n) % mod);
      sum %= mod;
    }
  cout << sum;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define N 5000005
#define Mod 998244353
using namespace std;
int n, A, B, K, ans, fac[N], inv[N];
inline int ksm(int x, int y) {
  int ans1 = 1;
  while (y) {
    if (y & 1)
      ans1 = 1ll * ans1 * x % Mod;
    y >>= 1;
    x = 1ll * x * x % Mod;
  }
  return ans1;
}
inline int C(int n, int m) {
  return 1ll * fac[n] * inv[m] % Mod * inv[n - m] % Mod;
}
signed main() {
  scanf("%lld%lld%lld%lld", &n, &A, &B, &K);
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % Mod;
  inv[N - 1] = ksm(fac[N - 1], Mod - 2);
  for (int i = N - 2; ~i; i--)
    inv[i] = inv[i + 1] * (i + 1) % Mod;
  for (int i = 0; i <= n; i++) {
    int res = K - i * A;
    if (res < 0)
      break;
    if (res % B == 0) {
      int j = res / B;
      ans = 1ll * (ans + 1ll * C(n, i) * C(n, j) % Mod) % Mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define N 5000005
#define Mod 998244353
using namespace std;
int n, A, B, K, ans, fac[N], inv[N];
inline int ksm(int x, int y) {
  int ans1 = 1;
  while (y) {
    if (y & 1)
      ans1 = 1ll * ans1 * x % Mod;
    y >>= 1;
    x = 1ll * x * x % Mod;
  }
  return ans1;
}
inline int C(int n, int m) {
  return 1ll * fac[n] * inv[m] % Mod * inv[n - m] % Mod;
}
signed main() {
  scanf("%lld%lld%lld%lld", &n, &A, &B, &K);
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = fac[i - 1] * i % Mod;
  inv[N - 1] = ksm(fac[N - 1], Mod - 2);
  for (int i = N - 2; ~i; i--)
    inv[i] = inv[i + 1] * (i + 1) % Mod;
  for (int i = 0; i <= n; i++) {
    int res = K - i * A;
    if (res < 0)
      break;
    if (res % B == 0) {
      int j = res / B;
      if (j > n)
        continue;
      ans = 1ll * (ans + 1ll * C(n, i) * C(n, j) % Mod) % Mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define int long long
#define INF 1000000000
#define MOD 998244353
int n, fact[364364], ans;
int k;
int modpow(int a, int b) {
  if (b == 0)
    return 1;
  if (b % 2)
    return modpow(a, b - 1) * a % MOD;
  return modpow(a, b / 2) * modpow(a, b / 2) % MOD;
}
int comb(int x) {
  return fact[n] * modpow(fact[x], MOD - 2) % MOD *
         modpow(fact[n - x], MOD - 2) % MOD;
}
signed main() {
  int a, b;
  cin >> n >> a >> b >> k;
  fact[0] = 1;
  for (int i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * i % MOD;
  rep(i, n + 1) {
    if ((k - a * i) % b != 0)
      continue;
    if ((k - a * i) / b > n)
      continue;
    int x = i, y = (k - a * i) / b;
    ans += comb(x) * comb(y) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define int long long
#define INF 1000000000
#define MOD 998244353
int n, fact[364364], ans;
int k;
int modpow(int a, int b) {
  if (b == 0)
    return 1;
  if (b % 2)
    return modpow(a, b - 1) * a % MOD;
  return modpow(a, b / 2) * modpow(a, b / 2) % MOD;
}
int comb(int x) {
  return fact[n] * modpow(fact[x], MOD - 2) % MOD *
         modpow(fact[n - x], MOD - 2) % MOD;
}
signed main() {
  int a, b;
  cin >> n >> a >> b >> k;
  fact[0] = 1;
  for (int i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * i % MOD;
  rep(i, n + 1) {
    if ((k - a * i) % b != 0)
      continue;
    if ((k - a * i) / b > n || (k - a * i) / b < 0)
      continue;
    int x = i, y = (k - a * i) / b;
    ans += comb(x) * comb(y) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#define mod 998244353
typedef long long ll;
ll inv[300005], c[300005];
int main() {
  ll n, a, b, k, ans = 0;
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  inv[1] = 1;
  for (ll i = 2; i <= n; i++)
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  c[0] = 1;
  for (ll i = 1; i <= n; i++)
    c[i] = c[i - 1] * (n - i + 1) % mod * inv[i] % mod;
  for (ll i = 0, j; i <= n; i++) {
    if (a * i > k)
      break;
    if ((k - a * i) % b == 0)
      j = (k - a * i) / b;
    else
      continue;
    ans += c[i] * c[j] % mod, ans %= mod;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <cstdio>
#define mod 998244353
typedef long long ll;
ll inv[300005], c[300005];
int main() {
  ll n, a, b, k, ans = 0;
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  inv[1] = 1;
  for (ll i = 2; i <= n; i++)
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  c[0] = 1;
  for (ll i = 1; i <= n; i++)
    c[i] = c[i - 1] * (n - i + 1) % mod * inv[i] % mod;
  for (ll i = 0, j; i <= n; i++) {
    if (a * i > k)
      break;
    if ((k - a * i) % b == 0)
      j = (k - a * i) / b;
    else
      continue;
    if (j > n)
      continue;
    ans += c[i] * c[j] % mod, ans %= mod;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long int64;
const int M = 998244353;
const int N = (int)4e5 + 10;

int fact[N], ifact[N];

int64 gcd(int64 a, int64 b) { return b ? gcd(b, a % b) : a; }

int mult(int a, int b) { return (a * (int64)b) % M; }

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

int inv(int x) { return bpow(x, M - 2); }

int cnk(int n, int k) { return mult(fact[n], mult(ifact[k], ifact[n - k])); }

int main() {
  int n, a, b;
  int64 k;
  scanf("%d%d%d%lld", &n, &a, &b, &k);
  fact[0] = ifact[0] = 1;
  for (int i = 0; i < n; ++i) {
    fact[i + 1] = mult(fact[i], i + 1);
    ifact[i + 1] = inv(fact[i + 1]);
  }
  int64 g = gcd(a, b);
  if (k % g != 0) {
    printf("%d\n", 0);
    return 0;
  }
  k /= g, a /= g, b /= g;
  int64 base_x = 0;
  for (int x = 0; x < b; ++x) {
    if ((k - x * (int64)a) % b == 0) {
      base_x = x;
      break;
    }
  }
  int ans = 0;
  while (base_x <= n) {
    int64 base_y = (k - base_x * (int64)a) / b;
    if (base_y <= n) {
      ans = (ans + cnk(n, base_x) * (int64)cnk(n, base_y)) % M;
    }
    base_x += b;
  }
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long int64;
const int M = 998244353;
const int N = (int)4e5 + 10;

int fact[N], ifact[N];

int64 gcd(int64 a, int64 b) { return b ? gcd(b, a % b) : a; }

int mult(int a, int b) { return (a * (int64)b) % M; }

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

int inv(int x) { return bpow(x, M - 2); }

int cnk(int n, int k) { return mult(fact[n], mult(ifact[k], ifact[n - k])); }

int main() {
  int n, a, b;
  int64 k;
  scanf("%d%d%d%lld", &n, &a, &b, &k);
  fact[0] = ifact[0] = 1;
  for (int i = 0; i < n; ++i) {
    fact[i + 1] = mult(fact[i], i + 1);
    ifact[i + 1] = inv(fact[i + 1]);
  }
  int64 g = gcd(a, b);
  if (k % g != 0) {
    printf("%d\n", 0);
    return 0;
  }
  k /= g, a /= g, b /= g;
  int64 base_x = 0;
  for (int x = 0; x < b; ++x) {
    if ((k - x * (int64)a) % b == 0) {
      base_x = x;
      break;
    }
  }
  int ans = 0;
  while (base_x <= n) {
    int64 base_y = (k - base_x * (int64)a) / b;
    if ((base_y >= 0) && (base_y <= n)) {
      ans = (ans + cnk(n, base_x) * (int64)cnk(n, base_y)) % M;
    }
    base_x += b;
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03332 (C++)

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define whole(f, x, ...)                                                       \
  ([&](decltype((x)) whole) {                                                  \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \
  })(x)

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (998244353);

ll power(ll x, ll n) {
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return power(x * x % MOD, n / 2) % MOD;
  return power(x * x % MOD, n / 2) * x % MOD;
}

int main() {
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll fact = 1;
  rep(i, n) fact = fact * (i + 1) % MOD;
  vector<ll> inv(n + 1);
  inv[n] = power(fact, MOD - 2);
  for (int i = n; i > 0; --i)
    inv[i - 1] = inv[i] * i % MOD;

  function<ll(ll, ll)> comb = [&inv, &fact](ll n, ll r) {
    return fact * inv[r] % MOD * inv[n - r] % MOD;
  };

  ll res = 0;
  for (int i = 0; i <= n && a * i <= k; ++i) {
    if (((k - a * i) % b == 0)) {
      int j = (k - a * i) / b;
      res = (res + comb(n, j) * comb(n, i) % MOD) % MOD;
    }
  }
  cout << res << endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define whole(f, x, ...)                                                       \
  ([&](decltype((x)) whole) {                                                  \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \
  })(x)

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (998244353);

ll power(ll x, ll n) {
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return power(x * x % MOD, n / 2) % MOD;
  return power(x * x % MOD, n / 2) * x % MOD;
}

int main() {
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll fact = 1;
  rep(i, n) fact = fact * (i + 1) % MOD;
  vector<ll> inv(n + 1);
  inv[n] = power(fact, MOD - 2);
  for (int i = n; i > 0; --i)
    inv[i - 1] = inv[i] * i % MOD;

  function<ll(ll, ll)> comb = [&inv, &fact](ll n, ll r) {
    return fact * inv[r] % MOD * inv[n - r] % MOD;
  };

  ll res = 0;
  for (int i = 0; i <= n && a * i <= k; ++i) {
    if (((k - a * i) % b == 0)) {
      int j = (k - a * i) / b;
      if (j > n)
        continue;
      res = (res + comb(n, j) * comb(n, i) % MOD) % MOD;
    }
  }
  cout << res << endl;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 1;
const long long mod = 998244353;

long long cnk[N], r[N];

int main() {
  long long i, j, n, A, B, K;
  // freopen("input.txt", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> A >> B >> K;
  long long ans = 0;
  r[1] = 1;
  for (int i = 2; i <= n; ++i)
    r[i] = (mod - (mod / i) * r[mod % i] % mod) % mod;
  cnk[0] = 1;
  for (i = 1; i <= n; ++i)
    cnk[i] = (((cnk[i - 1] * r[i]) % mod) * (n - i + 1)) % mod;
  for (i = 0; i <= n; ++i)
    if (i * A <= K && (K - i * A) % B == 0)
      ans = (ans + cnk[i] * cnk[(K - i * A) / B]) % mod;
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 1;
const long long mod = 998244353;

long long cnk[N], r[N];

int main() {
  long long i, j, n, A, B, K;
  // freopen("input.txt", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> A >> B >> K;
  long long ans = 0;
  r[1] = 1;
  for (int i = 2; i <= n; ++i)
    r[i] = (mod - (mod / i) * r[mod % i] % mod) % mod;
  cnk[0] = 1;
  for (i = 1; i <= n; ++i)
    cnk[i] = (((cnk[i - 1] * r[i]) % mod) * (n - i + 1)) % mod;
  for (i = 0; i <= n; ++i)
    if (i * A <= K && (K - i * A) % B == 0 && (K - i * A) / B <= n)
      ans = (ans + cnk[i] * cnk[(K - i * A) / B]) % mod;
  cout << ans;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define P pair<int, int>
#define len(s) (int)s.size()
#define pb push_back

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void cmps(vector<int> &v, int &i) { i = lower_bound(all(v), i) - v.begin(); }
constexpr int mod = 998244353;
constexpr int inf = 3e18;

int mod_pow(int x, int y, int m = mod) {
  int res = 1;
  while (y > 0) {
    if (y & 1)
      res = res * x % m;
    y >>= 1;
    x = x * x % m;
  }
  return res;
}
int perm[1000001], inv[1000001];
void init_perm() {
  perm[0] = 1;
  REP(i, 1000001) perm[i] = perm[i - 1] * i % mod;
  inv[1000000] = mod_pow(perm[1000000], mod - 2);
  for (int i = 999999; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % mod;
  }
}
int nCk(int x, int y) {
  if (x < y)
    return 0;
  return perm[x] * inv[x - y] % mod * inv[y] % mod;
}

signed main() {
  init_perm();
  int N, A, B, K;
  cin >> N >> A >> B >> K;
  int ans = 0;
  rep(i, N + 1) {
    if ((K - A * i) % B)
      continue;
    int j = (K - A * i) / B;
    ans += nCk(N, i) * nCk(N, j) % mod;
    ans %= mod;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define P pair<int, int>
#define len(s) (int)s.size()
#define pb push_back

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void cmps(vector<int> &v, int &i) { i = lower_bound(all(v), i) - v.begin(); }
constexpr int mod = 998244353;
constexpr int inf = 3e18;

int mod_pow(int x, int y, int m = mod) {
  int res = 1;
  while (y > 0) {
    if (y & 1)
      res = res * x % m;
    y >>= 1;
    x = x * x % m;
  }
  return res;
}
int perm[1000001], inv[1000001];
void init_perm() {
  perm[0] = 1;
  REP(i, 1000001) perm[i] = perm[i - 1] * i % mod;
  inv[1000000] = mod_pow(perm[1000000], mod - 2);
  for (int i = 999999; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % mod;
  }
}
int nCk(int x, int y) {
  if (x < y)
    return 0;
  return perm[x] * inv[x - y] % mod * inv[y] % mod;
}

signed main() {
  init_perm();
  int N, A, B, K;
  cin >> N >> A >> B >> K;
  int ans = 0;
  rep(i, N + 1) {
    if ((K - A * i) % B || K < A * i)
      continue;
    int j = (K - A * i) / B;
    ans += nCk(N, i) * nCk(N, j) % mod;
    ans %= mod;
  }
  cout << ans << endl;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const long long MAXN = 300005, MOD = 998244353;
long long jc[MAXN], inv[MAXN];
long long gcd(long long a, long long b) {
  return a % b == 0 ? b : gcd(b, a % b);
}
long long ksm(long long x, long long y) {
  long long k = 1;
  while (y) {
    if (y & 1)
      k = (k * x) % MOD;
    x = (x * x) % MOD;
    y >>= 1;
  }
  return k;
}
void Init() {
  jc[0] = 1;
  for (long long i = 1; i < MAXN; i++)
    jc[i] = (jc[i - 1] * i) % MOD;
  inv[MAXN - 1] = ksm(jc[MAXN - 1], MOD - 2);
  for (long long i = MAXN - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % MOD;
}
long long C(long long n, long long m) {
  if (m < n || n < 0 || m < 0)
    return 0ll;
  return ((jc[m] * inv[n]) % MOD * inv[m - n]) % MOD;
}
int main() {
  Init();
  long long n, a1, b1, k;
  scanf("%lld%lld%lld%lld", &n, &a1, &b1, &k);
  long long e = gcd(gcd(a1, b1), k);
  k /= e;
  a1 /= e;
  b1 /= e;
  long long a = 0, b = 0;
  for (long long i = 0; i * a1 <= k; i++) {
    if ((k - (i * a1)) % b1 == 0) {
      b = (k - (i * a1)) / b1;
      b %= a1;
      a = (k - (b * b1)) / a1;
      break;
    }
  }
  if (a * a1 + b * b1 != k) {
    printf("0\n");
    return 0;
  }
  long long ans = 0;
  while (a >= 0) {
    ans = (ans + (C(a, n) * C(b, n)) % MOD) % MOD;
    a -= b1;
    b += a1;
  }
  printf("%lld\n", (ans + MOD) % MOD);
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const long long MAXN = 300005, MOD = 998244353;
long long jc[MAXN], inv[MAXN];
long long gcd(long long a, long long b) {
  return a % b == 0 ? b : gcd(b, a % b);
}
long long ksm(long long x, long long y) {
  long long k = 1;
  while (y) {
    if (y & 1)
      k = (k * x) % MOD;
    x = (x * x) % MOD;
    y >>= 1;
  }
  return k;
}
void Init() {
  jc[0] = 1;
  for (long long i = 1; i < MAXN; i++)
    jc[i] = (jc[i - 1] * i) % MOD;
  inv[MAXN - 1] = ksm(jc[MAXN - 1], MOD - 2);
  for (long long i = MAXN - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % MOD;
}
long long C(long long n, long long m) {
  if (m < n || n < 0 || m < 0)
    return 0ll;
  return ((jc[m] * inv[n]) % MOD * inv[m - n]) % MOD;
}
int main() {
  Init();
  long long n, a1, b1, k;
  scanf("%lld%lld%lld%lld", &n, &a1, &b1, &k);
  long long e = gcd(k, gcd(a1, b1));
  if (e != 0) {
    k /= e;
    a1 /= e;
    b1 /= e;
  }
  long long a = 0, b = 0;
  for (long long i = 0; i * a1 <= k; i++) {
    if ((k - (i * a1)) % b1 == 0) {
      b = (k - (i * a1)) / b1;
      b %= a1;
      a = (k - (b * b1)) / a1;
      break;
    }
  }
  if (a * a1 + b * b1 != k) {
    printf("0\n");
    return 0;
  }
  long long ans = 0;
  while (a >= 0) {
    ans = (ans + (C(a, n) * C(b, n)) % MOD) % MOD;
    a -= b1;
    b += a1;
  }
  printf("%lld\n", (ans + MOD) % MOD);
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
typedef long long ll;
ll n, m, MOD = 998244353, a, b, ans, bik[300001], A[300001], B[300001];
ll f(ll x, ll y) {
  if (y == 0)
    return 1;
  if (y % 2 == 0)
    return f(x, y / 2) * f(x, y / 2) % MOD;
  return x * f(x, y - 1) % MOD;
}
ll comb(ll x, ll y) {
  return bik[x] * f(bik[x - y], MOD - 2) % MOD * f(bik[y], MOD - 2) % MOD;
}
int main(void) {
  bik[0] = 1;
  for (ll i = 1; i <= 300000; i++) {
    bik[i] = bik[i - 1] * i;
    bik[i] %= MOD;
  }
  cin >> n >> a >> b >> m;
  for (ll i = 0LL; i <= min(n, (m / a)); i++) {
    A[i] = comb(n, i);
  }
  for (ll i = 0LL; i <= min(n, (m / b)); i++) {
    B[i] = comb(n, i);
  }
  for (ll i = 0LL; i <= min(n, (m / a)); i++) {
    if ((m - i * a) % b == 0) {
      ans += A[i] * B[(m - i * a) / b] % MOD;
      ans %= MOD;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
typedef long long ll;
ll n, m, MOD = 998244353, a, b, ans, bik[300001], A[300001], B[300001];
ll f(ll x, ll y) {
  if (y == 0)
    return 1;
  if (y % 2 == 0)
    return f(x, y / 2) * f(x, y / 2) % MOD;
  return x * f(x, y - 1) % MOD;
}
ll comb(ll x, ll y) {
  return bik[x] * f(bik[x - y], MOD - 2) % MOD * f(bik[y], MOD - 2) % MOD;
}
int main(void) {
  bik[0] = 1;
  for (ll i = 1; i <= 300000; i++) {
    bik[i] = bik[i - 1] * i;
    bik[i] %= MOD;
  }
  cin >> n >> a >> b >> m;
  for (ll i = 0LL; i <= min(n, (m / a)); i++) {
    A[i] = comb(n, i);
  }
  for (ll i = 0LL; i <= min(n, (m / b)); i++) {
    B[i] = comb(n, i);
  }
  for (ll i = 0LL; i <= min(n, (m / a)); i++) {
    if ((m - i * a) % b == 0 && (m - i * a) / b <= n) {
      ans += A[i] * B[(m - i * a) / b] % MOD;
      ans %= MOD;
    }
  }
  cout << ans << endl;
}
Problem p03332 (C++)

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

using namespace std;

typedef long long ll;

const int maxn = 300100;
const int mod = 998244353;

int add(int a, int b) { return (a + b) % mod; }
int mult(int a, int b) { return ll(a) * b % mod; }
int exp(int b, int e) {
  if (!e)
    return 1;
  if (e & 1)
    return mult(b, exp(b, e - 1));
  int res = exp(b, e >> 1);
  return mult(res, res);
}

int fact[maxn], invfact[maxn];

int C(int a, int b) { return mult(fact[a], mult(invfact[b], invfact[a - b])); }

int n, a, b;
ll k;

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

  fact[0] = 1;
  for (int i = 1; i < maxn; i++)
    fact[i] = mult(fact[i - 1], i);
  for (int i = 0; i < maxn; i++)
    invfact[i] = exp(fact[i], mod - 2);

  int ans = 0;
  for (int i = 0; i <= n; i++) { // num a
    ll tot = ll(a) * i;
    if ((k - tot) % b == 0) {
      ll j = (k - tot) / b;
      if (j <= n)
        ans = add(ans, mult(C(n, i), C(n, j)));
    }
  }

  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

const int maxn = 300100;
const int mod = 998244353;

int add(int a, int b) { return (a + b) % mod; }
int mult(int a, int b) { return ll(a) * b % mod; }
int exp(int b, int e) {
  if (!e)
    return 1;
  if (e & 1)
    return mult(b, exp(b, e - 1));
  int res = exp(b, e >> 1);
  return mult(res, res);
}

int fact[maxn], invfact[maxn];

int C(int a, int b) { return mult(fact[a], mult(invfact[b], invfact[a - b])); }

int n, a, b;
ll k;

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

  fact[0] = 1;
  for (int i = 1; i < maxn; i++)
    fact[i] = mult(fact[i - 1], i);
  for (int i = 0; i < maxn; i++)
    invfact[i] = exp(fact[i], mod - 2);

  int ans = 0;
  for (int i = 0; i <= n; i++) { // num a
    ll tot = ll(a) * i;
    if ((k - tot) % b == 0) {
      ll j = (k - tot) / b;
      if (0 <= j && j <= n)
        ans = add(ans, mult(C(n, i), C(n, j)));
    }
  }

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

Buggy submission (status: Runtime Error):
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const long long INF = 1e18;
const double PI = 2 * asin(1);

ll AN(ll A, ll N) {
  if (N == 0)
    return 1;
  else {
    if (N % 2 == 0) {
      return AN(A * A % mod, N / 2) % mod;
    } else {
      return A * AN(A * A % mod, N / 2) % mod;
    }
  }
}

int main() {

  ll N;
  cin >> N;
  vector<ll> dir(N + 1), rev(N + 1);
  dir[0] = 1;
  for (ll i = 1; i < N + 1; i++) {
    dir[i] = dir[i - 1] * i % mod;
  }
  for (ll i = 0; i < N + 1; i++) {
    rev[i] = AN(dir[i], mod - 2);
  }

  ll ans = 0;
  ll A, B, K;
  cin >> A >> B >> K;

  for (ll i = 0; i <= N; i++) {
    ll rest = K - A * i;
    if (rest >= 0 && rest % B == 0) {
      ll a = i, b = rest / B;
      ll now = dir[N];
      now *= rev[a];
      now %= mod;
      now *= rev[N - a];
      now %= mod;
      now *= dir[N];
      now %= mod;
      now *= rev[b];
      now %= mod;
      now *= rev[N - b];
      now %= mod;
      ans += now;
      ans %= mod;
    } else if (rest < 0) {
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const long long INF = 1e18;
const double PI = 2 * asin(1);

ll AN(ll A, ll N) {
  if (N == 0)
    return 1;
  else {
    if (N % 2 == 0) {
      return AN(A * A % mod, N / 2) % mod;
    } else {
      return A * AN(A * A % mod, N / 2) % mod;
    }
  }
}

int main() {

  ll N;
  cin >> N;
  vector<ll> dir(N + 1), rev(N + 1);
  dir[0] = 1;
  for (ll i = 1; i < N + 1; i++) {
    dir[i] = dir[i - 1] * i % mod;
  }
  for (ll i = 0; i < N + 1; i++) {
    rev[i] = AN(dir[i], mod - 2);
  }

  ll ans = 0;
  ll A, B, K;
  cin >> A >> B >> K;

  for (ll i = 0; i <= N; i++) {
    ll rest = K - A * i;
    if (rest >= 0 && rest % B == 0 && rest / B <= N) {
      ll a = i, b = rest / B;
      ll now = dir[N];
      now *= rev[a];
      now %= mod;
      now *= rev[N - a];
      now %= mod;
      now *= dir[N];
      now %= mod;
      now *= rev[b];
      now %= mod;
      now *= rev[N - b];
      now %= mod;
      ans += now;
      ans %= mod;
    } else if (rest < 0) {
      break;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03332 (C++)

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() { printf("yes\n"); }
void no() { printf("no\n"); }
void Yes() { printf("Yes\n"); }
void No() { printf("No\n"); }
void YES() { printf("YES\n"); }
void NO() { printf("NO\n"); }

ll Pow(ll A, ll N) {
  if (N == 0)
    return 1;
  if (N % 2 == 0)
    return Pow(A * A % MOD2, N / 2);
  return A * Pow(A * A % MOD2, N / 2) % MOD2;
}

ll N, A, B, K, nCr[int(3e5 + 5)];

int main() {
  cin >> N >> A >> B >> K;
  nCr[0] = 1;
  for (ll i = 1; i <= N; i++) {
    nCr[i] = nCr[i - 1] * (N + 1 - i) % MOD2;
    nCr[i] *= Pow(i, MOD2 - 2);
    nCr[i] %= MOD2;
  }

  ll ans = 0;
  for (ll i = 0; i <= N; i++) {
    ll rest = K - A * i;
    if (rest % B != 0)
      continue;
    rest /= B;
    if (rest > N)
      continue;

    ll now = nCr[i] * nCr[rest] % MOD2;
    ans += now;
    ans %= MOD2;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() { printf("yes\n"); }
void no() { printf("no\n"); }
void Yes() { printf("Yes\n"); }
void No() { printf("No\n"); }
void YES() { printf("YES\n"); }
void NO() { printf("NO\n"); }

ll Pow(ll A, ll N) {
  if (N == 0)
    return 1;
  if (N % 2 == 0)
    return Pow(A * A % MOD2, N / 2);
  return A * Pow(A * A % MOD2, N / 2) % MOD2;
}

ll N, A, B, K, nCr[int(3e5 + 5)];

int main() {
  cin >> N >> A >> B >> K;
  nCr[0] = 1;
  for (ll i = 1; i <= N; i++) {
    nCr[i] = nCr[i - 1] * (N + 1 - i) % MOD2;
    nCr[i] *= Pow(i, MOD2 - 2);
    nCr[i] %= MOD2;
  }

  ll ans = 0;
  for (ll i = 0; i <= N; i++) {
    ll rest = K - A * i;
    if (rest % B != 0)
      continue;
    rest /= B;
    if (rest > N || rest < 0)
      continue;

    ll now = nCr[i] * nCr[rest] % MOD2;
    ans += now;
    ans %= MOD2;
  }
  cout << ans << endl;

  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, mod = 998244353, inf = 0x3f3f3f3f;
int n, m, k, t, fac[maxn], inv[maxn];
int qpow(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1)
      ret = (long long)ret * x % mod;
    x = (long long)x * x % mod;
    y >>= 1;
  }
  return ret;
}
int C(int x, int y) {
  return (long long)fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main() {
  int i, j;
  fac[0] = 1;
  for (i = 1; i < maxn; i++)
    fac[i] = (long long)fac[i - 1] * i % mod;
  inv[maxn - 1] = qpow(fac[maxn - 1], mod - 2);
  for (i = maxn - 2; i >= 0; i--)
    inv[i] = (long long)inv[i + 1] * (i + 1) % mod;
  long long k;
  int a, b;
  scanf("%d%d%d%lld", &n, &a, &b, &k);
  int ret = 0;
  for (i = 0; i <= n && (long long)a * i <= k; i++) {
    long long cnt = (k - (long long)a * i) / b;
    if (cnt > n || cnt * b != k - (long long)a * i)
      continue;
    ret += (long long)C(n, i) * C(n, cnt) % mod;
    ret %= mod;
  }
  printf("%d\n", ret);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10, mod = 998244353, inf = 0x3f3f3f3f;
int n, m, k, t, fac[maxn], inv[maxn];
int qpow(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1)
      ret = (long long)ret * x % mod;
    x = (long long)x * x % mod;
    y >>= 1;
  }
  return ret;
}
int C(int x, int y) {
  return (long long)fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main() {
  int i, j;
  fac[0] = 1;
  for (i = 1; i < maxn; i++)
    fac[i] = (long long)fac[i - 1] * i % mod;
  inv[maxn - 1] = qpow(fac[maxn - 1], mod - 2);
  for (i = maxn - 2; i >= 0; i--)
    inv[i] = (long long)inv[i + 1] * (i + 1) % mod;
  long long k;
  int a, b;
  scanf("%d%d%d%lld", &n, &a, &b, &k);
  int ret = 0;
  for (i = 0; i <= n && (long long)a * i <= k; i++) {
    long long cnt = (k - (long long)a * i) / b;
    if (cnt > n || cnt * b != k - (long long)a * i)
      continue;
    ret += (long long)C(n, i) * C(n, cnt) % mod;
    ret %= mod;
  }
  printf("%d\n", ret);
  return 0;
}
Problem p03332 (C++)

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

typedef long long ll;

const int N = 3e5 + 1;
ll bp = 998244353, fact[N];

void init() {
  fact[0] = 1;
  for (ll i = 1; i < N; i++)
    fact[i] = (fact[i - 1] * i) % bp;
}

ll fexp(ll b, ll p) {
  if (p <= 0)
    return 1;
  ll ans = 1;
  while (p) {
    if (p % 2)
      ans = (ans * b) % bp;
    p >>= 1;
    b = (b * b) % bp;
  }
  return ans;
}

ll ncr(ll n, ll r) {
  return (fact[n] *
          ((fexp(fact[r], bp - 2) * fexp(fact[n - r], bp - 2)) % bp)) %
         bp;
}

int main() {
  init();
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  for (ll i = 0; i <= n; i++)
    if ((k - a * i) % b == 0 && (k - a * i) / b <= n)
      ans = (ans + (ncr(n, i) * ncr(n, (k - a * i) / b)) % bp) % bp;
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;

const int N = 3e5 + 1;
ll bp = 998244353, fact[N];

void init() {
  fact[0] = 1;
  for (ll i = 1; i < N; i++)
    fact[i] = (fact[i - 1] * i) % bp;
}

ll fexp(ll b, ll p) {
  if (p <= 0)
    return 1;
  ll ans = 1;
  while (p) {
    if (p % 2)
      ans = (ans * b) % bp;
    p >>= 1;
    b = (b * b) % bp;
  }
  return ans;
}

ll ncr(ll n, ll r) {
  return (fact[n] *
          ((fexp(fact[r], bp - 2) * fexp(fact[n - r], bp - 2)) % bp)) %
         bp;
}

int main() {
  init();
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  for (ll i = 0; i <= n && a * i <= k; i++)
    if ((k - a * i) % b == 0 && (k - a * i) / b <= n)
      ans = (ans + (ncr(n, i) * ncr(n, (k - a * i) / b)) % bp) % bp;
  cout << ans << endl;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1, MAXN = 3e5 + 10, mod = 998244353;
int fc[N], ifc[N];
long long power(long long a, long long b) {
  if (!b)
    return 1;
  long long rtr = power(a, b / 2);
  if (b % 2)
    return rtr * rtr % mod * a % mod;
  return rtr * rtr % mod;
}
void getFc() {
  fc[0] = ifc[0] = 1;
  for (int i = 1; i < N; i++) {
    fc[i] = 1ll * fc[i - 1] * i % mod;
    ifc[i] = 1ll * ifc[i - 1] * power(i, mod - 2) % mod;
  }
  return;
}
long long ch(int x, int y) {
  return 1ll * fc[y] * ifc[x] % mod * ifc[y - x] % mod;
}
int main() {
  long long n, a, b, k, ans = 0;
  cin >> n >> a >> b >> k;
  getFc();
  for (int i = 0; i <= n; i++) {
    long long rn = k - i * a;
    if (rn >= 0 && rn % b == 0)
      ans = (ans + 1ll * ch(i, n) * ch(rn / b, n) % mod) % mod;
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1, MAXN = 3e5 + 10, mod = 998244353;
int fc[N], ifc[N];
long long power(long long a, long long b) {
  if (!b)
    return 1;
  long long rtr = power(a, b / 2);
  if (b % 2)
    return rtr * rtr % mod * a % mod;
  return rtr * rtr % mod;
}
void getFc() {
  fc[0] = ifc[0] = 1;
  for (int i = 1; i < N; i++) {
    fc[i] = 1ll * fc[i - 1] * i % mod;
    ifc[i] = 1ll * ifc[i - 1] * power(i, mod - 2) % mod;
  }
  return;
}
long long ch(int x, int y) {
  return 1ll * fc[y] * ifc[x] % mod * ifc[y - x] % mod;
}
int main() {
  long long n, a, b, k, ans = 0;
  cin >> n >> a >> b >> k;
  getFc();
  for (int i = 0; i <= n; i++) {
    long long rn = k - i * a;
    if (rn >= 0 && rn % b == 0 && rn / b <= n)
      ans = (ans + 1ll * ch(i, n) * ch(rn / b, n) % mod) % mod;
  }
  cout << ans;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define rep(i, a, b) for (i = a; i <= b; i++)
using namespace std;
typedef long long ll;
const int mod = 998244353;
const int N = 300010;
int cj[N], inv[N];
int ans;

int power(int x, int y) {
  int ret = 1;
  for (; y; y >>= 1, x = 1ll * x * x % mod) {
    if (y & 1)
      ret = 1ll * ret * x % mod;
  }
  return ret;
}

int C(int n, int m) { return 1ll * cj[n] * inv[m] % mod * inv[n - m] % mod; }

int main() {
  // freopen("a.in","r",stdin);
  // freopen("a.out","w",stdout);
  int n;
  ll A, B, K, x;
  int i;
  scanf("%d%lld%lld%lld", &n, &A, &B, &K);
  cj[0] = 1;
  rep(i, 1, n) cj[i] = 1ll * cj[i - 1] * i % mod;
  inv[n] = power(cj[n], mod - 2);
  inv[0] = 1;
  for (i = n - 1; i; i--)
    inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
  rep(i, 0, n) {
    if (1ll * i * A > K)
      break;
    x = K - 1ll * i * A;
    if (x % B != 0)
      continue;
    ans = (ans + 1ll * C(n, i) * C(n, x / B)) % mod;
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define rep(i, a, b) for (i = a; i <= b; i++)
using namespace std;
typedef long long ll;
const int mod = 998244353;
const int N = 300010;
int cj[N], inv[N];
int ans;

int power(int x, int y) {
  int ret = 1;
  for (; y; y >>= 1, x = 1ll * x * x % mod) {
    if (y & 1)
      ret = 1ll * ret * x % mod;
  }
  return ret;
}

int C(int n, int m) { return 1ll * cj[n] * inv[m] % mod * inv[n - m] % mod; }

int main() {
  // freopen("a.in","r",stdin);
  // freopen("a.out","w",stdout);
  int n;
  ll A, B, K, x;
  int i;
  scanf("%d%lld%lld%lld", &n, &A, &B, &K);
  cj[0] = 1;
  rep(i, 1, n) cj[i] = 1ll * cj[i - 1] * i % mod;
  inv[n] = power(cj[n], mod - 2);
  inv[0] = 1;
  for (i = n - 1; i; i--)
    inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
  rep(i, 0, n) {
    if (1ll * i * A > K)
      break;
    x = K - 1ll * i * A;
    if (x % B != 0)
      continue;
    x /= B;
    if (x > n)
      continue;
    ans = (ans + 1ll * C(n, i) * C(n, x)) % mod;
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
// In The Name Of God
#include <bits/stdc++.h>

#define sqr(A) ((A) * (A))
#define F first
#define S second
#define MP make_pair
#define bsz __builtin_popcount
#define all(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 998244353;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 3e5 + 20;
ll ans, fac[N], n, a, b, k;

ll powmod(ll x, ll y, ll MODD = MOD) {
  if (y == 0)
    return 1LL;
  ll tmp = powmod(x, y / 2, MODD);
  tmp = sqr(tmp) % MODD;
  return (tmp * (y % 2 ? (x % MODD) : 1LL)) % MODD;
}

ll divmod(ll x, ll y, ll MODD = MOD) {
  return ((x % MODD) * powmod(y, MODD - 2, MODD)) % MODD;
}

ll CR(ll r, ll n, ll MODD = MOD) {
  return divmod(fac[n], (fac[r] * fac[n - r]) % MODD, MODD);
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  fac[0] = 1;
  for (ll i = 1; i < N; i++)
    fac[i] = (fac[i - 1] * i) % MOD;
  cin >> n >> a >> b >> k;
  for (ll x = 0; x <= n; x++) {
    if (k >= x * a && (k - x * a) % b == 0) {
      ll y = (k - x * a) / b;
      ans = (ans + CR(y, n) * CR(x, n)) % MOD;
    }
  }
  cout << ans << endl;
}


Fixed submission:
// In The Name Of God
#include <bits/stdc++.h>

#define sqr(A) ((A) * (A))
#define F first
#define S second
#define MP make_pair
#define bsz __builtin_popcount
#define all(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 998244353;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 3e5 + 20;
ll ans, fac[N], n, a, b, k;

ll powmod(ll x, ll y, ll MODD = MOD) {
  if (y == 0)
    return 1LL;
  ll tmp = powmod(x, y / 2, MODD);
  tmp = sqr(tmp) % MODD;
  return (tmp * (y % 2 ? (x % MODD) : 1LL)) % MODD;
}

ll divmod(ll x, ll y, ll MODD = MOD) {
  return ((x % MODD) * powmod(y, MODD - 2, MODD)) % MODD;
}

ll CR(ll r, ll n, ll MODD = MOD) {
  return divmod(fac[n], (fac[r] * fac[n - r]) % MODD, MODD);
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  fac[0] = 1;
  for (ll i = 1; i < N; i++)
    fac[i] = (fac[i - 1] * i) % MOD;
  cin >> n >> a >> b >> k;
  for (ll x = 0; x <= n; x++) {
    if (k >= x * a && (k - x * a) % b == 0) {
      ll y = (k - x * a) / b;
      if (y > n)
        continue;
      ans = (ans + CR(y, n) * CR(x, n)) % MOD;
    }
  }
  cout << ans << endl;
}
Problem p03332 (C++)

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

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int)x.size())
#define pb(x) push_back(x)

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

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

ll n, a, b, k, sol;
ll fakt[MAXN], inv[MAXN], povrh[MAXN], pref[MAXN];

ll add(int x, int y) {
  x += y;
  if (x >= mod)
    return x - mod;
  return x;
}

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

ll sub(ll x, ll y) {
  x -= y;
  if (x < 0)
    x += mod;
  return x;
}

ll pot(ll b, ll p) {
  if (p % 2)
    return pot(b, p - 1) * b % mod;
  else {
    ll tmp = p ? pot(b, p / 2) % mod : 1;
    return tmp * tmp % mod;
  }
}

int main() {

  cin >> n >> a >> b >> k;
  fakt[1] = 1;
  FOR(i, 2, n + 1)
  fakt[i] = mul(fakt[i - 1], i);
  FOR(i, 1, n + 1)
  inv[i] = pot(fakt[i], mod - 2);
  FOR(i, 1, n + 1)
  povrh[i] = mul(fakt[n], mul(inv[i], inv[n - i]));
  povrh[0] = 1;
  povrh[n] = 1;

  REP(i, n + 1) {
    ll x = i * a;
    ll tmp = k - x;
    if (tmp % b || x > k)
      continue;
    ll y = tmp / b;
    sol = add(sol, mul(povrh[i], povrh[y]));
  }
  cout << sol;
}


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

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int)x.size())
#define pb(x) push_back(x)

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

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

ll n, a, b, k, sol;
ll fakt[MAXN], inv[MAXN], povrh[MAXN], pref[MAXN];

ll add(int x, int y) {
  x += y;
  if (x >= mod)
    return x - mod;
  return x;
}

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

ll sub(ll x, ll y) {
  x -= y;
  if (x < 0)
    x += mod;
  return x;
}

ll pot(ll b, ll p) {
  if (p % 2)
    return pot(b, p - 1) * b % mod;
  else {
    ll tmp = p ? pot(b, p / 2) % mod : 1;
    return tmp * tmp % mod;
  }
}

int main() {

  cin >> n >> a >> b >> k;
  fakt[1] = 1;
  FOR(i, 2, n + 1)
  fakt[i] = mul(fakt[i - 1], i);
  FOR(i, 1, n + 1)
  inv[i] = pot(fakt[i], mod - 2);
  FOR(i, 1, n + 1)
  povrh[i] = mul(fakt[n], mul(inv[i], inv[n - i]));
  povrh[0] = 1;
  povrh[n] = 1;

  REP(i, n + 1) {
    ll x = i * a;
    ll tmp = k - x;
    if (tmp % b || x > k)
      continue;
    ll y = tmp / b;
    if (y > n)
      continue;
    sol = add(sol, mul(povrh[i], povrh[y]));
  }
  cout << sol;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#pragma optimize "O3"
#define endl '\n'
const int MAXN = 400017;
const int MOD = 998244353;
using namespace std;

int n, a, b, fact[MAXN], inv[MAXN];
long long ans, k;

int poww(int st, int p) {
  if (p == 0)
    return 1;
  int half = poww(st, p / 2), all = (half * 1ll * half) % MOD;
  if (p % 2 == 0)
    return all;
  return (all * 1ll * st) % MOD;
}
int c(int i, int j) {
  int zn = (inv[j] * 1ll * inv[i - j]) % MOD;
  return (fact[i] * 1ll * zn) % MOD;
}
void mainp() {
  cin >> n >> a >> b >> k;
  fact[0] = 1;
  for (int i = 1; i <= n; i++)
    fact[i] = (fact[i - 1] * 1ll * i) % MOD;
  for (int i = 0; i <= n; i++)
    inv[i] = poww(fact[i], MOD - 2);

  for (int i = 0; i <= n; i++) {
    long long aa = i, bb = (k - aa * 1ll * a) / b;
    if (bb < 0 || aa * 1ll * a + bb * 1ll * b != k)
      continue;
    // cout<<aa<<" "<<bb<<endl;
    ans += c(n, aa) * 1ll * c(n, bb);
    ans %= MOD;
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  mainp();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#pragma optimize "O3"
#define endl '\n'
const int MAXN = 400017;
const int MOD = 998244353;
using namespace std;

int n, a, b, fact[MAXN], inv[MAXN];
long long ans, k;

int poww(int st, int p) {
  if (p == 0)
    return 1;
  int half = poww(st, p / 2), all = (half * 1ll * half) % MOD;
  if (p % 2 == 0)
    return all;
  return (all * 1ll * st) % MOD;
}
int c(int i, int j) {
  int zn = (inv[j] * 1ll * inv[i - j]) % MOD;
  return (fact[i] * 1ll * zn) % MOD;
}
void mainp() {
  cin >> n >> a >> b >> k;
  fact[0] = 1;
  for (int i = 1; i <= n; i++)
    fact[i] = (fact[i - 1] * 1ll * i) % MOD;
  for (int i = 0; i <= n; i++)
    inv[i] = poww(fact[i], MOD - 2);

  for (int i = 0; i <= n; i++) {
    long long aa = i, bb = (k - aa * 1ll * a) / b;
    if (bb < 0 || bb > n || aa * 1ll * a + bb * 1ll * b != k)
      continue;
    // cout<<aa<<" "<<bb<<endl;
    ans += c(n, aa) * 1ll * c(n, bb);
    ans %= MOD;
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  mainp();
  return 0;
}