Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a, 0, sizeof(a))
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
const int inf = 1e9;
const ll Inf = 1e18;
const int N = 1e5 + 10;
const int mod = 998244353;
ll gi() {
  ll x = 0, o = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-')
    ch = getchar();
  if (ch == '-')
    o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
template <typename T> bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; };
template <typename T> bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; };
int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
void inc(int &a, int b) { a = (a + b >= mod ? a + b - mod : a + b); }
void dec(int &a, int b) { a = (a - b < 0 ? a - b + mod : a - b); }
int fac[N], inv[N], ifac[N];
int n;
ll a, b, k;
int C(int n, int m) {
  if (n < 0 || m < 0 || n < m)
    return 0;
  return 1ll * fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
int main() {
  n = gi(), a = gi(), b = gi(), k = gi();
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = 1ll * fac[i - 1] * i % mod;
  inv[1] = 1;
  for (int i = 2; i <= n; i++)
    inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
  ifac[0] = 1;
  for (int i = 1; i <= n; i++)
    ifac[i] = 1ll * ifac[i - 1] * inv[i] % mod;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (a * i <= k && (k - a * i) % b == 0)
      inc(ans, 1ll * C(n, i) * C(n, (k - a * i) / b) % mod);
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a, 0, sizeof(a))
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
const int inf = 1e9;
const ll Inf = 1e18;
const int N = 3e5 + 10;
const int mod = 998244353;
ll gi() {
  ll x = 0, o = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-')
    ch = getchar();
  if (ch == '-')
    o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
template <typename T> bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; };
template <typename T> bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; };
int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
void inc(int &a, int b) { a = (a + b >= mod ? a + b - mod : a + b); }
void dec(int &a, int b) { a = (a - b < 0 ? a - b + mod : a - b); }
int fac[N], inv[N], ifac[N];
int n;
ll a, b, k;
int C(int n, int m) {
  if (n < 0 || m < 0 || n < m)
    return 0;
  return 1ll * fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
int main() {
  n = gi(), a = gi(), b = gi(), k = gi();
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = 1ll * fac[i - 1] * i % mod;
  inv[1] = 1;
  for (int i = 2; i <= n; i++)
    inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
  ifac[0] = 1;
  for (int i = 1; i <= n; i++)
    ifac[i] = 1ll * ifac[i - 1] * inv[i] % mod;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (a * i <= k && (k - a * i) % b == 0)
      inc(ans, 1ll * C(n, i) * C(n, (k - a * i) / b) % mod);
  }
  printf("%d\n", ans);
  return 0;
}