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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define error(args...)                                                         \
  {                                                                            \
    string _s = #args;                                                         \
    replace(_s.begin(), _s.end(), ',', ' ');                                   \
    stringstream _ss(_s);                                                      \
    istream_iterator<string> _it(_ss);                                         \
    err(_it, args);                                                            \
  }

using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}

typedef long long ll;

ll sum(ll n) {
  ll s = 0;
  while (n) {
    s += n % 10;
    n /= 10;
  }
  return s;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll ans = 1e9, b, sm;
  cin >> sm;
  for (ll i = sm - 1; i >= 1; --i) {
    b = sm - i;
    // cout<<sum(i)<<" "<<sum(b)<<"\n";
    ans = min(ans, sum(i) + sum(b));
  }
  cout << ans << "\n";

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define error(args...)                                                         \
  {                                                                            \
    string _s = #args;                                                         \
    replace(_s.begin(), _s.end(), ',', ' ');                                   \
    stringstream _ss(_s);                                                      \
    istream_iterator<string> _it(_ss);                                         \
    err(_it, args);                                                            \
  }

using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}

typedef long long ll;

ll sum(ll n) {
  ll s = 0;
  while (n) {
    s += n % 10;
    n /= 10;
  }
  return s;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif

  ll ans = 1e9, b, sm;
  cin >> sm;
  for (ll i = sm - 1; i >= 1; --i) {
    b = sm - i;
    // cout<<sum(i)<<" "<<sum(b)<<"\n";
    ans = min(ans, sum(i) + sum(b));
  }
  cout << ans << "\n";

  return 0;
}
Problem p03331 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); (i)++)

int N;

int d(int i) {
  int ans = 0;
  while (i > 0) {
    ans += i % 10;
    ans /= 10;
  }
  return ans;
}

int main() {
  cin >> N;
  int ans = 1e9;
  rep(i, 1, N - 1) {
    int j = N - i;
    ans = min(ans, d(i) + d(j));
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); (i)++)

int N;

int d(int i) {
  int ans = 0;
  while (i > 0) {
    ans += i % 10;
    i /= 10;
  }
  return ans;
}

int main() {
  cin >> N;
  int ans = 1e9;
  rep(i, 1, N - 1) {
    int j = N - i;
    ans = min(ans, d(i) + d(j));
  }
  cout << ans << endl;
}
Problem p03332 (C++)

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

int qpow(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1)
      ret = ret * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return ret;
}

