Problem p03332 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize("O2")

// 注意点
// Tは3つの値を持つ構造
// だがワイルドカードとしても使っている
#include <bits/stdc++.h>
using namespace std;
//@起動時
struct initon {
  initon() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    srand((unsigned)clock() + (unsigned)time(NULL));
  };
} __initon;

//@必須構造
struct T {
  int f, s, t;
  T() { f = -1, s = -1, t = -1; }
  T(int f, int s, int t) : f(f), s(s), t(t) {}
  bool operator<(const T &r) const {
    return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t;
    // return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 大きい順
  }
  bool operator>(const T &r) const {
    return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t;
    // return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順
  }
  int operator[](int i) {
    assert(i < 3);
    return i == 0 ? f : i == 1 ? s : t;
  }
};

//@マクロ省略系 型,構造

#define int long long
#define ll long long
#define double long double
#define ull unsigned long long
using dou = double;
using itn = int;
using str = string;
using bo = bool;
using P = pair<int, int>;
#define F first
#define S second
#define vec vector
#define con continue
#define bre break
#define brk break
#define is ==
#define rs resize

// マクロ省略系 コンテナ
using vi = vector<int>;
#define vvi(a, b, c) vec<vi> a(b, vi(c))
using vb = vector<bool>;
#define vvb(a, b, c) vec<vb> a(b, vb(c))
using vs = vector<string>;
#define vvs(a, b, c) vec<vs> a(b, vs(c))
using vl = vector<ll>;
#define vvl(a, b, c) vec<vl> a(b, vl(c))
using vd = vector<double>;
#define vvd(a, b, c) vec<vd> a(b, vd(c))
using vc = vector<char>;
#define vvc(a, b, c) vec<vc> a(b, vc(c))
using vp = vector<P>;
#define vvp(a, b, c) vec<vp> a(b, vp(c))
using vt = vector<T>;
#define vvt(a, b, c) vec<vt> a(b, vt(c))
#define v3i(a, b, c, d) vector<vector<vi>> a(b, vector<vi>(c, vi(d)))
#define v3d(a, b, c, d) vector<vector<vd>> a(b, vector<vd>(c, vd(d)))
#define v3m(a, b, c, d) vector<vector<vm>> a(b, vector<vm>(c, vm(d)))
#define PQ priority_queue<ll, vector<ll>, greater<ll>>
using seti = set<int>;
#define uset unordered_set
#define mset multiset
#define umap unordered_map
#define mmap multimap

// マクロ 繰り返し
#define _overloadrep(_1, _2, _3, name, ...) name
#define _rep(i, n) for (int i = 0; i < n; i++)
#define repi(i, m, n) for (int i = m; i < n; i++)
#define rep(...) _overloadrep(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rer(i, n) for (int i = n; i >= 0; i--)
#define reri(i, m, n) for (int i = m; i >= n; i--)
#define rer(...) _overloadrep(__VA_ARGS__, reri, _rer, )(__VA_ARGS__)
#define fora(a, b) for (auto &&a : b)
#define forg(gi, ve)                                                           \
  for (int gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].from, t = ve[gi].to, \
                                              c = ve[gi].cost, true);          \
       gi++)

