Problem p03332 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, k, n) for (ll i = (ll)k; i < (ll)n; i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',')
    cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr                                                                   \
  if (0)                                                                       \
  cout
#endif

const int N = 5e5;

const ll mod = 998244353;

ll fact[N + 1];

ll int_pow(ll base, ll exp) {
  if (!exp) {
    return 1ll;
  } else if (exp & 1) {
    return base * int_pow(base, exp - 1) % mod;
  } else {
    return int_pow(base * base % mod, exp >> 1);
  }
}

ll binom(ll n, ll k) {
  return fact[n] * int_pow(fact[k] * fact[n - k] % mod, mod - 2) % mod;
}

int main() {
#ifndef LOCAL
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  fact[0] = 1;
  rep(i, 1, n + 1) { fact[i] = fact[i - 1] * i % mod; }
  ll res = 0;
  rep(i, 0, n) {
    if (k >= a * i and (k - a * i) % b == 0) {
      res = (res + binom(n, i) * binom(n, (k - a * i) / b)) % mod;
    }
  }
  cout << res << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, k, n) for (ll i = (ll)k; i < (ll)n; i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',')
    cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr                                                                   \
  if (0)                                                                       \
  cout
#endif

const int N = 5e5;

const ll mod = 998244353;

ll fact[N + 1];

ll int_pow(ll base, ll exp) {
  if (!exp) {
    return 1ll;
  } else if (exp & 1) {
    return base * int_pow(base, exp - 1) % mod;
  } else {
    return int_pow(base * base % mod, exp >> 1);
  }
}

ll binom(ll n, ll k) {
  return fact[n] * int_pow(fact[k] * fact[n - k] % mod, mod - 2) % mod;
}

int main() {
#ifndef LOCAL
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  fact[0] = 1;
  rep(i, 1, n + 1) { fact[i] = fact[i - 1] * i % mod; }
  ll res = 0;
  rep(i, 0, n + 1) {
    if (k >= a * i and (k - a * i) % b == 0 and (k - a * i) / b <= n) {
      res = (res + binom(n, i) * binom(n, (k - a * i) / b)) % mod;
    }
  }
  cout << res << "\n";
  return 0;
}