prithivMLmods/Coder-Stat huggingface dataset:
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 RREP(i, n) for (int i = (n)-1; i >= 0; --i)
// #define int long long

vector<long long> binomial_coefficient(long long N) {
  const long long MOD = 998244353;
  vector<long long> fac;
  vector<long long> facIE;
  vector<long long> comb;
  for (int i = 0; i <= N; i++) {
    if (i == 0) {
      fac.push_back(1);
    } else {
      fac.push_back(i * fac[i - 1] % MOD);
    }
  }
  for (int i = 0; i <= N; i++) {
    long long r = 1, b = fac[i], e = MOD - 2;
    while (e) {
      if (e & 1) {
        r = (r * b) % MOD;
      }
      b = (b * b) % MOD;
      e >>= 1;
    }
    facIE.push_back(r);
  }
  for (int i = 0; i <= N; i++) {
    long long r = fac[N];
    r = (r * facIE[i]) % MOD;
    r = (r * facIE[N - i]) % MOD;
    comb.push_back(r);
  }
  return comb;
}

signed main(void) {
  long long N, A, B, K;
  cin >> N >> A >> B >> K;
  vector<long long> nC;
  nC = binomial_coefficient(N);

  const long long MOD = 998244353;
  long long Ans = 0;

  // REP(i,N+1){cout << nC[i] << " ";}cout << endl;

  REP(i, N + 1) {
    long long b = K - A * i;
    if (b > 0 && b % B == 0) {
      b /= B;
      Ans += nC[i] * nC[b];
      Ans %= MOD;
    }
  }
  cout << Ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
// #define int long long

vector<long long> binomial_coefficient(long long N) {
  const long long MOD = 998244353;
  vector<long long> fac;
  vector<long long> facIE;
  vector<long long> comb;
  for (int i = 0; i <= N; i++) {
    if (i == 0) {
      fac.push_back(1);
    } else {
      fac.push_back(i * fac[i - 1] % MOD);
    }
  }
  for (int i = 0; i <= N; i++) {
    long long r = 1, b = fac[i], e = MOD - 2;
    while (e) {
      if (e & 1) {
        r = (r * b) % MOD;
      }
      b = (b * b) % MOD;
      e >>= 1;
    }
    facIE.push_back(r);
  }
  for (int i = 0; i <= N; i++) {
    long long r = fac[N];
    r = (r * facIE[i]) % MOD;
    r = (r * facIE[N - i]) % MOD;
    comb.push_back(r);
  }
  return comb;
}

signed main(void) {
  long long N, A, B, K;
  cin >> N >> A >> B >> K;
  vector<long long> nC;
  nC = binomial_coefficient(N);

  const long long MOD = 998244353;
  long long Ans = 0;

  // REP(i,N+1){cout << nC[i] << " ";}cout << endl;

  REP(i, N + 1) {
    long long b = K - A * i;
    if (b >= 0 && b % B == 0 && b / B <= N) {
      b /= B;
      Ans += nC[i] * nC[b];
      Ans %= MOD;
    }
  }
  cout << Ans << endl;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNiINGS
#include <algorithm>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i, n) for (long long i = 0; i < n; ++i)
long long inv(long long a) {
  long long now = 1;
  long long cnt = MOD - 2;
  while (cnt != 0) {
    if (cnt % 2 == 1) {
      now *= a;
      now %= MOD;
    }
    a *= a;
    a %= MOD;
    cnt /= 2;
  }
  return now;
}
long long geko[200000] = {};
int main() {
#define int long long
  long long n, a, b, k;
  cin >> n >> a >> b >> k;
  geko[0] = 1;
  for (int i = 1; i <= n; ++i) {
    geko[i] = geko[i - 1] * inv(i);
    geko[i] %= MOD;
    geko[i] *= (n - (long long)i + 1LL);
    geko[i] %= MOD;
  }
  long long ans = 0;
  for (long long i = 0; i <= n; ++i) {
    long long remaining = k - a * i;
    if (remaining < 0)
      break;
    if (remaining % b == 0) {
      long long go = remaining / b;
      if (go <= n) {
        long long tmp = geko[i] * geko[go];
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNiINGS
#include <algorithm>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i, n) for (long long i = 0; i < n; ++i)
long long inv(long long a) {
  long long now = 1;
  long long cnt = MOD - 2;
  while (cnt != 0) {
    if (cnt % 2 == 1) {
      now *= a;
      now %= MOD;
    }
    a *= a;
    a %= MOD;
    cnt /= 2;
  }
  return now;
}
long long geko[500000] = {};
int main() {
#define int long long
  long long n, a, b, k;
  cin >> n >> a >> b >> k;
  geko[0] = 1;
  for (int i = 1; i <= n; ++i) {
    geko[i] = geko[i - 1] * inv(i);
    geko[i] %= MOD;
    geko[i] *= (n - (long long)i + 1LL);
    geko[i] %= MOD;
  }
  long long ans = 0;
  for (long long i = 0; i <= n; ++i) {
    long long remaining = k - a * i;
    if (remaining < 0)
      break;
    if (remaining % b == 0) {
      long long go = remaining / b;
      if (go <= n) {
        long long tmp = geko[i] * geko[go];
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03332 (C++)

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

using namespace std;

#define MP make_pair
#define PB push_back
#define INF (1000000007)
#define eps 1e-9
#define MOD (998244353)
#define IOS ios::sync_with_stdio(false)

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef long long ll;

ll n, a, b, k;
ll inv[300005], fooq[300005];

ll Pow(int x, int p) {
  if (p == 1)
    return x;
  if (p == 0)
    return 1;
  ll ret = Pow(x, p >> 1);
  if (p & 1)
    return ((ret * ret % MOD) * (ll)x) % MOD;
  return (ret * ret) % MOD;
}

inline ll C(int x, int y) {
  if (y == 0)
    return 1;
  if (y > x)
    return 0;
  return ((fooq[x] * inv[y] % MOD) * inv[x - y]) % MOD;
}

int main() {
  cin >> n >> a >> b >> k;
  fooq[1] = 1;
  fooq[0] = inv[0] = 1;
  for (int i = 2; i <= 300000; i++)
    fooq[i] = (fooq[i - 1] * i) % MOD;
  inv[300000] = Pow(fooq[300000], MOD - 2);
  for (int i = 299999; i >= 1; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % MOD;
  ll ans = 0ll;
  for (int i = 0; i <= n; i++) {
    ll sa = a * (ll)i;
    if ((k - sa) % b)
      continue;
    ll B = (k - sa) / b;
    ans += (C(n, i) * C(n, B)) % MOD;
    if (ans >= MOD)
      ans -= MOD;
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define MP make_pair
#define PB push_back
#define INF (1000000007)
#define eps 1e-9
#define MOD (998244353)
#define IOS ios::sync_with_stdio(false)

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef long long ll;

ll n, a, b, k;
ll inv[300005], fooq[300005];

ll Pow(int x, int p) {
  if (p == 1)
    return x;
  if (p == 0)
    return 1;
  ll ret = Pow(x, p >> 1);
  if (p & 1)
    return ((ret * ret % MOD) * (ll)x) % MOD;
  return (ret * ret) % MOD;
}

inline ll C(int x, int y) {
  if (y == 0)
    return 1;
  if (y > x)
    return 0;
  return ((fooq[x] * inv[y] % MOD) * inv[x - y]) % MOD;
}

int main() {
  cin >> n >> a >> b >> k;
  fooq[1] = 1;
  fooq[0] = inv[0] = 1;
  for (int i = 2; i <= 300000; i++)
    fooq[i] = (fooq[i - 1] * i) % MOD;
  inv[300000] = Pow(fooq[300000], MOD - 2);
  for (int i = 299999; i >= 1; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % MOD;
  ll ans = 0ll;
  for (int i = 0; i <= n; i++) {
    ll sa = a * (ll)i;
    if ((k - sa) % b || sa > k)
      continue;
    ll B = (k - sa) / b;
    ans += (C(n, i) * C(n, B)) % MOD;
    if (ans >= MOD)
      ans -= MOD;
  }
  cout << ans;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iostream>
#include <random>
#include <string>

using namespace std;

typedef long long ll;

const ll mod = 998244353;

ll Pow(ll x, ll n) {
  ll result = 1;
  while (n > 0) {
    if (n % 2) {
      n--;
      result *= x;
      result %= mod;
    } else {
      n /= 2;
      x *= x;
      x %= mod;
    }
  }
  return result;
}

ll Inv(ll x) { return Pow(x, mod - 2); }

const int maxn = 100 * 1000 + 2;
ll fact[maxn];

ll C(int n, int k) {
  ll result = fact[n];
  result = result * Inv(fact[k]) % mod;
  result = result * Inv(fact[n - k]) % mod;
  return result;
}

int main() {
  ll n, A, B, k;
  cin >> n >> A >> B >> k;

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

  ll result = 0;
  for (ll x = 0; x <= n; ++x) {
    if (k - x * A < 0)
      continue;
    if ((k - x * A) % B != 0)
      continue;
    ll y = (k - x * A) / B;
    if (y > n)
      continue;

    result += C(n, x) * C(n, y);
    result %= mod;
  }
  cout << result << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iostream>
#include <random>
#include <string>

using namespace std;

typedef long long ll;

const ll mod = 998244353;

ll Pow(ll x, ll n) {
  ll result = 1;
  while (n > 0) {
    if (n % 2) {
      n--;
      result *= x;
      result %= mod;
    } else {
      n /= 2;
      x *= x;
      x %= mod;
    }
  }
  return result;
}

ll Inv(ll x) { return Pow(x, mod - 2); }

const int maxn = 3 * 100 * 1000 + 2;
ll fact[maxn];

ll C(int n, int k) {
  ll result = fact[n];
  result = result * Inv(fact[k]) % mod;
  result = result * Inv(fact[n - k]) % mod;
  return result;
}

int main() {
  ll n, A, B, k;
  cin >> n >> A >> B >> k;

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

  ll result = 0;
  for (ll x = 0; x <= n; ++x) {
    if (k - x * A < 0)
      continue;
    if ((k - x * A) % B != 0)
      continue;
    ll y = (k - x * A) / B;
    if (y > n)
      continue;

    result += C(n, x) * C(n, y);
    result %= mod;
  }
  cout << result << endl;

  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 300010
ll mypow(ll x, ll y, ll p) {
  ll ret = 1;
  while (y) {
    if (y & 1)
      ret = (ret * x) % p;
    x = (x * x) % p;
    y /= 2;
  }
  return ret;
}
ll inv(ll x, ll p) {
  if (!x)
    return 1;
  return mypow(x, p - 2, p);
}
const ll mod = 998244353;
ll N, A, B, K, ans, fact[MAX], invv[MAX];

int main() {
  scanf("%lld %lld %lld %lld", &N, &A, &B, &K);
  fact[0] = fact[1] = 1;
  for (int i = 1; i <= N; i++)
    fact[i] = (fact[i - 1] * i) % mod;
  invv[0] = 1;
  for (int i = 1; i <= N; i++)
    invv[i] = inv(fact[i], mod);
  for (int i = 0; i <= N; i++) {
    if (K - A * i < 0 || (K - A * i) % B != 0)
      continue;
    ll X = i, Y = (K - A * i) / B;
    ll c1 = (fact[N] * invv[X] * invv[N - X]) % mod;
    ll c2 = (fact[N] * invv[Y] * invv[N - Y]) % mod;
    ans = (ans + (c1 * c2) % mod) % mod;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 300010
ll mypow(ll x, ll y, ll p) {
  ll ret = 1;
  while (y) {
    if (y & 1)
      ret = (ret * x) % p;
    x = (x * x) % p;
    y /= 2;
  }
  return ret;
}
ll inv(ll x, ll p) {
  if (!x)
    return 1;
  return mypow(x, p - 2, p);
}
const ll mod = 998244353;
ll N, A, B, K, ans, fact[MAX], invv[MAX];

int main() {
  scanf("%lld %lld %lld %lld", &N, &A, &B, &K);
  fact[0] = fact[1] = 1;
  for (int i = 1; i <= N; i++)
    fact[i] = (fact[i - 1] * i) % mod;
  invv[0] = 1;
  for (int i = 1; i <= N; i++)
    invv[i] = inv(fact[i], mod);
  for (int i = 0; i <= N; i++) {
    if (K - A * i < 0 || (K - A * i) % B != 0)
      continue;
    ll X = i, Y = (K - A * i) / B;
    if (X > N || Y > N)
      continue;
    ll c1 = (((fact[N] * invv[X]) % mod) * invv[N - X]) % mod;
    ll c2 = (((fact[N] * invv[Y]) % mod) * invv[N - Y]) % mod;
    ans = (ans + (c1 * c2) % mod) % mod;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
long long n, a, b, k, fac[400000], r, s, e[400000];
long long p = 998244353;
long long binp(long long h, long long j) {
  if (j == 0)
    return 1;
  if (j % 2 == 1)
    return ((binp(h, j - 1)) % p * h) % p;
  else {
    long long u = binp(h, j / 2) % p;
    return (u * u) % p;
  }
}
long long C(long long h, long long j) {
  if (h < j)
    return 0;
  if (j == 0 || j == h)
    return 1;
  long long c = h - j;
  c = fac[c];
  h = fac[h];
  j = fac[j];
  j = binp(j, p - 2);
  c = binp(c, p - 2);
  return (((h * j) % p) * c) % p;
}
int main() {
  cin >> n >> a >> b >> k;
  if (a > b)
    swap(a, b);
  if (n * (a + b) < k) {
    cout << 0 << endl;
    return 0;
  }
  fac[0] = 1;
  for (long long i = 1; i <= n; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= p;
  }
  for (long long i = 0; i <= n / 2; i++) {
    e[i] = C(n, i);
    e[n - i] = e[i];
  }
  r = 0;
  for (long long i = 0; r <= k; i++) {
    if ((k - r) % a == 0) {
      long long y = i;
      long long x = (k - r) / a;
      s += (e[x] * e[y]) % p;
    }
    r += b;
  }
  cout << (s + p) % p << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
long long n, a, b, k, fac[400000], r, s, e[400000];
long long p = 998244353;
long long binp(long long h, long long j) {
  if (j == 0)
    return 1;
  if (j % 2 == 1)
    return ((binp(h, j - 1)) % p * h) % p;
  else {
    long long u = binp(h, j / 2) % p;
    return (u * u) % p;
  }
}
long long C(long long h, long long j) {
  if (h < j)
    return 0;
  if (j == 0 || j == h)
    return 1;
  long long c = h - j;
  c = fac[c];
  h = fac[h];
  j = fac[j];
  j = binp(j, p - 2);
  c = binp(c, p - 2);
  return (((h * j) % p) * c) % p;
}
int main() {
  cin >> n >> a >> b >> k;
  if (a > b)
    swap(a, b);
  if (n * (a + b) < k) {
    cout << 0 << endl;
    return 0;
  }
  fac[0] = 1;
  for (long long i = 1; i <= n; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= p;
  }
  for (long long i = 0; i <= n / 2; i++) {
    e[i] = C(n, i);
    e[n - i] = e[i];
  }
  r = 0;
  for (long long i = 0; r <= k; i++) {
    if ((k - r) % a == 0) {
      long long y = i;
      long long x = (k - r) / a;
      if (x <= n && y <= n)
        s += (e[x] * e[y]) % p;
      s %= p;
    }
    r += b;
  }
  cout << (s + p) % p << endl;
  return 0;
}
Problem p03332 (C++)

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<ll, ll>
using namespace std;

const ll maxn = 1e5 + 500;
const ll inf = 1e17 + 7;
const ll mod = 998244353;

ll fac[maxn];
ll rfac[maxn];
ll ent(ll n, ll k) {
  if (k > n || k < 0) {
    return 0;
  }
  return (((fac[n] * rfac[k]) % mod) * rfac[n - k]) % mod;
}
ll poww(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1) {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b = (b / 2);
  }
  return ans;
}
int main() {
  fac[0] = 1;
  rfac[0] = 1;
  for (ll i = 1; i < maxn; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
    rfac[i] = poww(fac[i], mod - 2);
  }
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    ll kk = k - a * i;
    if (kk >= 0 && kk % b == 0) {
      ll j = kk / b;
      ans += (ent(n, i) * ent(n, j)) % mod;
      ans %= mod;
    }
  }
  cout << ans;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<ll, ll>
using namespace std;

const ll maxn = 4e5 + 500;
const ll inf = 1e17 + 7;
const ll mod = 998244353;

ll fac[maxn];
ll rfac[maxn];
ll ent(ll n, ll k) {
  if (k > n || k < 0) {
    return 0;
  }
  return (((fac[n] * rfac[k]) % mod) * rfac[n - k]) % mod;
}
ll poww(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1) {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b = (b / 2);
  }
  return ans;
}
int main() {
  fac[0] = 1;
  rfac[0] = 1;
  for (ll i = 1; i < maxn; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
    rfac[i] = poww(fac[i], mod - 2);
  }
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    ll kk = k - a * i;
    if (kk >= 0 && kk % b == 0) {
      ll j = kk / b;
      ans += (ent(n, i) * ent(n, j)) % mod;
      ans %= mod;
    }
  }
  cout << ans;
}
Problem p03332 (C++)

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

using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
const ll MOD = 998244353LL;
ll add(ll &a, ll b) { return a = (a + b) % MOD; }
ll mul(ll &a, ll b) { return a = (a * b) % MOD; }

const int SIZE = 300000 + 10;

ll fact[SIZE];

ll inv(ll a, ll p) {
  return (a == 1LL ? 1LL : (1LL - p * inv(p % a, a)) / a + p);
}

ll solve(ll N, ll A, ll B, ll K) {
  ll ans = 0;
  for (ll a = 0; a <= N; a++) {
    if (a * A > K)
      break;
    ll b = (K - (a * A)) / B;
    if (a * A + b * B != K)
      continue;
    ll tmp = 1LL;
    mul(tmp, fact[N]);
    mul(tmp, inv(fact[a], MOD));
    mul(tmp, inv(fact[N - a], MOD));
    mul(tmp, fact[N]);
    mul(tmp, inv(fact[b], MOD));
    mul(tmp, inv(fact[N - b], MOD));
    add(ans, tmp);
  }
  return ans;
}

int main() {
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i < SIZE; i++) {
    fact[i] = (ll)i;
    mul(fact[i], fact[i - 1]);
    //    cout << i << " " << fact[i] << endl;                                         \

  }
  ll N;
  ll A, B;
  ll K;
  cin >> N >> A >> B >> K;
  if (A > B)
    swap(A, B);
  ll ans = solve(N, A, B, K);
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
const ll MOD = 998244353LL;
ll add(ll &a, ll b) { return a = (a + b) % MOD; }
ll mul(ll &a, ll b) { return a = (a * b) % MOD; }

const int SIZE = 300000 + 10;

ll fact[SIZE];

ll inv(ll a, ll p) {
  return (a == 1LL ? 1LL : (1LL - p * inv(p % a, a)) / a + p);
}

ll solve(ll N, ll A, ll B, ll K) {
  ll ans = 0;
  for (ll a = 0; a <= N; a++) {
    if (a * A > K)
      break;
    ll b = (K - (a * A)) / B;
    if (a * A + b * B != K)
      continue;
    if (b > N)
      continue;
    ll tmp = 1LL;
    mul(tmp, fact[N]);
    mul(tmp, inv(fact[a], MOD));
    mul(tmp, inv(fact[N - a], MOD));
    mul(tmp, fact[N]);
    mul(tmp, inv(fact[b], MOD));
    mul(tmp, inv(fact[N - b], MOD));
    add(ans, tmp);
  }
  return ans;
}

int main() {
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i < SIZE; i++) {
    fact[i] = (ll)i;
    mul(fact[i], fact[i - 1]);
    //    cout << i << " " << fact[i] << endl;                                         \

  }
  ll N;
  ll A, B;
  ll K;
  cin >> N >> A >> B >> K;
  if (A > B)
    swap(A, B);
  ll ans = solve(N, A, B, K);
  cout << ans << endl;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
const LL mod = 998244353;
const int N = 3e5 + 3;
LL p[N], inv[N];
inline LL quick(LL a, LL b) {
  LL res = 1;
  while (b) {
    if (b & 1)
      res = res * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return res;
}
inline LL C(LL n, LL m) { return p[n] * inv[m] % mod * inv[n - m] % mod; }
inline LL mo(LL X) {
  if (X >= mod)
    X -= mod;
  return X;
}
int main() {
  p[0] = 1;
  p[1] = 1;
  inv[0] = 1;
  inv[1] = 1;
  for (int i = 2; i <= 300000; ++i) {
    p[i] = p[i - 1] * i % mod;
    inv[i] = quick(p[i], mod - 2);
  }
  LL n, a, b, k;
  LL ans = 0;
  std::cin >> n >> a >> b >> k;
  for (int i = 0; i <= n; ++i) {
    LL t = k - a * i;
    if (t % b != 0)
      continue;
    LL g = t / b;
    if (g > n)
      continue;
    ans = mo(ans + C(n, i) * C(n, g) % mod);
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
const LL mod = 998244353;
const int N = 3e5 + 3;
LL p[N], inv[N];
inline LL quick(LL a, LL b) {
  LL res = 1;
  while (b) {
    if (b & 1)
      res = res * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return res;
}
inline LL C(LL n, LL m) { return p[n] * inv[m] % mod * inv[n - m] % mod; }
inline LL mo(LL X) {
  if (X >= mod)
    X -= mod;
  return X;
}
int main() {
  p[0] = 1;
  p[1] = 1;
  inv[0] = 1;
  inv[1] = 1;
  for (int i = 2; i <= 300000; ++i) {
    p[i] = p[i - 1] * i % mod;
    inv[i] = quick(p[i], mod - 2);
  }
  LL n, a, b, k;
  LL ans = 0;
  std::cin >> n >> a >> b >> k;
  for (int i = 0; i <= n; ++i) {
    LL t = k - a * i;
    if (t < 0 || t % b != 0)
      continue;
    LL g = t / b;
    if (g > n)
      continue;
    ans = mo(ans + C(n, i) * C(n, g) % mod);
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03332 (C++)

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

typedef long long ll;

ll n, a, b, k, jwb = 0, tmp;
const ll MOD = 998244353;
ll f[300010];

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

ll inv(ll n) { return fastpow(n, MOD - 2); }

ll C(ll n, ll r) { return (f[n] * ((inv(f[r]) * inv(f[n - r])) % MOD)) % MOD; }

int main() {
  cin >> n >> a >> b >> k;
  f[0] = 1;
  for (ll i = 1; i <= 300000; ++i) {
    f[i] = (f[i - 1] * i) % MOD;
  }
  for (ll i = 0; i <= n; ++i) {
    if (k - i * a < 0)
      break;
    if ((k - i * a) % b == 0) {
      ll j = (k - i * a) / b;
      tmp = (C(n, i) * C(n, j)) % MOD;
      jwb = (jwb + tmp) % MOD;
    }
  }
  cout << jwb << endl;
  return 0;
}

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

typedef long long ll;

ll n, a, b, k, jwb = 0, tmp;
const ll MOD = 998244353;
ll f[300010];

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

ll inv(ll n) { return fastpow(n, MOD - 2); }

ll C(ll n, ll r) { return (f[n] * ((inv(f[r]) * inv(f[n - r])) % MOD)) % MOD; }

int main() {
  cin >> n >> a >> b >> k;
  f[0] = 1;
  for (ll i = 1; i <= 300000; ++i) {
    f[i] = (f[i - 1] * i) % MOD;
  }
  for (ll i = 0; i <= n; ++i) {
    if (k - i * a < 0)
      break;
    if ((k - i * a) % b == 0) {
      ll j = (k - i * a) / b;
      if (j > n)
        continue;
      tmp = (C(n, i) * C(n, j)) % MOD;
      jwb = (jwb + tmp) % MOD;
    }
  }
  cout << jwb << endl;
  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 int long long
const long long mod = 998244353;
const int maxN = 300001;
int kj[300005], kji[300005];

void setkj() {
  kj[0] = 1;
  kji[0] = kji[1] = 1;
  for (int i = 1; i <= maxN; i++)
    kj[i] = kj[i - 1] * i % mod;
  for (int i = 2; i <= maxN; i++)
    kji[i] = mod - (kji[mod % i] * (mod / i)) % mod;
  for (int i = 2; i <= maxN; i++)
    kji[i] = kji[i] * kji[i - 1] % mod;
}
int comb(int r, int c) { return kj[r] * kji[c] % mod * kji[r - c] % mod; }

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

  for (int i = 0; i <= n; i++) {
    int j = k - a * i;
    if (j >= 0 && j % b == 0) {
      ans += comb(n, i) * comb(n, j / b) % mod;
      ans %= mod;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define int long long
const long long mod = 998244353;
const int maxN = 300001;
int kj[300005], kji[300005];

void setkj() {
  kj[0] = 1;
  kji[0] = kji[1] = 1;
  for (int i = 1; i <= maxN; i++)
    kj[i] = kj[i - 1] * i % mod;
  for (int i = 2; i <= maxN; i++)
    kji[i] = mod - (kji[mod % i] * (mod / i)) % mod;
  for (int i = 2; i <= maxN; i++)
    kji[i] = kji[i] * kji[i - 1] % mod;
}
int comb(int r, int c) {
  if (r < c)
    return 0;
  return kj[r] * kji[c] % mod * kji[r - c] % mod;
}

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

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

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

using namespace std;

const int MAXN = 1e5 * 3 + 5;
const int mod = 998244353;

long long fakt[MAXN];

int n;
long long a, b, k;
long long sol = 0;

int mul(int a, int b) { return ((long long)a * b) % mod; }
int add(int a, int b) {
  a += b;
  if (a >= mod)
    return a - mod;
  return a;
}
int pow(int baza, int potencija) {
  int r = 1, a = baza, x = potencija;
  while (x) {
    if (x % 2 == 1) {
      r = mul(r, a);
    }
    a = mul(a, a);
    x /= 2;
  }
  return r;
}
int divi(int a, int b) { return mul(a, pow(b, mod - 2)); }

int main() {
  fakt[0] = 1;
  for (int i = 1; i < MAXN - 2; i++) {
    fakt[i] = mul(fakt[i - 1], i);
  }
  cin >> n >> a >> b >> k;
  for (int i = 0; i <= n; i++) {
    long long A = a * i;
    if ((k - A) % b == 0) {
      // cout << "PROV: " <<A << " " << B;
      int j = (k - A) / b;
      if (j <= n)
        sol = add(sol, mul(divi(fakt[n], mul(fakt[i], fakt[n - i])),
                           divi(fakt[n], mul(fakt[j], fakt[n - j]))));
    } else {
      continue;
    }
  }
  cout << sol;

  return 0;
}


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

using namespace std;

const int MAXN = 1e5 * 3 + 5;
const int mod = 998244353;

long long fakt[MAXN];

int n;
long long a, b, k;
long long sol = 0;

int mul(int a, int b) { return ((long long)a * b) % mod; }
int add(int a, int b) {
  a += b;
  if (a >= mod)
    return a - mod;
  return a;
}
int pow(int baza, int potencija) {
  int r = 1, a = baza, x = potencija;
  while (x) {
    if (x % 2 == 1) {
      r = mul(r, a);
    }
    a = mul(a, a);
    x /= 2;
  }
  return r;
}
int divi(int a, int b) { return mul(a, pow(b, mod - 2)); }

int main() {
  fakt[0] = 1;
  for (int i = 1; i < MAXN - 2; i++) {
    fakt[i] = mul(fakt[i - 1], i);
  }
  cin >> n >> a >> b >> k;
  for (int i = 0; i <= n; i++) {
    long long A = a * i;
    if (A > k)
      break;
    if ((k - A) % b == 0) {
      // cout << "PROV: " <<A << " " << B;
      int j = (k - A) / b;
      if (j <= n)
        sol = add(sol, mul(divi(fakt[n], mul(fakt[i], fakt[n - i])),
                           divi(fakt[n], mul(fakt[j], fakt[n - j]))));
    } else {
      continue;
    }
  }
  cout << sol;

  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 998244353;
// const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

const long long table_size = 100005;
long long fact[table_size], finv[table_size], inv[table_size];

// 前処理
void make_table(long long mod) {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < table_size; i++) {
    fact[i] = fact[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

// nCr
long long nCr(long long n, long long r, long long mod) {
  return fact[n] * (finv[r] * finv[n - r] % mod) % mod;
}

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

  make_table(MOD);

  ll ans = 0;
  REP(i, n + 1) {
    ll t = k - i * a;
    if (t < 0 || t > n * b || t % b != 0)
      continue;
    ll tt = t / b;
    ans += nCr(n, i, MOD) * nCr(n, tt, MOD) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 998244353;
// const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

const long long table_size = 300005;
long long fact[table_size], finv[table_size], inv[table_size];

// 前処理
void make_table(long long mod) {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < table_size; i++) {
    fact[i] = fact[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

// nCr
long long nCr(long long n, long long r, long long mod) {
  return fact[n] * (finv[r] * finv[n - r] % mod) % mod;
}

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

  make_table(MOD);

  ll ans = 0;
  REP(i, n + 1) {
    ll t = k - i * a;
    if (t < 0 || t > n * b || t % b != 0)
      continue;
    ll tt = t / b;
    ans += nCr(n, i, MOD) * nCr(n, tt, MOD) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 998244353 /*1e9 + 7 */;

#define REP(i, n) for (ll i = 0; i < n; i++)

const long long table_size = 1e5 + 5;
long long fact[table_size], inverse[table_size];

// 高速に n^m (mod p) を求める
long long POW(long long n, long long m, long long p) {
  if (m == 0) {
    return 1;
  }
  if (m % 2 == 0) {
    long long tmp = POW(n, m / 2, p) % p;
    return tmp * tmp % p;
  } else {
    return n * POW(n, m - 1, p) % p;
  }
}

// 階乗を生成    e.g. 5! == fact[5]
void make_table(long long n, long long p) {
  fact[0] = 1;
  inverse[0] = 1;
  for (long long i = 1; i <= n; i++) {
    fact[i] = (fact[i - 1] * i) % p;
    inverse[i] = POW(fact[i], p - 2, p) % p;
  }
}

// nCr
long long nCr(long long n, long long r, long long p) {
  return fact[n] * inverse[r] % p * inverse[n - r] % p;
}

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

  make_table(n + 1, MOD);

  ll ans = 0;
  REP(i, n + 1) {
    ll t = k - i * a;
    if (t < 0 || t > n * b || t % b != 0)
      continue;
    ll tt = t / b;
    ans += nCr(n, i, MOD) * nCr(n, tt, MOD) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 998244353 /*1e9 + 7 */;

#define REP(i, n) for (ll i = 0; i < n; i++)

const long long table_size = 3e5 + 5;
long long fact[table_size], inverse[table_size];

// 高速に n^m (mod p) を求める
long long POW(long long n, long long m, long long p) {
  if (m == 0) {
    return 1;
  }
  if (m % 2 == 0) {
    long long tmp = POW(n, m / 2, p) % p;
    return tmp * tmp % p;
  } else {
    return n * POW(n, m - 1, p) % p;
  }
}

// 階乗を生成    e.g. 5! == fact[5]
void make_table(long long n, long long p) {
  fact[0] = 1;
  inverse[0] = 1;
  for (long long i = 1; i <= n; i++) {
    fact[i] = (fact[i - 1] * i) % p;
    inverse[i] = POW(fact[i], p - 2, p) % p;
  }
}

// nCr
long long nCr(long long n, long long r, long long p) {
  return fact[n] * inverse[r] % p * inverse[n - r] % p;
}

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

  make_table(n + 1, MOD);

  ll ans = 0;
  REP(i, n + 1) {
    ll t = k - i * a;
    if (t < 0 || t > n * b || t % b != 0)
      continue;
    ll tt = t / b;
    ans += nCr(n, i, MOD) * nCr(n, tt, MOD) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll mod = 998244353;
//---------------------------------------------------------------------------------------------------
ll f[301010], rf[301010];
ll inv(ll x) {
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while (k) {
    if (k & 1)
      res = (res * y) % mod;
    y = (y * y) % mod;
    k /= 2;
  }
  return res;
}
void init() {
  f[0] = 1;
  rep(i, 1, 301010) f[i] = (f[i - 1] * i) % mod;
  rep(i, 0, 301010) rf[i] = inv(f[i]);
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
  ll a = f[n];      // = n!
  ll b = rf[n - k]; // = (n-k)!
  ll c = rf[k];     // = k!

  ll bc = (b * c) % mod;

  return (a * bc) % mod;
}

int main() {
  init();
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  for (ll i = 0; i < n + 1; i++) {
    if ((k - a * i) % b == 0) {
      ll t = (k - a * i) / b;
      if (t > n)
        continue;
      ans += C(n, i) * C(n, t);
      ans %= mod;
    }
  }
  cout << ans % mod << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll mod = 998244353;
//---------------------------------------------------------------------------------------------------
ll f[301010], rf[301010];
ll inv(ll x) {
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while (k) {
    if (k & 1)
      res = (res * y) % mod;
    y = (y * y) % mod;
    k /= 2;
  }
  return res;
}
void init() {
  f[0] = 1;
  rep(i, 1, 301010) f[i] = (f[i - 1] * i) % mod;
  rep(i, 0, 301010) rf[i] = inv(f[i]);
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
  ll a = f[n];      // = n!
  ll b = rf[n - k]; // = (n-k)!
  ll c = rf[k];     // = k!

  ll bc = (b * c) % mod;

  return (a * bc) % mod;
}

int main() {
  init();
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  for (ll i = 0; i < n + 1; i++) {
    if (a * i > k)
      break;
    if ((k - a * i) % b == 0) {
      ll t = (k - a * i) / b;
      if (t > n)
        continue;
      ans += C(n, i) * C(n, t);
      ans %= mod;
    }
  }
  cout << ans % mod << endl;
}
Problem p03332 (C++)

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

int n, a, b;
int fact[300005];
long long k;
const int MOD = 998244353;
inline int invmod(int x) {
  int p = MOD - 2, aux = x, ans = 1;
  for (int i = 0; (1 << i) <= p; ++i) {
    if ((1 << i) & p)
      ans = (1LL * ans * aux) % MOD;
    aux = (1LL * aux * aux) % MOD;
  }
  return ans;
}
inline int comb(int n, int k) {
  int ans = fact[n];
  int c1 = invmod(fact[n - k]);
  int c2 = invmod(fact[k]);
  ans = (1LL * ans * c1) % MOD;
  ans = (1LL * ans * c2) % MOD;
  return ans;
}
int main() {
  scanf("%d%d%d%lld", &n, &a, &b, &k);
  fact[0] = fact[1] = 1;
  for (int i = 2; i <= n; ++i)
    fact[i] = (1LL * fact[i - 1] * i) % MOD;

  int Sol = 0;
  for (int t = 0; t <= n; ++t) {
    int i = t;
    long long k2 = k - 1LL * i * a;
    if (k2 % b)
      continue;
    long long j = k2 / b;
    if (j > n)
      continue;
    Sol = (Sol + (1LL * comb(n, i) * comb(n, j)) % MOD) % MOD;
  }
  printf("%d", Sol);
  return 0;
}


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

int n, a, b;
int fact[300005];
long long k;
const int MOD = 998244353;
inline int invmod(int x) {
  int p = MOD - 2, aux = x, ans = 1;
  for (int i = 0; (1 << i) <= p; ++i) {
    if ((1 << i) & p)
      ans = (1LL * ans * aux) % MOD;
    aux = (1LL * aux * aux) % MOD;
  }
  return ans;
}
inline int comb(int n, int k) {
  int ans = fact[n];
  int c1 = invmod(fact[n - k]);
  int c2 = invmod(fact[k]);
  ans = (1LL * ans * c1) % MOD;
  ans = (1LL * ans * c2) % MOD;
  return ans;
}
int main() {
  scanf("%d%d%d%lld", &n, &a, &b, &k);
  fact[0] = fact[1] = 1;
  for (int i = 2; i <= n; ++i)
    fact[i] = (1LL * fact[i - 1] * i) % MOD;

  int Sol = 0;
  for (int t = 0; t <= n; ++t) {
    int i = t;
    long long k2 = k - 1LL * i * a;
    if (k2 < 0)
      break;
    if (k2 % b)
      continue;
    long long j = k2 / b;
    if (j > n)
      continue;
    Sol = (Sol + (1LL * comb(n, i) * comb(n, j)) % MOD) % MOD;
  }
  printf("%d", Sol);
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int MAX = 100005;
const int MOD = 998244353;

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

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

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

int main() {
  // 前処理
  COMinit();
  // 計算例
  int n, a, b;
  ll k;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  rep(i, n + 1) {
    if ((k - a * i) % b == 0 && (k - a * i) / b <= n) {
      // cout << i << (k-a*i)/b << endl;
      ans += COM(n, i) * COM(n, (k - a * i) / b);
      ans %= 998244353;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int MAX = 300005;
const int MOD = 998244353;

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

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

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

int main() {
  // 前処理
  COMinit();
  // 計算例
  int n, a, b;
  ll k;
  cin >> n >> a >> b >> k;
  ll ans = 0;
  rep(i, n + 1) {
    if ((k - a * i) % b == 0 && (k - a * i) / b <= n) {
      // cout << i << (k-a*i)/b << endl;
      ans += COM(n, i) * COM(n, (k - a * i) / b);
      ans %= 998244353;
    }
  }
  cout << ans << endl;
}
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 pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;

template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

const int mod = 998244353;
inline void add(int &a, int b) {
  a += b;
  if (a >= mod)
    a -= mod;
}
int mpow(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1)
      ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}
const int FACTSIZE = 1111111;
int fact[FACTSIZE];
int factinv[FACTSIZE];
class FactInit {
public:
  FactInit() {
    fact[0] = 1;
    for (int i = 1; i < FACTSIZE; i++)
      fact[i] = fact[i - 1] * i % mod;
    factinv[FACTSIZE - 1] = mpow(fact[FACTSIZE - 1], mod - 2);
    for (int i = FACTSIZE - 2; i >= 0; i--)
      factinv[i] = factinv[i + 1] * (i + 1) % mod;
  }
} factInit;

int binomial(int n, int k) {
  return fact[n] * factinv[k] % mod * factinv[n - k] % mod;
}

signed main() {
  int N, A, B, K;
  cin >> N >> A >> B >> K;
  int ans = 0;
  for (int i = 0; i <= N; i++) {
    if (i * A > K || (K - i * A) % B || (K - i * A) % B > N)
      continue;
    add(ans, binomial(N, i) * binomial(N, (K - i * A) / B) % mod);
  }
  cout << ans << endl;
  return 0;
}

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 pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;

template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

const int mod = 998244353;
inline void add(int &a, int b) {
  a += b;
  if (a >= mod)
    a -= mod;
}
int mpow(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1)
      ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}
const int FACTSIZE = 1111111;
int fact[FACTSIZE];
int factinv[FACTSIZE];
class FactInit {
public:
  FactInit() {
    fact[0] = 1;
    for (int i = 1; i < FACTSIZE; i++)
      fact[i] = fact[i - 1] * i % mod;
    factinv[FACTSIZE - 1] = mpow(fact[FACTSIZE - 1], mod - 2);
    for (int i = FACTSIZE - 2; i >= 0; i--)
      factinv[i] = factinv[i + 1] * (i + 1) % mod;
  }
} factInit;

int binomial(int n, int k) {
  return fact[n] * factinv[k] % mod * factinv[n - k] % mod;
}

signed main() {
  int N, A, B, K;
  cin >> N >> A >> B >> K;
  int ans = 0;
  for (int i = 0; i <= N; i++) {
    if (i * A > K || (K - i * A) % B || (K - i * A) / B > N)
      continue;
    add(ans, binomial(N, i) * binomial(N, (K - i * A) / B) % mod);
  }
  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 pair<ll, ll> p_ll;

template <class T> void debug(T itr1, T itr2) {
  auto now = itr1;
  while (now < itr2) {
    cout << *now << " ";
    now++;
  }
  cout << endl;
}
#define repr(i, from, to) for (ll i = (ll)from; i < (ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i, N) repr(i, 0, N)
#define per(i, N) for (int i = (int)N - 1; i >= 0; i--)

const ll MOD = 998244353;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

vector<ll> fac;
void c_fac(int x = pow(10, 6) + 10) {
  fac.resize(x, true);
  rep(i, x) fac[i] = i ? (fac[i - 1] * i) % MOD : 1;
}
ll inv(ll a, ll m = MOD) {
  ll b = m, x = 1, y = 0;
  while (b != 0) {
    int d = a / b;
    a -= b * d;
    swap(a, b);
    x -= y * d;
    swap(x, y);
  }
  return (x + m) % m;
}
ll nck(ll n, ll k) { return fac[n] * inv(fac[k] * fac[n - k] % MOD) % MOD; }
ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

  c_fac();
  ll result = 0;
  rep(i, N + 1) {
    if (K - A * i < 0 || (K - A * i) % B)
      continue;
    ll j = (K - A * i) / B;
    result = (result + nck(N, i) * nck(N, j)) % MOD;
    // cout << i << " " << j << endl;
  }
  cout << result << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template <class T> void debug(T itr1, T itr2) {
  auto now = itr1;
  while (now < itr2) {
    cout << *now << " ";
    now++;
  }
  cout << endl;
}
#define repr(i, from, to) for (ll i = (ll)from; i < (ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i, N) repr(i, 0, N)
#define per(i, N) for (int i = (int)N - 1; i >= 0; i--)

const ll MOD = 998244353;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

vector<ll> fac;
void c_fac(int x = pow(10, 6) + 10) {
  fac.resize(x, true);
  rep(i, x) fac[i] = i ? (fac[i - 1] * i) % MOD : 1;
}
ll inv(ll a, ll m = MOD) {
  ll b = m, x = 1, y = 0;
  while (b != 0) {
    int d = a / b;
    a -= b * d;
    swap(a, b);
    x -= y * d;
    swap(x, y);
  }
  return (x + m) % m;
}
ll nck(ll n, ll k) { return fac[n] * inv(fac[k] * fac[n - k] % MOD) % MOD; }
ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

  c_fac();
  ll result = 0;
  rep(i, N + 1) {
    if (K - A * i < 0 || (K - A * i) % B || (K - A * i) / B > N)
      continue;
    ll j = (K - A * i) / B;
    result = (result + nck(N, i) * nck(N, j)) % MOD;
    // cout << i << " " << j << endl;
  }
  cout << result << endl;
  return 0;
}
Problem p03332 (C++)

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

#define MAX_N 300005
ll factorial[MAX_N];

void make_factorial_tableMOD() {
  factorial[0] = 1;
  for (int i = 1; i < MAX_N; i++) {
    factorial[i] = factorial[i - 1] * i % MOD;
  }
}

ll bisection_powerMOD(ll x, ll y) {
  if (y == 0) {
    return 1;
  }
  ll t = bisection_powerMOD(x * x % MOD, y / 2);
  if (y % 2 == 1) {
    t = t * x % MOD;
  }
  return t;
}

ll nCrMOD(int n, int r) {
  ll a = factorial[n];
  ll b = a * bisection_powerMOD(factorial[r], (MOD - 2)) % MOD;
  ll c = b * bisection_powerMOD(factorial[n - r], MOD - 2) % MOD;
  return c % MOD;
}

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

  for (int i = 0; i < n + 1; i++) {
    ll anum = (ll)i;
    ll r = k - anum * a;
    ll bnum = r / b;
    if (r % b == 0LL && bnum <= n) {
      ans += (nCrMOD(n, anum) * nCrMOD(n, bnum)) % MOD;
    }
  }

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


Fixed submission:
#include <bits/stdc++.h>
#define MOD 998244353LL
using namespace std;
typedef long long ll;

#define MAX_N 300005
ll factorial[MAX_N];

void make_factorial_tableMOD() {
  factorial[0] = 1;
  for (int i = 1; i < MAX_N; i++) {
    factorial[i] = factorial[i - 1] * i % MOD;
  }
}

ll bisection_powerMOD(ll x, ll y) {
  if (y == 0) {
    return 1;
  }
  ll t = bisection_powerMOD(x * x % MOD, y / 2);
  if (y % 2 == 1) {
    t = t * x % MOD;
  }
  return t;
}

ll nCrMOD(int n, int r) {
  ll a = factorial[n];
  ll b = a * bisection_powerMOD(factorial[r], (MOD - 2)) % MOD;
  ll c = b * bisection_powerMOD(factorial[n - r], MOD - 2) % MOD;
  return c % MOD;
}

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

  for (int i = 0; i < n + 1; i++) {
    ll anum = (ll)i;
    ll r = k - anum * a;
    ll bnum = r / b;
    if (bnum < 0) {
      continue;
    }
    if (r % b == 0LL && bnum <= n) {
      ans += (nCrMOD(n, anum) * nCrMOD(n, bnum)) % MOD;
    }
  }

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