// マクロ 定数
#define k4 10101
#define k5 101010
#define k6 1010101
#define k7 10101010
const int inf = (int)1e9 + 100;
const ll linf = (ll)1e18 + 100;
const double eps = 1e-9;
const int y4[] = {-1, 1, 0, 0};
const int x4[] = {0, 0, -1, 1};
const int y8[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int x8[] = {1, 0, -1, 0, 1, -1, 1, -1};

// マクロ省略形 関数等
#define arsz(a) (sizeof(a) / sizeof(a[0]))
#define s(a) (a.size())
#define mp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

//@拡張系 こう出来るべきというもの

// 埋め込み 存在を意識せずに機能を増やされているもの
//  境界チェック付きvector
namespace std_vector_bounds_checking {
using namespace std;
template <class T, class A = std::allocator<T>>
struct vector : std::vector<T, A> {
  using std::vector<T, A>::vector;
  typename std::vector<T>::reference
  operator[](typename std::vector<T>::size_type n) {
    return this->at(n);
  }
};
} // namespace std_vector_bounds_checking
namespace std {
template <> class hash<std::pair<signed, signed>> {
public:
  size_t operator()(const std::pair<signed, signed> &x) const {
    return hash<ll>()(((ll)x.first << 32) + x.second);
  }
};
template <> class hash<std::pair<ll, ll>> {
public:
  size_t operator()(const std::pair<ll, ll> &x) const {
    return hash<ll>()(((ll)x.first << 32) + x.second);
  }
};
} // namespace std
template <typename T> istream &operator>>(istream &iss, vector<T> &vec) {
  for (T &x : vec)
    iss >> x;
  return iss;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
template <typename V, typename H>
void resize(vector<V> &vec,
            const H head) { // 再帰の終端。 可変長templateの長さが 0
                            // になるとこっちが呼ばれる。
  vec.resize(head);
}
template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &head, const T... tail) {
  vec.resize(head);
  for (auto &v : vec)
    resize(v, tail...);
}
template <class T> T pop(set<T> &set) {
  T res = *set.begin();
  set.erase(set.find(res));
  return res;
}
template <class T> T pop(mset<T> &set) {
  T res = *set.begin();
  set.erase(set.find(res));
  return res;
}
template <class T> T popBack(set<T> &set) {
  T res = *set.rbegin();
  set.erase(set.find(res));
  return res;
}
template <class T> T popBack(mset<T> &set) {
  T res = *set.rbegin();
  set.erase(set.find(res));
  return res;
}
template <class T> inline void sort(vector<T> &a) { sort(a.begin(), a.end()); };
template <class T> inline void rsort(vector<T> &a) {
  sort(a.begin(), a.end(), greater<T>());
};
template <class T> inline void sort(vector<T> &a, int len) {
  sort(a.begin(), a.begin() + len);
};
template <class T> inline void rsort(vector<T> &a, int len) {
  sort(a.begin(), a.begin() + len, greater<T>());
};
template <class T> inline void sort2(vector<vector<T>> &a) {
  for (int i = 0, n = a.size(); i < n; i++)
    sort(a[i]);
}
template <class T> inline void rsort2(vector<vector<T>> &a) {
  for (int i = 0, n = a.size(); i < n; i++)
    rsort(a[i]);
}
template <typename A, size_t N, typename T> void fill(A (&a)[N], const T &v) {
  rep(i, N) a[i] = v;
}
template <typename A, size_t N, size_t O, typename T>
void fill(A (&a)[N][O], const T &v) {
  rep(i, N) rep(j, O) a[i][j] = v;
}
template <typename A, size_t N, size_t O, size_t P, typename T>
void fill(A (&a)[N][O][P], const T &v) {
  rep(i, N) rep(j, O) rep(k, P) a[i][j][k] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, typename T>
void fill(A (&a)[N][O][P][Q], const T &v) {
  rep(i, N) rep(j, O) rep(k, P) rep(l, Q) a[i][j][k][l] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
          typename T>
void fill(A (&a)[N][O][P][Q][R], const T &v) {
  rep(i, N) rep(j, O) rep(k, P) rep(l, Q) rep(m, R) a[i][j][k][l][m] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
          size_t S, typename T>
void fill(A (&a)[N][O][P][Q][R][S], const T &v) {
  rep(i, N) rep(j, O) rep(k, P) rep(l, Q) rep(m, R) rep(n, S)
      a[i][j][k][l][m][n] = v;
}
template <typename V, typename T> void fill(V &x, const T &val) { x = val; }
template <typename V, typename T> void fill(vector<V> &vect, const T &val) {
  for (auto &v : vect)
    fill(v, val);
}
//@汎用便利関数 入力
template <typename T = int> T _in() {
  T x;
  cin >> x;
  return (x);
}
#define _overloadin(_1, _2, _3, _4, name, ...) name
#define in0() _in()
#define in1(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define in4(a, b, c, d) cin >> a >> b >> c >> d
#define in(...) _overloadin(__VA_ARGS__, in4, in3, in2, in1, in0)(__VA_ARGS__)

string sin() { return _in<string>(); }
double din() { return _in<double>(); }
ll lin() { return _in<ll>(); }
#define na(a, n) rep(i, n) cin >> a[i];
#define nad(a, n) rep(i, n) cin >> a[i], a[i]--;
#define na3(a, b, c, n) rep(i, n) cin >> a[i] >> b[i] >> c[i];
#define add2(a, b, n) rep(i, n) a.pb(in()), b.pb(in());
#define add2d(a, b, n) rep(i, n) a.pb(in() - 1), b.pb(in() - 1);
#define add3(a, b, c, n) rep(i, n) a.pb(in()), b.pb(in()), c.pb(in());
#define add3d(a, b, c, n) rep(i, n) a.pb(in() - 1), b.pb(in() - 1), c.pb(in());
#define na2(a, b, n) rep(i, n) cin >> a[i] >> b[i];
#define nt(a, h, w) rep(hi, h) rep(wi, w) cin >> a[hi][wi];
#define ntd(a, h, w) rep(hi, h) rep(wi, w) cin >> a[hi][wi], a[hi][wi]--;
#define ntp(a, h, w)                                                           \
  fill(a, '#');                                                                \
  rep(hi, 1, h + 1) rep(wi, 1, w + 1) cin >> a[hi][wi];
#define addn(a, n)                                                             \
  a.resize(n);                                                                 \
  na(a, n);
#define addnd(a, n)                                                            \
  a.resize(n);                                                                 \
  na(a, n);                                                                    \
  rep(i, n) a[i]--;

// 汎用便利関数 出力
template <class T> void out(T x) {
  typeid(x) == typeid(double) ? cout << fixed << setprecision(10) << x << endl
                              : cout << x << endl;
}
// デバッグ
#define debug(x)                                                               \
  cerr << x << " "                                                             \
       << "(L:" << __LINE__ << ")" << '\n';
// よく使うクラス、構造体
class UnionFind {
public:
  vi par, rank, sizes;
  int n, trees;
  UnionFind(int n) : n(n), trees(n) {
    par.resize(n), rank.resize(n), sizes.resize(n);
    rep(i, n) par[i] = i, sizes[i] = 1;
  }
  int root(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = root(par[x]);
  }
  int find(int x) { return root(x); }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return;
    if (rank[x] < rank[y])
      swap(x, y);
    trees--;
    par[y] = x;
    sizes[x] += sizes[y];
    if (rank[x] == rank[y])
      rank[x]++;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int size(int x) { return sizes[root(x)]; }
  // 順不同 umapなので
  vec<vi> sets() {
    vec<vi> res(trees);
    umap<int, vi> map;
    rep(i, n) map[root(i)].push_back(i);
    int i = 0;
    for (auto &&p : map) {
      int r = p.F;
      res[i].push_back(r);
      for (auto &&v : p.S) {
        if (r == v)
          continue;
        res[i].push_back(v);
      }
      i++;
    }
    return res;
  }
};

template <typename T> T minv(T a, T m);

template <typename T> class Modular {
public:
  using Type = typename decay<decltype(T::value)>::type;

  constexpr Modular() : value() {}
  template <typename U> Modular(const U &x) { value = normalize(x); }

  template <typename U> static Type normalize(const U &x) {
    Type v;
    if (-mod() <= x && x < mod())
      v = static_cast<Type>(x);
    else
      v = static_cast<Type>(x % mod());
    if (v < 0)
      v += mod();
    return v;
  }

  const Type &operator()() const { return value; }
  template <typename U> explicit operator U() const {
    return static_cast<U>(value);
  }
  constexpr static Type mod() { return T::value; }

  Modular &operator+=(const Modular &other) {
    if ((value += other.value) >= mod())
      value -= mod();
    return *this;
  }
  Modular &operator-=(const Modular &other) {
    if ((value -= other.value) < 0)
      value += mod();
    return *this;
  }
  template <typename U> Modular &operator+=(const U &other) {
    return *this += Modular(other);
  }
  template <typename U> Modular &operator-=(const U &other) {
    return *this -= Modular(other);
  }
  Modular &operator++() { return *this += 1; }
  Modular &operator--() { return *this -= 1; }
  Modular operator++(signed) {
    Modular result(*this);
    *this += 1;
    return result;
  }
  Modular operator--(signed) {
    Modular result(*this);
    *this -= 1;
    return result;
  }
  Modular operator-() const { return Modular(-value); }

  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, signed>::value,
                     Modular>::type &
  operator*=(const Modular &rhs) {
#ifdef _WIN32
    uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
    uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x),
             d, m;
    asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod()));
    value = m;
#else
    value = normalize(static_cast<int64_t>(value) *
                      static_cast<int64_t>(rhs.value));
#endif
    return *this;
  }
  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value,
                     Modular>::type &
  operator*=(const Modular &rhs) {
    int64_t q =
        static_cast<int64_t>(static_cast<double>(value) * rhs.value / mod());
    value = normalize(value * rhs.value - q * mod());
    return *this;
  }
  template <typename U = T>
  typename enable_if<!is_integral<typename Modular<U>::Type>::value,
                     Modular>::type &
  operator*=(const Modular &rhs) {
    value = normalize(value * rhs.value);
    return *this;
  }

  Modular &operator/=(const Modular &other) {
    return *this *= Modular(minv(other.value, mod()));
  }

  template <typename U>
  friend bool operator==(const Modular<U> &lhs, const Modular<U> &rhs);

  template <typename U>
  friend bool operator<(const Modular<U> &lhs, const Modular<U> &rhs);

  template <typename U>
  friend std::istream &operator>>(std::istream &stream, Modular<U> &number);

private:
  Type value;
};

template <typename T>
bool operator==(const Modular<T> &lhs, const Modular<T> &rhs) {
  return lhs.value == rhs.value;
}
template <typename T, typename U>
bool operator==(const Modular<T> &lhs, U rhs) {
  return lhs == Modular<T>(rhs);
}
template <typename T, typename U>
bool operator==(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) == rhs;
}