int fac[1000005];
int C(int n, int m) {
  if (n < m)
    return 0;
  return fac[n] * qpow(fac[m], MOD - 2) % MOD * qpow(fac[n - m], MOD - 2) % MOD;
}
int A, B, k, n;
signed main() {
  scanf("%lld%lld%lld%lld", &n, &A, &B, &k);
  fac[0] = 0;
  int ans = 0;
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % MOD;
  for (int i = 0; i <= n; i++) {
    int x = i;
    if ((k - A * i) % B != 0)
      continue;
    int y = (k - A * i) / B;
    ans = (ans + C(n, x) * C(n, y) % MOD) % MOD;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 998244353;

int qpow(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1)
      ret = ret * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return ret;
}

int fac[1000005];
int C(int n, int m) {
  if (n < m)
    return 0;
  return fac[n] * qpow(fac[m], MOD - 2) % MOD * qpow(fac[n - m], MOD - 2) % MOD;
}
int A, B, k, n;
signed main() {
  scanf("%lld%lld%lld%lld", &n, &A, &B, &k);
  fac[0] = 0;
  int ans = 0;
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % MOD;
  for (int i = 0; i <= n; i++) {
    int x = i;
    if ((k - A * i) % B != 0 || k < A * i)
      continue;
    int y = (k - A * i) / B;
    ans = (ans + C(n, x) * C(n, y) % MOD) % MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int MOD = 998244353;
long long jc[N];
long long qpow(long long x, long long k) {
  long long r = 1;
  while (k) {
    if (k & 1)
      r = r * x % MOD;
    k >>= 1;
    x = x * x % MOD;
  }
  return r;
}
long long inv(long long x) { return qpow(x, MOD - 2); }
long long C(long long x, long long y) {
  return jc[x] * inv(jc[y]) % MOD * inv(jc[x - y]) % MOD;
}
int main() {
  jc[0] = jc[1] = 1;
  for (int i = 2; i < N; i++) {
    jc[i] = jc[i - 1] * i % MOD;
  }
  long long n, a, b, k, ans = 0;
  cin >> n >> a >> b >> k;
  for (long long i = 0; i <= n; i++) {
    if ((k - a * i) % b == 0) {
      long long x = i, y = (k - a * i) / b;
      if (x <= n && y <= n && y >= 0)
        ans = (ans + C(n, x) * C(n, y)) % MOD;
    }
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int MOD = 998244353;
long long jc[N];
long long qpow(long long x, long long k) {
  long long r = 1;
  while (k) {
    if (k & 1)
      r = r * x % MOD;
    k >>= 1;
    x = x * x % MOD;
  }
  return r;
}
long long inv(long long x) { return qpow(x, MOD - 2); }
long long C(long long x, long long y) {
  return jc[x] * inv(jc[y]) % MOD * inv(jc[x - y]) % MOD;
}
int main() {
  jc[0] = jc[1] = 1;
  for (int i = 2; i < N; i++) {
    jc[i] = jc[i - 1] * i % MOD;
  }
  long long n, a, b, k, ans = 0;
  cin >> n >> a >> b >> k;
  for (long long i = 0; i <= n; i++) {
    if ((k - a * i) % b == 0) {
      long long x = i, y = (k - a * i) / b;
      if (x <= n && y <= n && y >= 0)
        ans = (ans + C(n, x) * C(n, y)) % MOD;
    }
  }
  cout << ans;
  return 0;
}
Problem p03332 (C++)

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

long long ta[99999];

int main() {
  int n;
  int a;
  int b;
  long long k;
  std::cin >> n >> a >> b >> k;
  //  n = 4; a = 2; b = 1; k = 5;
  // printf("%d\t%d\t%d\t%lld\n", n, a, b, k);
  // system("pause");
  ta[0] = 1;
  long long q = 1;
  int m = (n + 1) / 2;
  long long answer = 0;

  for (int i = 1; i < m + 1; i++) {
    q = (q * (n - i + 1)) % 998244353;
    long long j = 998244353 - 2;
    long long ii = i;
    while (j > 0) {
      if (j % 2 == 1) {
        q = (q * ii) % 998244353;
      }
      ii = (ii * ii) % 998244353;
      j = j / 2;
    }
    ta[i] = q;
  }
  for (int i = m + 1; i < n + 1; i++) {
    ta[i] = ta[n - i];
  }
  for (int i = 0; i < n + 1; i++) {
    // printf("%d\t%lld\n", i, ta[i]);
  }
  for (int i = 0; i < n + 1; i++) {
    if ((k - i * a) % b == 0) {
      int j = (k - i * a) / b;
      if (j <= n && j >= 0) {
        long long pp = (ta[i]) * (ta[j]);
        // printf("%d %d %lld %lld %lld\n", i, j, ta[i],ta[j],pp);
        answer += pp;
        answer = answer % 998244353;
      } else {
        continue;
      }
    }
  }

  // printf("%d\t%d\t%d\t%d\n", n, a, b, k);
  printf("%lld\n", answer);
}

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

long long ta[399999];

int main() {
  int n;
  int a;
  int b;
  long long k;
  std::cin >> n >> a >> b >> k;
  //  n = 4; a = 2; b = 1; k = 5;
  // printf("%d\t%d\t%d\t%lld\n", n, a, b, k);
  // system("pause");
  ta[0] = 1;
  long long q = 1;
  int m = (n + 1) / 2;
  long long answer = 0;

  for (int i = 1; i < m + 1; i++) {
    q = (q * (n - i + 1)) % 998244353;
    long long j = 998244353 - 2;
    long long ii = i;
    while (j > 0) {
      if (j % 2 == 1) {
        q = (q * ii) % 998244353;
      }
      ii = (ii * ii) % 998244353;
      j = j / 2;
    }
    ta[i] = q;
  }
  for (int i = m + 1; i < n + 1; i++) {
    ta[i] = ta[n - i];
  }
  for (int i = 0; i < n + 1; i++) {
    // printf("%d\t%lld\n", i, ta[i]);
  }
  for (int i = 0; i < n + 1; i++) {
    if ((k - i * a) % b == 0) {
      int j = (k - i * a) / b;
      if (j <= n && j >= 0) {
        long long pp = (ta[i]) * (ta[j]);
        // printf("%d %d %lld %lld %lld\n", i, j, ta[i],ta[j],pp);
        answer += pp;
        answer = answer % 998244353;
      } else {
        continue;
      }
    }
  }

  // printf("%d\t%d\t%d\t%d\n", n, a, b, k);
  printf("%lld\n", answer);
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const long long md = 998244353;
const int maxn = 300100;
long long fac[maxn], inv[maxn];
long long powd(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1)
      res = res * x % md;
    x = x * x % md;
    y >>= 1;
  }
  return res;
}
void csh() {
  fac[0] = 1;
  for (int i = 1; i <= 300000; i++)
    fac[i] = fac[i - 1] * i % md;
  inv[300000] = powd(fac[300000], md - 2);
  for (int i = 300000; i >= 1; i--)
    inv[i - 1] = inv[i] * i % md;
}
long long C(int x, int y) { return fac[x] * inv[y] % md * inv[x - y] % md; }
int main() {
  csh();
  long long n, a, b, k;
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    if (i * a > k || (k - i * a) % b != 0)
      continue;
    ans = (ans + C(n, i) * C(n, (k - i * a) / b)) % md;
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long md = 998244353;
const int maxn = 300100;
long long fac[maxn], inv[maxn];
long long powd(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1)
      res = res * x % md;
    x = x * x % md;
    y >>= 1;
  }
  return res;
}
void csh() {
  fac[0] = 1;
  for (int i = 1; i <= 300000; i++)
    fac[i] = fac[i - 1] * i % md;
  inv[300000] = powd(fac[300000], md - 2);
  for (int i = 300000; i >= 1; i--)
    inv[i - 1] = inv[i] * i % md;
}
long long C(int x, int y) { return fac[x] * inv[y] % md * inv[x - y] % md; }
int main() {
  csh();
  long long n, a, b, k;
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    if (i * a > k || (k - i * a) % b != 0 || (k - i * a) / b > n)
      continue;
    ans = (ans + C(n, i) * C(n, (k - i * a) / b)) % md;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int mod = 998244353;
const int MAXN = (int)1e5 + 5;

int fact[MAXN];

int rev[MAXN];

ll a, b, k;

int n, ans;

int binPow(int a, int b, int m = mod) {
  int ret = 1;

  while (b > 0) {
    if (b & 1) {
      ret = (ret * 1ll * a) % m;
    }

    a = (a * 1ll * a) % m;
    b >>= 1;
  }

  return ret;
}

void pre() {
  fact[0] = rev[0] = 1;

  for (int i = 1; i < MAXN; ++i) {
    fact[i] = (fact[i - 1] * 1ll * i) % mod;
    rev[i] = binPow(fact[i], mod - 2);
  }
}

void addMod(int &a, int b, int m = mod) {
  a += b;

  if (m <= a) {
    a -= m;
  }
}

int C(int n, int k) {
  if (k < 0 || k > n) {
    return 0;
  }

  return fact[n] * 1ll * rev[k] % mod * rev[n - k] % mod;
}

void solve() {
  scanf("%d %lld %lld %lld", &n, &a, &b, &k);

  for (int x = 0; x <= n; ++x) {
    ll left = k - x * a;

    if (left < 0) {
      break;
    }

    if (left % b == 0 && left / b <= n) {
      int y = left / b;
      addMod(ans, C(n, x) * 1ll * C(n, y) % mod);
    }
  }

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

int main() {
  int tt = 1;

  pre();

  while (tt--) {
    solve();
  }

  return 0;
}

Fixed submission:
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int mod = 998244353;
const int MAXN = (int)3e5 + 5;

int fact[MAXN];

int rev[MAXN];

ll a, b, k;

int n, ans;

int binPow(int a, int b, int m = mod) {
  int ret = 1;

  while (b > 0) {
    if (b & 1) {
      ret = (ret * 1ll * a) % m;
    }

    a = (a * 1ll * a) % m;
    b >>= 1;
  }

  return ret;
}

void pre() {
  fact[0] = rev[0] = 1;

  for (int i = 1; i < MAXN; ++i) {
    fact[i] = (fact[i - 1] * 1ll * i) % mod;
    rev[i] = binPow(fact[i], mod - 2);
  }
}

void addMod(int &a, int b, int m = mod) {
  a += b;

  if (m <= a) {
    a -= m;
  }
}

int C(int n, int k) {
  if (k < 0 || k > n) {
    return 0;
  }

  return fact[n] * 1ll * rev[k] % mod * rev[n - k] % mod;
}

void solve() {
  scanf("%d %lld %lld %lld", &n, &a, &b, &k);

  for (int x = 0; x <= n; ++x) {
    ll left = k - x * a;

    if (left < 0) {
      break;
    }

    if (left % b == 0 && left / b <= n) {
      int y = left / b;
      addMod(ans, C(n, x) * 1ll * C(n, y) % mod);
    }
  }

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

int main() {
  int tt = 1;

  pre();

  while (tt--) {
    solve();
  }

  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 998244353;
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll d = a;
  if (b) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}
ll modi(ll a) {
  ll x, y;
  extgcd(a, mod, x, y);
  return (mod + x % mod) % mod;
}
ll tmp[300010];
ll N, A, B, K, ans = 0;
ll pat(ll x) {
  ll res = mul(tmp[N], modi(tmp[x]));
  res = mul(res, modi(tmp[N - x]));
  return res;
}

int main() {
  tmp[0] = 1;
  for (ll i = 1; i <= 300005; i++) {
    tmp[i] = mul(tmp[i - 1], i);
  }
  cin >> N >> A >> B >> K;
  for (ll a = 0; a <= N; a++) {
    if ((K - a * A) % B)
      continue;
    ll b = (K - a * A) / B;
    if (b > N && b < 0)
      continue;
    ans = (ans + mul(pat(a), pat(b))) % mod;
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 998244353;
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll d = a;
  if (b) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}
ll modi(ll a) {
  ll x, y;
  extgcd(a, mod, x, y);
  return (mod + x % mod) % mod;
}
ll tmp[300010];
ll N, A, B, K, ans = 0;
ll pat(ll x) {
  ll res = mul(tmp[N], modi(tmp[x]));
  res = mul(res, modi(tmp[N - x]));
  return res;
}

int main() {
  tmp[0] = 1;
  for (ll i = 1; i <= 300005; i++) {
    tmp[i] = mul(tmp[i - 1], i);
  }
  cin >> N >> A >> B >> K;
  for (ll a = 0; a <= N; a++) {
    if ((K - a * A) % B)
      continue;
    ll b = (K - a * A) / B;
    if (b > N || b < 0)
      continue;
    ans = (ans + mul(pat(a), pat(b))) % mod;
  }
  cout << ans << endl;

  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pd pair<double, double>
#define ld long double
#define pld pair<ld, ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd
#define eps 0.0000000000000000001

ll n, a, b, k, mod = 998244353, f[300005], v[300005], ans;

ll pwr(ll a, ll p) {
  if (!p)
    return 1;
  ll t = pwr(a, p / 2);
  t = t * t % mod;
  if (p % 2)
    return t * a % mod;
  else
    return t;
}

ll C(ll n, ll k) { return f[n] * v[k] % mod * v[n - k] % mod; }

int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n >> a >> b >> k;
  f[0] = 1;
  v[0] = 1;
  for (ll i = 1; i <= n; i++) {
    f[i] = (f[i - 1] * i) % mod;
    v[i] = pwr(f[i], mod - 2);
  }
  for (ll i = 0; i <= n; i++) {
    if ((k - a * i) % b == 0) {
      ll j = (k - a * i) / b;
      ans += C(n, i) * C(n, j);
      ans %= mod;
    }
  }
  cout << ans;
}


Fixed submission:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pd pair<double, double>
#define ld long double
#define pld pair<ld, ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd
#define eps 0.0000000000000000001

ll n, a, b, k, mod = 998244353, f[300005], v[300005], ans;

ll pwr(ll a, ll p) {
  if (!p)
    return 1;
  ll t = pwr(a, p / 2);
  t = t * t % mod;
  if (p % 2)
    return t * a % mod;
  else
    return t;
}

ll C(ll n, ll k) { return f[n] * v[k] % mod * v[n - k] % mod; }

int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n >> a >> b >> k;
  f[0] = 1;
  v[0] = 1;
  for (ll i = 1; i <= n; i++) {
    f[i] = (f[i - 1] * i) % mod;
    v[i] = pwr(f[i], mod - 2);
  }
  for (ll i = 0; i <= n; i++) {
    if (k >= a * i && (k - a * i) % b == 0 && (k - a * i) / b <= n) {
      ll j = (k - a * i) / b;
      ans += C(n, i) * C(n, j);
      ans %= mod;
    }
  }
  cout << ans;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define N 100010
const int mod = 998244353;
int frac[N], ifrac[N];
void exgcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1, y = 0;
    return;
  }
  exgcd(b, a % b, y, x);
  y -= a / b * x;
}
int inv(int a) {
  int x, y;
  exgcd(a, mod, x, y);
  return (x + mod) % mod;
}
void pre(int n) {
  frac[0] = ifrac[0] = 1;
  for (int i = 1; i <= n; i++)
    frac[i] = (ll)i * frac[i - 1] % mod;
  for (int i = 1; i <= n; i++)
    ifrac[i] = inv(frac[i]);
}
int C(int a, int b) {
  return (ll)frac[a] * ifrac[b] % mod * ifrac[a - b] % mod;
}
int main() {
  int n, b, a;
  ll k;
  scanf("%d%d%d%lld", &n, &a, &b, &k);
  pre(n);
  int s = min(k / a, (ll)n), ans = 0;
  for (int i = 0; i <= s; i++) {
    ll last = k - (ll)i * a;
    if (last % b)
      continue;
    int j = last / b;
    if (j > n)
      continue;
    ans = (ans + (ll)C(n, i) * C(n, j)) % mod;
  }
  printf("%d\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define N 300010
const int mod = 998244353;
int frac[N], ifrac[N];
void exgcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1, y = 0;
    return;
  }
  exgcd(b, a % b, y, x);
  y -= a / b * x;
}
int inv(int a) {
  int x, y;
  exgcd(a, mod, x, y);
  return (x + mod) % mod;
}
void pre(int n) {
  frac[0] = ifrac[0] = 1;
  for (int i = 1; i <= n; i++)
    frac[i] = (ll)i * frac[i - 1] % mod;
  for (int i = 1; i <= n; i++)
    ifrac[i] = inv(frac[i]);
}
int C(int a, int b) {
  return (ll)frac[a] * ifrac[b] % mod * ifrac[a - b] % mod;
}
int main() {
  int n, b, a;
  ll k;
  scanf("%d%d%d%lld", &n, &a, &b, &k);
  pre(n);
  int s = min(k / a, (ll)n), ans = 0;
  for (int i = 0; i <= s; i++) {
    ll last = k - (ll)i * a;
    if (last % b)
      continue;
    int j = last / b;
    if (j > n)
      continue;
    ans = (ans + (ll)C(n, i) * C(n, j)) % mod;
  }
  printf("%d\n", ans);
}
Problem p03332 (C++)

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()

typedef long long lint;

using namespace std;
lint p = 998244353;
lint pro[300001];

lint pow_mod(lint a, lint b, lint p) {
  if (b == 0)
    return 1;
  if (b % 2 == 0) {
    lint d = pow_mod(a, b / 2, p);
    return (d * d) % p;
  } else {
    return (a * pow_mod(a, b - 1, p)) % p;
  }
}

// x / a mod p=x * inv_mod(a,p)
lint inv_mod(lint a, lint p) {
  return pow_mod(a, p - 2, p); //(a^(p-2))mod p
}

lint nCk(lint n, lint k) {
  return (pro[n] * inv_mod((pro[k] * pro[n - k]) % p, p)) % p;
}

int main() {
  pro[0] = 1;
  FOR(i, 1, 300001) {
    pro[i] = pro[i - 1] * i;
    pro[i] %= p;
  }
  lint N, A, B, K;
  cin >> N >> A >> B >> K;
  lint ans = 0;
  REP(i, N + 1) {
    if ((K - A * i) % B != 0)
      continue;
    if ((K - A * i) / B > N)
      continue;
    ans += nCk(N, i) * nCk(N, (K - A * i) / B);
    ans %= p;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()

typedef long long lint;

using namespace std;
lint p = 998244353;
lint pro[300001];

lint pow_mod(lint a, lint b, lint p) {
  if (b == 0)
    return 1;
  if (b % 2 == 0) {
    lint d = pow_mod(a, b / 2, p);
    return (d * d) % p;
  } else {
    return (a * pow_mod(a, b - 1, p)) % p;
  }
}

// x / a mod p=x * inv_mod(a,p)
lint inv_mod(lint a, lint p) {
  return pow_mod(a, p - 2, p); //(a^(p-2))mod p
}

lint nCk(lint n, lint k) {
  return (pro[n] * inv_mod((pro[k] * pro[n - k]) % p, p)) % p;
}

int main() {
  pro[0] = 1;
  FOR(i, 1, 300001) {
    pro[i] = pro[i - 1] * i;
    pro[i] %= p;
  }
  lint N, A, B, K;
  cin >> N >> A >> B >> K;
  lint ans = 0;
  REP(i, N + 1) {
    if (K < A * i)
      continue;
    if ((K - A * i) % B != 0)
      continue;
    if ((K - A * i) / B > N)
      continue;
    ans += nCk(N, i) * nCk(N, (K - A * i) / B);
    ans %= p;
  }
  cout << ans << endl;
  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 + 5;
const ll mod = 998244353;

int n;
ll a, b, k, x, y, fac[N], rev[N];

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

void init() {
  int i;
  for (fac[0] = i = 1; i < N; ++i)
    fac[i] = fac[i - 1] * i % mod;
  for (rev[N - 1] = qpow(fac[N - 1], mod - 2), i = N - 2; ~i; --i)
    rev[i] = rev[i + 1] * (i + 1) % mod;
}

ll C(int n, int m) {
  return n < m ? 0 : fac[n] * rev[m] % mod * rev[n - m] % mod;
}

int main() {
  init();
  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) {
      ll j = (k - a * i) / b;
      (ans += C(n, i) * C(n, j) % mod) %= mod;
    }
  cout << ans << endl;
}

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

int n;
ll a, b, k, x, y, fac[N], rev[N];

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

void init() {
  int i;
  for (fac[0] = i = 1; i < N; ++i)
    fac[i] = fac[i - 1] * i % mod;
  for (rev[N - 1] = qpow(fac[N - 1], mod - 2), i = N - 2; ~i; --i)
    rev[i] = rev[i + 1] * (i + 1) % mod;
}

ll C(int n, int m) {
  return n < m ? 0 : fac[n] * rev[m] % mod * rev[n - m] % mod;
}

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

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, a, b, k;
  cin >> n >> a >> b >> k;
  auto pow = [&](long long x, int p) {
    x %= MOD;
    long long y = 1;
    while (p) {
      if (p & 1) {
        y = x * y % MOD;
      }
      x = x * x % MOD;
      p >>= 1;
    }
    return y;
  };
  vector<long long> fact(n + 1), facti(n + 1);
  fact[0] = 1, facti[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fact[i] = fact[i - 1] * i % MOD;
    facti[i] = pow(fact[i], MOD - 2);
  }
  long long ans = 0;
  for (long long x = 0; x <= n; ++x) {
    long long y = (k - a * x) / b;
    if ((k - a * x) % b == 0 && y >= 0) {
      long long sub = fact[n];
      sub = sub * fact[n] % MOD;
      sub = sub * facti[x] % MOD;
      sub = sub * facti[y] % MOD;
      sub = sub * facti[n - x] % MOD;
      sub = sub * facti[n - y] % MOD;
      ans = (ans + sub) % MOD;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, a, b, k;
  cin >> n >> a >> b >> k;
  auto pow = [&](long long x, int p) {
    x %= MOD;
    long long y = 1;
    while (p) {
      if (p & 1) {
        y = x * y % MOD;
      }
      x = x * x % MOD;
      p >>= 1;
    }
    return y;
  };
  vector<long long> fact(n + 1), facti(n + 1);
  fact[0] = 1, facti[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fact[i] = fact[i - 1] * i % MOD;
    facti[i] = pow(fact[i], MOD - 2);
  }
  long long ans = 0;
  for (long long x = 0; x <= n; ++x) {
    long long y = (k - a * x) / b;
    if ((k - a * x) % b == 0 && n >= y && y >= 0) {
      long long sub = fact[n];
      sub = sub * fact[n] % MOD;
      sub = sub * facti[x] % MOD;
      sub = sub * facti[y] % MOD;
      sub = sub * facti[n - x] % MOD;
      sub = sub * facti[n - y] % MOD;
      ans = (ans + sub) % MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03332 (C++)

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

#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back

using namespace std;
typedef long long ll;

const int mod = 998244353;
const int maxn = 3e5 + 5;

int power(int a, int b) {
  if (b == 0)
    return 1;
  int res = power(a, b / 2);
  if (b & 1)
    return 1ll * res * res % mod * a % mod;
  return 1ll * res * res % mod;
}

int fact[maxn], ifact[maxn];
int N, A, B, K;

int kCn(int k, int n) {
  if (k > n)
    return 0;
  return 1ll * fact[n] * ifact[k] % mod * ifact[n - k] % mod;
}

signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen("A.INP", "r")) {
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N >> A >> B >> K;
  fact[0] = 1;
  for (int i = 1; i <= N; ++i) {
    fact[i] = 1ll * fact[i - 1] * i % mod;
  }
  ifact[N] = power(fact[N], mod - 2);
  for (int i = N - 1; i >= 0; --i) {
    ifact[i] = 1ll * ifact[i + 1] * (i + 1) % mod;
  }
  int res = 0;
  for (int i = 0; i <= N; ++i) {
    ll val = K - 1ll * i * A;
    if (val % B == 0) {
      if (val / B > N)
        continue;
      int j = val / B;
      res += 1ll * kCn(i, N) * kCn(j, N) % mod;
      res %= mod;
    }
  }
  cout << res << '\n';
}


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

#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back

using namespace std;
typedef long long ll;

const int mod = 998244353;
const int maxn = 3e5 + 5;

int power(int a, int b) {
  if (b == 0)
    return 1;
  int res = power(a, b / 2);
  if (b & 1)
    return 1ll * res * res % mod * a % mod;
  return 1ll * res * res % mod;
}

int fact[maxn], ifact[maxn];
int N, A, B, K;

int kCn(int k, int n) {
  if (k > n)
    return 0;
  return 1ll * fact[n] * ifact[k] % mod * ifact[n - k] % mod;
}

signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen("A.INP", "r")) {
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N >> A >> B >> K;
  fact[0] = 1;
  for (int i = 1; i <= N; ++i) {
    fact[i] = 1ll * fact[i - 1] * i % mod;
  }
  ifact[N] = power(fact[N], mod - 2);
  for (int i = N - 1; i >= 0; --i) {
    ifact[i] = 1ll * ifact[i + 1] * (i + 1) % mod;
  }
  int res = 0;
  for (int i = 0; i <= N; ++i) {
    int j = (K - i * A) / B;
    if (j < 0 || j > N || j * B + i * A != K)
      continue;
    res += 1ll * kCn(i, N) * kCn(j, N) % mod;
    res %= mod;
  }
  cout << res << '\n';
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include "algorithm"
#include "bitset"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;

const long long int MOD = 998244353;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
  long long int tmp = 1;

  if (n > 0) {
    tmp = power(x, n / 2, M);
    if (n % 2 == 0)
      tmp = (tmp * tmp) % M;
    else
      tmp = (((tmp * tmp) % M) * x) % M;
  }
  return tmp;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> N >> M >> K >> L;
  vector<long long int> ncr(N + 1);
  ncr[0] = 1;
  for (int i = 1; i <= N; i++) {
    ncr[i] = ncr[i - 1] * (N + 1 - i);
    ncr[i] %= MOD;
    ncr[i] *= power(i, MOD - 2, MOD);
    ncr[i] %= MOD;
  }
  long long int ans = 0;
  for (int i = 0; i <= N; i++) {
    if ((L - M * i) % K)
      continue;
    if ((L - M * i) / K > N)
      continue;
    long long int add = ncr[i] * ncr[(L - M * i) / K];
    ans += add;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include "algorithm"
#include "bitset"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;

const long long int MOD = 998244353;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
  long long int tmp = 1;

  if (n > 0) {
    tmp = power(x, n / 2, M);
    if (n % 2 == 0)
      tmp = (tmp * tmp) % M;
    else
      tmp = (((tmp * tmp) % M) * x) % M;
  }
  return tmp;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> N >> M >> K >> L;
  vector<long long int> ncr(N + 1);
  ncr[0] = 1;
  for (int i = 1; i <= N; i++) {
    ncr[i] = ncr[i - 1] * (N + 1 - i);
    ncr[i] %= MOD;
    ncr[i] *= power(i, MOD - 2, MOD);
    ncr[i] %= MOD;
  }
  long long int ans = 0;
  for (int i = 0; i <= N; i++) {
    if (L - M * i < 0)
      continue;
    if ((L - M * i) % K)
      continue;
    if ((L - M * i) / K > N)
      continue;
    long long int add = ncr[i] * ncr[(L - M * i) / K];
    ans += add;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p03332 (C++)

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

using namespace std;

typedef long long ll;

const ll N = 1e7 + 5, P = 998244353;

ll fac[N], inv[N], fnv[N];

void pre() {
  fnv[0] = fac[0] = inv[1] = 1;
  for (ll i = 2; i <= N; ++i)
    inv[i] = (P - P / i) * 1ll * inv[P % i] % P;
  for (ll i = 1; i <= N; ++i)
    fac[i] = fac[i - 1] % P * i % P, fnv[i] = fnv[i - 1] % P * inv[i] % P;
}

ll C(ll a, ll b) { return fac[a] % P * fnv[b] % P * fnv[a - b] % P; }

int main(void) {
  pre();
  ll a, b, c, d;
  scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
  ll ans = 0;
  for (ll i = 0; i <= a; ++i) {
    if ((d - i * b) % c == 0) {
      ll k = (d - i * b) / c;
      ans = (ans + C(a, k) % P * C(a, i)) % P;
    }
  }
  printf("%lld", ans % P);
}

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

using namespace std;

typedef long long ll;

const ll N = 1e7 + 5, P = 998244353;

ll fac[N], inv[N], fnv[N];

void pre() {
  fnv[0] = fac[0] = inv[1] = 1;
  for (ll i = 2; i <= N; ++i)
    inv[i] = (P - P / i) * 1ll * inv[P % i] % P;
  for (ll i = 1; i <= N; ++i)
    fac[i] = fac[i - 1] % P * i % P, fnv[i] = fnv[i - 1] % P * inv[i] % P;
}

ll C(ll a, ll b) {
  if (a < 0 or b < 0 or b > a)
    return 0;
  return fac[a] % P * fnv[b] % P * fnv[a - b] % P;
}

int main(void) {
  pre();
  ll a, b, c, d;
  scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
  ll ans = 0;
  for (ll i = 0; i <= a; ++i) {
    if ((d - i * b) % c == 0) {
      ll k = (d - i * b) / c;
      ans = (ans + C(a, k) % P * C(a, i)) % P;
    }
  }
  printf("%lld", ans % P);
}
Problem p03332 (C++)

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n, k) ((((n) % (k)) + (k)) % (k))
#define FOR(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, ll> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int MX = 300005, mod = 998244353;
int n;
ll a, b, k, res = 0;
ll fac[MX], inv[MX];

void pre() {
  fac[0] = 1;
  for (ll i = 1; i < MX; i++)
    fac[i] = i * fac[i - 1] % mod;

  inv[0] = inv[1] = 1;
  for (int i = 2; i < MX; i++)
    inv[i] = inv[mod % i] * (mod - mod / i) % mod;

  for (int i = 2; i < MX; i++)
    inv[i] = inv[i] * inv[i - 1] % mod;
}

ll C(int n, int k) { return fac[n] * inv[k] % mod * inv[n - k] % mod; }

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

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

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

    j /= b;
    if (j > n)
      continue;

    res += C(n, i) * C(n, j) % mod;
    res %= mod;
  }

  cout << res << endl;

  return 0;
}


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

#define endl '\n'
#define fi first
#define se second
#define MOD(n, k) ((((n) % (k)) + (k)) % (k))
#define FOR(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, ll> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int MX = 300005, mod = 998244353;
int n;
ll a, b, k, res = 0;
ll fac[MX], inv[MX];

void pre() {
  fac[0] = 1;
  for (ll i = 1; i < MX; i++)
    fac[i] = i * fac[i - 1] % mod;

  inv[0] = inv[1] = 1;
  for (int i = 2; i < MX; i++)
    inv[i] = inv[mod % i] * (mod - mod / i) % mod;

  for (int i = 2; i < MX; i++)
    inv[i] = inv[i] * inv[i - 1] % mod;
}

ll C(int n, int k) { return fac[n] * inv[k] % mod * inv[n - k] % mod; }

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

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

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

    j /= b;
    if (j > n || j < 0)
      continue;

    res += C(n, i) * C(n, j) % mod;
    res %= mod;
  }

  cout << res << endl;

  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
typedef pair<ll, ll> pll;
void read(int &x) { scanf("%d", &x); }
void read(ll &x) { scanf("%lld", &x); }
template <typename T, typename... Args> void read(T &a, Args &...b) {
  read(a);
  read(b...);
}
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

ll n, a, b, k;

ll fact[300010];
const ll mod = 998244353;

ll Pow(ll b, ll e) {
  if (e < 0)
    e = (-e) * (mod - 2) % (mod - 1);
  ll ret = 1;
  while (e) {
    if (e & 1)
      (ret *= b) %= mod;
    (b *= b) %= mod;
    e >>= 1;
  }
  return ret;
}

ll Comb(ll n, ll r) {
  return fact[n] * Pow(fact[r], -1) % mod * Pow(fact[n - r], -1) % mod;
}

int main() {
  read(n, a, b, k);
  fact[0] = 1;
  for (int i = 1; i <= n; ++i)
    fact[i] = fact[i - 1] * i % mod;
  ll ans = 0;
  for (int p = 0; p <= n; ++p) {
    ll q = (k - p * a) / b;
    if (p * a + q * b == k) {
      (ans += Comb(n, p) * Comb(n, q) % mod) %= mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
typedef pair<ll, ll> pll;
void read(int &x) { scanf("%d", &x); }
void read(ll &x) { scanf("%lld", &x); }
template <typename T, typename... Args> void read(T &a, Args &...b) {
  read(a);
  read(b...);
}
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

ll n, a, b, k;

ll fact[300010];
const ll mod = 998244353;

ll Pow(ll b, ll e) {
  if (e < 0)
    e = (-e) * (mod - 2) % (mod - 1);
  ll ret = 1;
  while (e) {
    if (e & 1)
      (ret *= b) %= mod;
    (b *= b) %= mod;
    e >>= 1;
  }
  return ret;
}

ll Comb(ll n, ll r) {
  return fact[n] * Pow(fact[r], -1) % mod * Pow(fact[n - r], -1) % mod;
}

int main() {
  read(n, a, b, k);
  fact[0] = 1;
  for (int i = 1; i <= n; ++i)
    fact[i] = fact[i - 1] * i % mod;
  ll ans = 0;
  for (int p = 0; p <= n; ++p) {
    ll q = (k - p * a) / b;
    if (p * a + q * b == k && 0 <= q && q <= n) {
      (ans += Comb(n, p) * Comb(n, q) % mod) %= mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03332 (C++)

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

struct P {
  int x, y;
  bool operator<(const P &a) const { return x > a.x; }
};

vector<int> v[11];
// bitset<4001000> b;
int a, c, i, b, k, n, d, e,
    m; // dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int o[120];
long long l[333310];
int j[22];
int dx[10] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[10] = {0, 1, 0, -1, 1, -1, 1, -1},
    dz[10] = {0, 0, 0, 0, 1, -1};

long long x, y, mod = 998244353;
long long z;

P u[550];
stack<int> s;

// set<int> s;
queue<int> q;

//'1'==49;
//'A'==65;
//'a'==97;
// unordered_
// map<int,int> p[11];
// list<int> l;

string r;
// char r[33];
// deque<int> de;
bool as(int a, int b) { return i > 2; }

long long f(int a, int b) {
  if (!b)
    return 1;
  long long x = f(a, b / 2);
  x *= x, x %= mod;
  if (b & 1)
    x *= a, x %= mod;
  return x;
}

int main() {

  scanf("%d %d %d %lld", &a, &b, &c, &x);
  l[1] = a, l[0] = 1;
  for (int t = 2; t <= a; t++) {
    l[t] = l[t - 1] * (a - t + 1) % mod * f(t, mod - 2) % mod;
    // printf("%lld ",l[t]);
  }
  for (long long t = 0; t * b <= x && t <= a; t++) {

    if ((x - t * b) % c == 0) {
      // printf("%lld %lld %lld\n",t,(x-t*b)/c,y);
      y += l[t] * l[(x - t * b) / c] % mod, y %= mod;
    }
  }
  printf("%lld", y);
}


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

struct P {
  int x, y;
  bool operator<(const P &a) const { return x > a.x; }
};

vector<int> v[11];
// bitset<4001000> b;
int a, c, i, b, k, n, d, e,
    m; // dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int o[120];
long long l[333310];
int j[22];
int dx[10] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[10] = {0, 1, 0, -1, 1, -1, 1, -1},
    dz[10] = {0, 0, 0, 0, 1, -1};

long long x, y, mod = 998244353;
long long z;

P u[550];
stack<int> s;

// set<int> s;
queue<int> q;

//'1'==49;
//'A'==65;
//'a'==97;
// unordered_
// map<int,int> p[11];
// list<int> l;

string r;
// char r[33];
// deque<int> de;
bool as(int a, int b) { return i > 2; }

long long f(int a, int b) {
  if (!b)
    return 1;
  long long x = f(a, b / 2);
  x *= x, x %= mod;
  if (b & 1)
    x *= a, x %= mod;
  return x;
}

int main() {

  scanf("%d %d %d %lld", &a, &b, &c, &x);
  l[1] = a, l[0] = 1;
  for (int t = 2; t <= a; t++) {
    l[t] = l[t - 1] * (a - t + 1) % mod * f(t, mod - 2) % mod;
    // printf("%lld ",l[t]);
  }
  for (long long t = 0; t * b <= x && t <= a; t++) {

    if ((x - t * b) % c == 0 && (x - t * b) / c <= a) {
      // printf("%lld %lld %lld\n",t,(x-t*b)/c,y);
      y += l[t] * l[(x - t * b) / c] % mod, y %= mod;
    }
  }
  printf("%lld", y);
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr << #x << "=" << x << endl
#define fgx cerr << "-------------" << endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 998244353;
int fac[N], inv[N];
inline int qpow(int x, int y) {
  int A = 1;
  for (; y; y >>= 1, x = (ll)x * x % mod)
    if (y & 1)
      A = (ll)A * x % mod;
  return A;
}
inline int C(int x, int y) {
  return (ll)fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main() {
  ll k, a, b;
  int n, ans = 0;
  cin >> n >> a >> b >> k;
  fac[0] = inv[0] = 1;
  for (rint i = 1; i <= n; i++)
    fac[i] = (ll)fac[i - 1] * i % mod, inv[i] = qpow(fac[i], mod - 2);
  for (rint i = 0; i <= n; i++)
    if ((k - a * i) % b == 0)
      ans += (ll)C(n, i) * C(n, (k - a * i) / b) % mod;
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr << #x << "=" << x << endl
#define fgx cerr << "-------------" << endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 998244353;
int fac[N], inv[N];
inline int qpow(int x, int y) {
  int A = 1;
  for (; y; y >>= 1, x = (ll)x * x % mod)
    if (y & 1)
      A = (ll)A * x % mod;
  return A;
}
inline int C(int x, int y) {
  return (ll)fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main() {
  ll k, a, b;
  int n, ans = 0;
  cin >> n >> a >> b >> k;
  fac[0] = inv[0] = 1;
  for (rint i = 1; i <= n; i++)
    fac[i] = (ll)fac[i - 1] * i % mod, inv[i] = qpow(fac[i], mod - 2);
  for (rint i = 0; i <= n; i++)
    if ((k - a * i) % b == 0 && 0 <= (k - a * i) / b && (k - a * i) / b <= n)
      (ans += (ll)C(n, i) * C(n, (k - a * i) / b) % mod) %= mod;
  cout << ans;
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
namespace io {
const int L = (1 << 19) + 1;
char ibuf[L], *iS, *iT, c;
int f;
char gc() {
  if (iS == iT) {
    iT = (iS = ibuf) + fread(ibuf, 1, L, stdin);
    return iS == iT ? EOF : *iS++;
  }
  return *iS++;
}
template <class I> void gi(I &x) {
  for (f = 1, c = gc(); c < '0' || c > '9'; c = gc())
    if (c == '-')
      f = -1;
  for (x = 0; c <= '9' && c >= '0'; c = gc())
    x = x * 10 + (c & 15);
  x *= f;
}
}; // namespace io
using io::gc;
using io::gi;
const int mod = 998244353;
const int M = 600005;
long long fac[M], inv[M];
int n, a, b;
long long k;
int ans = 0;
long long C(int x, int y) {
  if (y > x)
    return 0;
  return fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main() {
  //	freopen("a.in","r",stdin);
  //	freopen("a.out","w",stdout);
  fac[0] = 1;
  for (int i = 1; i <= 600000; i++)
    fac[i] = fac[i - 1] * i % mod;
  inv[1] = 1;
  for (int i = 2; i <= 600000; i++)
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  inv[0] = 1;
  for (int i = 1; i <= 600000; i++)
    (inv[i] *= inv[i - 1]) %= mod;
  scanf("%d%d%d%lld", &n, &a, &b, &k);
  for (int i = 0; i <= n; i++)
    if ((k - (long long)a * i) % b == 0) {
      ans = (ans + C(n, i) * C(n, (k - (long long)a * i) / b) % mod) % mod;
    }
  printf("%d", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
namespace io {
const int L = (1 << 19) + 1;
char ibuf[L], *iS, *iT, c;
int f;
char gc() {
  if (iS == iT) {
    iT = (iS = ibuf) + fread(ibuf, 1, L, stdin);
    return iS == iT ? EOF : *iS++;
  }
  return *iS++;
}
template <class I> void gi(I &x) {
  for (f = 1, c = gc(); c < '0' || c > '9'; c = gc())
    if (c == '-')
      f = -1;
  for (x = 0; c <= '9' && c >= '0'; c = gc())
    x = x * 10 + (c & 15);
  x *= f;
}
}; // namespace io
using io::gc;
using io::gi;
const int mod = 998244353;
const int M = 600005;
long long fac[M], inv[M];
int n, a, b;
long long k;
int ans = 0;
long long C(int x, int y) {
  if (y > x || y < 0)
    return 0;
  return fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main() {
  //	freopen("a.in","r",stdin);
  //	freopen("a.out","w",stdout);
  fac[0] = 1;
  for (int i = 1; i <= 600000; i++)
    fac[i] = fac[i - 1] * i % mod;
  inv[1] = 1;
  for (int i = 2; i <= 600000; i++)
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
  inv[0] = 1;
  for (int i = 1; i <= 600000; i++)
    (inv[i] *= inv[i - 1]) %= mod;
  scanf("%d%d%d%lld", &n, &a, &b, &k);
  for (int i = 0; i <= n; i++)
    if ((k - (long long)a * i) % b == 0) {
      ans = (ans + C(n, i) * C(n, (k - (long long)a * i) / b) % mod) % mod;
    }
  printf("%d", ans);
  return 0;
}
Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <array>
#include <bits/stdc++.h>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for (UL i = 0; i < (n); i++)

struct Problem {

  static const ULL M = 998244353;

  void Solve() {
    ULL N, A, B, K;
    cin >> N >> A >> B >> K;

    vector<ULL> C(N + 1);
    {
      vector<ULL> I(N + 1);
      I[1] = 1;
      for (UL i = 2; i <= N; i++)
        I[i] = M - M / i * I[M % i] % M;
      vector<ULL> iF(N + 1);
      iF[0] = 1;
      for (UL i = 1; i <= N; i++)
        iF[i] = iF[i - 1] * I[i] % M;
      vector<ULL> F(N + 1);
      F[0] = 1;
      for (UL i = 1; i <= N; i++)
        F[i] = F[i - 1] * i % M;
      rep(i, N + 1) C[i] = F[N] * iF[i] % M * iF[N - i] % M;
    }

    ULL ans = 0;
    rep(i, N + 1) {
      ULL AA = A * i;
      if (AA > K)
        continue;
      if ((K - AA) % B != 0)
        continue;
      ULL j = (K - AA) / B;
      ans += C[i] * C[j] % M;
    }
    ans %= M;
    cout << ans << endl;
  }

  Problem();
};
int main() {
  unique_ptr<Problem> p(new Problem());
  p->Solve();
  return 0;
}
Problem::Problem() { cout << fixed << setprecision(10); }

Fixed submission:
#include <array>
#include <bits/stdc++.h>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for (UL i = 0; i < (n); i++)

struct Problem {

  static const ULL M = 998244353;

  void Solve() {
    ULL N, A, B, K;
    cin >> N >> A >> B >> K;

    vector<ULL> C(N + 1);
    {
      vector<ULL> I(N + 1);
      I[1] = 1;
      for (UL i = 2; i <= N; i++)
        I[i] = M - M / i * I[M % i] % M;
      vector<ULL> iF(N + 1);
      iF[0] = 1;
      for (UL i = 1; i <= N; i++)
        iF[i] = iF[i - 1] * I[i] % M;
      vector<ULL> F(N + 1);
      F[0] = 1;
      for (UL i = 1; i <= N; i++)
        F[i] = F[i - 1] * i % M;
      rep(i, N + 1) C[i] = F[N] * iF[i] % M * iF[N - i] % M;
    }

    ULL ans = 0;
    rep(i, N + 1) {
      ULL AA = A * i;
      if (AA > K)
        continue;
      if ((K - AA) % B != 0)
        continue;
      ULL j = (K - AA) / B;
      if (j > N)
        continue;
      ans += C[i] * C[j] % M;
    }
    ans %= M;
    cout << ans << endl;
  }

  Problem();
};
int main() {
  unique_ptr<Problem> p(new Problem());
  p->Solve();
  return 0;
}
Problem::Problem() { cout << fixed << setprecision(10); }