Problem p03332 (C++)

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define R(i, n) for (int i = 0; i < (n); i++)
#define VI vector<int>
#define PII pair<int, int>
#define LD long double
#define FI first
#define SE second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template <class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template <class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

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...);
}

template <class T> ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V)
    os << vv << ",";
  return os << "]";
}

template <class T> ostream &operator<<(ostream &os, set<T> V) {
  os << "[";
  for (auto vv : V)
    os << vv << ",";
  return os << "]";
}

template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.FI << "," << P.SE << ")";
}

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

const int MAX = 100010;
const int P = 998244353;
int sil[MAX], odw[MAX];
int pot(int a, int w) {
  int r = 1;
  while (w) {
    if (w & 1) {
      r = r * a % P;
    }
    w /= 2;
    a = a * a % P;
  }
  return r;
}
int dwu(int a, int b) { return sil[a] * odw[b] % P * odw[a - b] % P; }

int n, a, b, k;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> a >> b >> k;
  sil[0] = 1;
  R(i, n) { sil[i + 1] = sil[i] * (i + 1) % P; }
  R(i, n + 1) { odw[i] = pot(sil[i], P - 2); }
  int res = 0;
  R(i, n + 1) {
    int pom = k - i * a;
    if (pom < 0 || pom % b != 0 || pom / b > n)
      continue;
    int j = pom / b;
    res += dwu(n, i) * dwu(n, j) % P;
  }
  cout << res % P << "\n";
}


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define R(i, n) for (int i = 0; i < (n); i++)
#define VI vector<int>
#define PII pair<int, int>
#define LD long double
#define FI first
#define SE second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template <class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template <class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

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...);
}

template <class T> ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V)
    os << vv << ",";
  return os << "]";
}

template <class T> ostream &operator<<(ostream &os, set<T> V) {
  os << "[";
  for (auto vv : V)
    os << vv << ",";
  return os << "]";
}

template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.FI << "," << P.SE << ")";
}

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

const int MAX = 400010;
const int P = 998244353;
int sil[MAX], odw[MAX];
int pot(int a, int w) {
  int r = 1;
  while (w) {
    if (w & 1) {
      r = r * a % P;
    }
    w /= 2;
    a = a * a % P;
  }
  return r;
}
int dwu(int a, int b) { return sil[a] * odw[b] % P * odw[a - b] % P; }

int n, a, b, k;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> a >> b >> k;
  sil[0] = 1;
  R(i, n) { sil[i + 1] = sil[i] * (i + 1) % P; }
  R(i, n + 1) { odw[i] = pot(sil[i], P - 2); }
  int res = 0;
  R(i, n + 1) {
    int pom = k - i * a;
    if (pom < 0 || pom % b != 0 || pom / b > n)
      continue;
    int j = pom / b;
    res += dwu(n, i) * dwu(n, j) % P;
  }
  cout << res % P << "\n";
}