template <typename T>
bool operator!=(const Modular<T> &lhs, const Modular<T> &rhs) {
  return !(lhs == rhs);
}
template <typename T, typename U>
bool operator!=(const Modular<T> &lhs, U rhs) {
  return !(lhs == rhs);
}
template <typename T, typename U>
bool operator!=(U lhs, const Modular<T> &rhs) {
  return !(lhs == rhs);
}

template <typename T>
bool operator<(const Modular<T> &lhs, const Modular<T> &rhs) {
  return lhs.value < rhs.value;
}

template <typename T>
Modular<T> operator+(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) += rhs;
}
template <typename T, typename U>
Modular<T> operator+(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) += rhs;
}
template <typename T, typename U>
Modular<T> operator+(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) += rhs;
}

template <typename T>
Modular<T> operator-(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) -= rhs;
}
template <typename T, typename U>
Modular<T> operator-(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) -= rhs;
}
template <typename T, typename U>
Modular<T> operator-(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) -= rhs;
}

template <typename T>
Modular<T> operator*(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) *= rhs;
}
template <typename T, typename U>
Modular<T> operator*(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) *= rhs;
}
template <typename T, typename U>
Modular<T> operator*(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) *= rhs;
}

template <typename T>
Modular<T> operator/(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> operator/(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> operator/(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) /= rhs;
}

constexpr signed MOD = 998244353;
using mint = Modular<std::integral_constant<decay<decltype(MOD)>::type, MOD>>;
const int setModMax = k6;
bool was_set_mod = 0;
mint *fac, *finv, *inv;
void setMod() {
  int mo = MOD;
  fac = (mint *)malloc(setModMax * sizeof(mint));
  finv = (mint *)malloc(setModMax * sizeof(mint));
  inv = (mint *)malloc(setModMax * sizeof(mint));
  fac[0] = fac[1] = 1;
  finv[0] = 1;
  finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < setModMax; i++) {
    fac[i] = fac[i - 1] * i;
    inv[i] = -inv[mo % i] * (mo / i);
    finv[i] = finv[i - 1] * inv[i];
  }
}
mint com(ll n, ll r) {
  if (n < r || r < 0)
    return 0;
  if (!was_set_mod)
    setMod();
  return fac[n] * finv[r] * finv[n - r];
}
//
mint ncr(ll n, ll r) { return com(n, r); }
// n人にr個を配るとき、同じ人に何個配っても良い場合
// n個の組の合計でrを作る
mint nhr(ll n, ll r) { return com(n + r - 1, r); }

template <typename T> T minv(T a, T m) {
  T u = 0, v = 1;
  while (a != 0) {
    T t = m / a;
    m -= t * a;
    swap(a, m);
    u -= t * v;
    swap(u, v);
  }
  assert(m == 1);
  return u;
}

template <typename T, typename U>
Modular<T> mpow(const Modular<T> &a, const U &b) {
  assert(b >= 0);
  int x = a(), res = 1;
  U p = b;
  while (p > 0) {
    if (p & 1)
      (res *= x) %= MOD;
    (x *= x) %= MOD;
    p >>= 1;
  }
  return res;
}
template <typename T, typename U> Modular<T> mpow(const T &a, const U &b) {
  assert(b >= 0);
  int x = a, res = 1;
  U p = b;
  while (p > 0) {
    if (p & 1)
      (res *= x) %= MOD;
    (x *= x) %= MOD;
    p >>= 1;
  }
  return res;
}
template <typename T> string to_string(const Modular<T> &number) {
  return to_string(number());
}

template <typename T>
std::ostream &operator<<(std::ostream &stream, const Modular<T> &number) {
  return stream << number();
}

template <typename T>
std::istream &operator>>(std::istream &stream, Modular<T> &number) {
  typename common_type<typename Modular<T>::Type, int64_t>::type x;
  stream >> x;
  number.value = Modular<T>::normalize(x);
  return stream;
}

using PM = pair<mint, mint>;
using vm = vector<mint>;
#define _overloadvvm(_1, _2, _3, _4, name, ...) name

#define vvm1(a) vec<vm> a
#define vvm2(a, b) vec<vm> a(b)
#define vvm3(a, b, c) vec<vm> a(b, vm(c))
#define vvm4(a, b, c, d) vec<vm> a(b, vm(c, d))
#define vvm(...) _overloadvvm(__VA_ARGS__, vvm4, vvm3, vvm2, vvm1)(__VA_ARGS__)

int n, k, m, h, w, x, y, q;
mint cou;
vi a, b, c;

signed main() {
  int a, b, k;
  in(n, a, b, k);
  setMod();
  mint res = 0;
  rep(i, n + 1) {
    int r = k - a * i;
    if (r % b || r < 0)
      con;
    int bi = r / b;
    if (bi < 0 || bi > n)
      con;
    res += com(n, i) * com(n, bi);
  }
  cout << res << endl;
  return 0;
}


Fixed submission:
#pragma GCC optimize("O2")

// 注意点
// Tは3つの値を持つ構造
// だがワイルドカードとしても使っている
#include <bits/stdc++.h>
using namespace std;
//@起動時
struct initon {
  initon() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    srand((unsigned)clock() + (unsigned)time(NULL));
  };
} __initon;

//@必須構造
struct T {
  int f, s, t;
  T() { f = -1, s = -1, t = -1; }
  T(int f, int s, int t) : f(f), s(s), t(t) {}
  bool operator<(const T &r) const {
    return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t;
    // return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 大きい順
  }
  bool operator>(const T &r) const {
    return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t;
    // return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順
  }
  int operator[](int i) {
    assert(i < 3);
    return i == 0 ? f : i == 1 ? s : t;
  }
};

//@マクロ省略系 型,構造

#define int long long
#define ll long long
#define double long double
#define ull unsigned long long
using dou = double;
using itn = int;
using str = string;
using bo = bool;
using P = pair<int, int>;
#define F first
#define S second
#define vec vector
#define con continue
#define bre break
#define brk break
#define is ==
#define rs resize

// マクロ省略系 コンテナ
using vi = vector<int>;
#define vvi(a, b, c) vec<vi> a(b, vi(c))
using vb = vector<bool>;
#define vvb(a, b, c) vec<vb> a(b, vb(c))
using vs = vector<string>;
#define vvs(a, b, c) vec<vs> a(b, vs(c))
using vl = vector<ll>;
#define vvl(a, b, c) vec<vl> a(b, vl(c))
using vd = vector<double>;
#define vvd(a, b, c) vec<vd> a(b, vd(c))
using vc = vector<char>;
#define vvc(a, b, c) vec<vc> a(b, vc(c))
using vp = vector<P>;
#define vvp(a, b, c) vec<vp> a(b, vp(c))
using vt = vector<T>;
#define vvt(a, b, c) vec<vt> a(b, vt(c))
#define v3i(a, b, c, d) vector<vector<vi>> a(b, vector<vi>(c, vi(d)))
#define v3d(a, b, c, d) vector<vector<vd>> a(b, vector<vd>(c, vd(d)))
#define v3m(a, b, c, d) vector<vector<vm>> a(b, vector<vm>(c, vm(d)))
#define PQ priority_queue<ll, vector<ll>, greater<ll>>
using seti = set<int>;
#define uset unordered_set
#define mset multiset
#define umap unordered_map
#define mmap multimap

// マクロ 繰り返し
#define _overloadrep(_1, _2, _3, name, ...) name
#define _rep(i, n) for (int i = 0; i < n; i++)
#define repi(i, m, n) for (int i = m; i < n; i++)
#define rep(...) _overloadrep(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rer(i, n) for (int i = n; i >= 0; i--)
#define reri(i, m, n) for (int i = m; i >= n; i--)
#define rer(...) _overloadrep(__VA_ARGS__, reri, _rer, )(__VA_ARGS__)
#define fora(a, b) for (auto &&a : b)
#define forg(gi, ve)                                                           \
  for (int gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].from, t = ve[gi].to, \
                                              c = ve[gi].cost, true);          \
       gi++)

// マクロ 定数
#define k4 10101
#define k5 101010
#define k6 1010101
#define k7 10101010
const int inf = (int)1e9 + 100;
const ll linf = (ll)1e18 + 100;
const double eps = 1e-9;
const int y4[] = {-1, 1, 0, 0};
const int x4[] = {0, 0, -1, 1};
const int y8[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int x8[] = {1, 0, -1, 0, 1, -1, 1, -1};

// マクロ省略形 関数等
#define arsz(a) (sizeof(a) / sizeof(a[0]))
#define s(a) (a.size())
#define mp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

//@拡張系 こう出来るべきというもの

// 埋め込み 存在を意識せずに機能を増やされているもの
//  境界チェック付きvector
namespace std_vector_bounds_checking {
using namespace std;
template <class T, class A = std::allocator<T>>
struct vector : std::vector<T, A> {
  using std::vector<T, A>::vector;
  typename std::vector<T>::reference
  operator[](typename std::vector<T>::size_type n) {
    return this->at(n);
  }
};
} // namespace std_vector_bounds_checking
namespace std {
template <> class hash<std::pair<signed, signed>> {
public:
  size_t operator()(const std::pair<signed, signed> &x) const {
    return hash<ll>()(((ll)x.first << 32) + x.second);
  }
};
template <> class hash<std::pair<ll, ll>> {
public:
  size_t operator()(const std::pair<ll, ll> &x) const {
    return hash<ll>()(((ll)x.first << 32) + x.second);
  }
};
} // namespace std
template <typename T> istream &operator>>(istream &iss, vector<T> &vec) {
  for (T &x : vec)
    iss >> x;
  return iss;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
template <typename V, typename H>
void resize(vector<V> &vec,
            const H head) { // 再帰の終端。 可変長templateの長さが 0
                            // になるとこっちが呼ばれる。
  vec.resize(head);
}
template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &head, const T... tail) {
  vec.resize(head);
  for (auto &v : vec)
    resize(v, tail...);
}
template <class T> T pop(set<T> &set) {
  T res = *set.begin();
  set.erase(set.find(res));
  return res;
}
template <class T> T pop(mset<T> &set) {
  T res = *set.begin();
  set.erase(set.find(res));
  return res;
}
template <class T> T popBack(set<T> &set) {
  T res = *set.rbegin();
  set.erase(set.find(res));
  return res;
}
template <class T> T popBack(mset<T> &set) {
  T res = *set.rbegin();
  set.erase(set.find(res));
  return res;
}
template <class T> inline void sort(vector<T> &a) { sort(a.begin(), a.end()); };
template <class T> inline void rsort(vector<T> &a) {
  sort(a.begin(), a.end(), greater<T>());
};
template <class T> inline void sort(vector<T> &a, int len) {
  sort(a.begin(), a.begin() + len);
};
template <class T> inline void rsort(vector<T> &a, int len) {
  sort(a.begin(), a.begin() + len, greater<T>());
};
template <class T> inline void sort2(vector<vector<T>> &a) {
  for (int i = 0, n = a.size(); i < n; i++)
    sort(a[i]);
}
template <class T> inline void rsort2(vector<vector<T>> &a) {
  for (int i = 0, n = a.size(); i < n; i++)
    rsort(a[i]);
}
template <typename A, size_t N, typename T> void fill(A (&a)[N], const T &v) {
  rep(i, N) a[i] = v;
}
template <typename A, size_t N, size_t O, typename T>
void fill(A (&a)[N][O], const T &v) {
  rep(i, N) rep(j, O) a[i][j] = v;
}
template <typename A, size_t N, size_t O, size_t P, typename T>
void fill(A (&a)[N][O][P], const T &v) {
  rep(i, N) rep(j, O) rep(k, P) a[i][j][k] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, typename T>
void fill(A (&a)[N][O][P][Q], const T &v) {
  rep(i, N) rep(j, O) rep(k, P) rep(l, Q) a[i][j][k][l] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
          typename T>
void fill(A (&a)[N][O][P][Q][R], const T &v) {
  rep(i, N) rep(j, O) rep(k, P) rep(l, Q) rep(m, R) a[i][j][k][l][m] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
          size_t S, typename T>
void fill(A (&a)[N][O][P][Q][R][S], const T &v) {
  rep(i, N) rep(j, O) rep(k, P) rep(l, Q) rep(m, R) rep(n, S)
      a[i][j][k][l][m][n] = v;
}
template <typename V, typename T> void fill(V &x, const T &val) { x = val; }
template <typename V, typename T> void fill(vector<V> &vect, const T &val) {
  for (auto &v : vect)
    fill(v, val);
}
//@汎用便利関数 入力
template <typename T = int> T _in() {
  T x;
  cin >> x;
  return (x);
}
#define _overloadin(_1, _2, _3, _4, name, ...) name
#define in0() _in()
#define in1(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define in4(a, b, c, d) cin >> a >> b >> c >> d
#define in(...) _overloadin(__VA_ARGS__, in4, in3, in2, in1, in0)(__VA_ARGS__)

string sin() { return _in<string>(); }
double din() { return _in<double>(); }
ll lin() { return _in<ll>(); }
#define na(a, n) rep(i, n) cin >> a[i];
#define nad(a, n) rep(i, n) cin >> a[i], a[i]--;
#define na3(a, b, c, n) rep(i, n) cin >> a[i] >> b[i] >> c[i];
#define add2(a, b, n) rep(i, n) a.pb(in()), b.pb(in());
#define add2d(a, b, n) rep(i, n) a.pb(in() - 1), b.pb(in() - 1);
#define add3(a, b, c, n) rep(i, n) a.pb(in()), b.pb(in()), c.pb(in());
#define add3d(a, b, c, n) rep(i, n) a.pb(in() - 1), b.pb(in() - 1), c.pb(in());
#define na2(a, b, n) rep(i, n) cin >> a[i] >> b[i];
#define nt(a, h, w) rep(hi, h) rep(wi, w) cin >> a[hi][wi];
#define ntd(a, h, w) rep(hi, h) rep(wi, w) cin >> a[hi][wi], a[hi][wi]--;
#define ntp(a, h, w)                                                           \
  fill(a, '#');                                                                \
  rep(hi, 1, h + 1) rep(wi, 1, w + 1) cin >> a[hi][wi];
#define addn(a, n)                                                             \
  a.resize(n);                                                                 \
  na(a, n);
#define addnd(a, n)                                                            \
  a.resize(n);                                                                 \
  na(a, n);                                                                    \
  rep(i, n) a[i]--;

// 汎用便利関数 出力
template <class T> void out(T x) {
  typeid(x) == typeid(double) ? cout << fixed << setprecision(10) << x << endl
                              : cout << x << endl;
}
// デバッグ
#define debug(x)                                                               \
  cerr << x << " "                                                             \
       << "(L:" << __LINE__ << ")" << '\n';
// よく使うクラス、構造体
class UnionFind {
public:
  vi par, rank, sizes;
  int n, trees;
  UnionFind(int n) : n(n), trees(n) {
    par.resize(n), rank.resize(n), sizes.resize(n);
    rep(i, n) par[i] = i, sizes[i] = 1;
  }
  int root(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = root(par[x]);
  }
  int find(int x) { return root(x); }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return;
    if (rank[x] < rank[y])
      swap(x, y);
    trees--;
    par[y] = x;
    sizes[x] += sizes[y];
    if (rank[x] == rank[y])
      rank[x]++;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int size(int x) { return sizes[root(x)]; }
  // 順不同 umapなので
  vec<vi> sets() {
    vec<vi> res(trees);
    umap<int, vi> map;
    rep(i, n) map[root(i)].push_back(i);
    int i = 0;
    for (auto &&p : map) {
      int r = p.F;
      res[i].push_back(r);
      for (auto &&v : p.S) {
        if (r == v)
          continue;
        res[i].push_back(v);
      }
      i++;
    }
    return res;
  }
};

template <typename T> T minv(T a, T m);

template <typename T> class Modular {
public:
  using Type = typename decay<decltype(T::value)>::type;

  constexpr Modular() : value() {}
  template <typename U> Modular(const U &x) { value = normalize(x); }

  template <typename U> static Type normalize(const U &x) {
    Type v;
    if (-mod() <= x && x < mod())
      v = static_cast<Type>(x);
    else
      v = static_cast<Type>(x % mod());
    if (v < 0)
      v += mod();
    return v;
  }

  const Type &operator()() const { return value; }
  template <typename U> explicit operator U() const {
    return static_cast<U>(value);
  }
  constexpr static Type mod() { return T::value; }

  Modular &operator+=(const Modular &other) {
    if ((value += other.value) >= mod())
      value -= mod();
    return *this;
  }
  Modular &operator-=(const Modular &other) {
    if ((value -= other.value) < 0)
      value += mod();
    return *this;
  }
  template <typename U> Modular &operator+=(const U &other) {
    return *this += Modular(other);
  }
  template <typename U> Modular &operator-=(const U &other) {
    return *this -= Modular(other);
  }
  Modular &operator++() { return *this += 1; }
  Modular &operator--() { return *this -= 1; }
  Modular operator++(signed) {
    Modular result(*this);
    *this += 1;
    return result;
  }
  Modular operator--(signed) {
    Modular result(*this);
    *this -= 1;
    return result;
  }
  Modular operator-() const { return Modular(-value); }

  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, signed>::value,
                     Modular>::type &
  operator*=(const Modular &rhs) {
#ifdef _WIN32
    uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
    uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x),
             d, m;
    asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod()));
    value = m;
#else
    value = normalize(static_cast<int64_t>(value) *
                      static_cast<int64_t>(rhs.value));
#endif
    return *this;
  }
  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value,
                     Modular>::type &
  operator*=(const Modular &rhs) {
    int64_t q =
        static_cast<int64_t>(static_cast<double>(value) * rhs.value / mod());
    value = normalize(value * rhs.value - q * mod());
    return *this;
  }
  template <typename U = T>
  typename enable_if<!is_integral<typename Modular<U>::Type>::value,
                     Modular>::type &
  operator*=(const Modular &rhs) {
    value = normalize(value * rhs.value);
    return *this;
  }

  Modular &operator/=(const Modular &other) {
    return *this *= Modular(minv(other.value, mod()));
  }

  template <typename U>
  friend bool operator==(const Modular<U> &lhs, const Modular<U> &rhs);

  template <typename U>
  friend bool operator<(const Modular<U> &lhs, const Modular<U> &rhs);

  template <typename U>
  friend std::istream &operator>>(std::istream &stream, Modular<U> &number);

private:
  Type value;
};

template <typename T>
bool operator==(const Modular<T> &lhs, const Modular<T> &rhs) {
  return lhs.value == rhs.value;
}
template <typename T, typename U>
bool operator==(const Modular<T> &lhs, U rhs) {
  return lhs == Modular<T>(rhs);
}
template <typename T, typename U>
bool operator==(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) == rhs;
}

template <typename T>
bool operator!=(const Modular<T> &lhs, const Modular<T> &rhs) {
  return !(lhs == rhs);
}
template <typename T, typename U>
bool operator!=(const Modular<T> &lhs, U rhs) {
  return !(lhs == rhs);
}
template <typename T, typename U>
bool operator!=(U lhs, const Modular<T> &rhs) {
  return !(lhs == rhs);
}

template <typename T>
bool operator<(const Modular<T> &lhs, const Modular<T> &rhs) {
  return lhs.value < rhs.value;
}

template <typename T>
Modular<T> operator+(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) += rhs;
}
template <typename T, typename U>
Modular<T> operator+(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) += rhs;
}
template <typename T, typename U>
Modular<T> operator+(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) += rhs;
}

template <typename T>
Modular<T> operator-(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) -= rhs;
}
template <typename T, typename U>
Modular<T> operator-(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) -= rhs;
}
template <typename T, typename U>
Modular<T> operator-(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) -= rhs;
}

template <typename T>
Modular<T> operator*(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) *= rhs;
}
template <typename T, typename U>
Modular<T> operator*(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) *= rhs;
}
template <typename T, typename U>
Modular<T> operator*(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) *= rhs;
}

template <typename T>
Modular<T> operator/(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> operator/(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> operator/(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) /= rhs;
}

constexpr signed MOD = 998244353;
using mint = Modular<std::integral_constant<decay<decltype(MOD)>::type, MOD>>;
const int setModMax = k6;
bool was_set_mod = 0;
mint *fac, *finv, *inv;
void setMod() {
  was_set_mod = 1;
  int mo = MOD;
  fac = (mint *)malloc(setModMax * sizeof(mint));
  finv = (mint *)malloc(setModMax * sizeof(mint));
  inv = (mint *)malloc(setModMax * sizeof(mint));
  fac[0] = fac[1] = 1;
  finv[0] = 1;
  finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < setModMax; i++) {
    fac[i] = fac[i - 1] * i;
    inv[i] = -inv[mo % i] * (mo / i);
    finv[i] = finv[i - 1] * inv[i];
  }
}
mint com(ll n, ll r) {
  if (n < r || r < 0)
    return 0;
  if (!was_set_mod)
    setMod();
  return fac[n] * finv[r] * finv[n - r];
}
//
mint ncr(ll n, ll r) { return com(n, r); }
// n人にr個を配るとき、同じ人に何個配っても良い場合
// n個の組の合計でrを作る
mint nhr(ll n, ll r) { return com(n + r - 1, r); }

template <typename T> T minv(T a, T m) {
  T u = 0, v = 1;
  while (a != 0) {
    T t = m / a;
    m -= t * a;
    swap(a, m);
    u -= t * v;
    swap(u, v);
  }
  assert(m == 1);
  return u;
}

template <typename T, typename U>
Modular<T> mpow(const Modular<T> &a, const U &b) {
  assert(b >= 0);
  int x = a(), res = 1;
  U p = b;
  while (p > 0) {
    if (p & 1)
      (res *= x) %= MOD;
    (x *= x) %= MOD;
    p >>= 1;
  }
  return res;
}
template <typename T, typename U> Modular<T> mpow(const T &a, const U &b) {
  assert(b >= 0);
  int x = a, res = 1;
  U p = b;
  while (p > 0) {
    if (p & 1)
      (res *= x) %= MOD;
    (x *= x) %= MOD;
    p >>= 1;
  }
  return res;
}
template <typename T> string to_string(const Modular<T> &number) {
  return to_string(number());
}

template <typename T>
std::ostream &operator<<(std::ostream &stream, const Modular<T> &number) {
  return stream << number();
}

template <typename T>
std::istream &operator>>(std::istream &stream, Modular<T> &number) {
  typename common_type<typename Modular<T>::Type, int64_t>::type x;
  stream >> x;
  number.value = Modular<T>::normalize(x);
  return stream;
}

using PM = pair<mint, mint>;
using vm = vector<mint>;
#define _overloadvvm(_1, _2, _3, _4, name, ...) name

#define vvm1(a) vec<vm> a
#define vvm2(a, b) vec<vm> a(b)
#define vvm3(a, b, c) vec<vm> a(b, vm(c))
#define vvm4(a, b, c, d) vec<vm> a(b, vm(c, d))
#define vvm(...) _overloadvvm(__VA_ARGS__, vvm4, vvm3, vvm2, vvm1)(__VA_ARGS__)

int n, k, m, h, w, x, y, q;
mint cou;
vi a, b, c;

signed main() {
  int a, b, k;
  in(n, a, b, k);
  setMod();
  mint res = 0;
  rep(i, n + 1) {
    int r = k - a * i;
    if (r % b || r < 0)
      con;
    int bi = r / b;
    if (bi < 0 || bi > n)
      con;
    res += com(n, i) * com(n, bi);
  }
  cout << res << endl;
  return 0;
}