Buggy python submission (verdict: Time Limit Exceeded):
# 拡張ユークリッド互除法
# gcd(a,b) と ax + by = gcd(a,b) の最小整数解を返す
def extgcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = extgcd(b % a, a)
        return g, x - (b // a) * y, y

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    gcd, x, y = extgcd(a,m)
    return (m+x%m)%m



N, A, B, K = map(int, input().split())

mod = 998244353
ans = 0
for a in range(N+1):
    if (K - A*a) % B == 0 and A*a <= K:
        b = (K- A*a) // B
        res_a = 1
        for i in range(1,N+1):
            res_a = res_a*i%mod
        for i in range(1,a+1):
            res_a = res_a*mod_inv(i,mod)%mod
        for i in range(1,(N-a)+1):
            res_a = res_a*mod_inv(i,mod)%mod
        res_b = 1
        for i in range(1,N+1):
            res_b = res_b*i%mod
        for i in range(1,b+1):
            res_b = res_b*mod_inv(i,mod)%mod
        for i in range(1,(N-b)+1):
            res_b = res_b*mod_inv(i,mod)%mod
        ans += res_a*res_b%mod

print(ans%mod)



Fixed submission:
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

N, A, B, K = map(int, input().split())

p = 998244353
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans = 0

for a in range(N+1):
    if (K - A*a) % B == 0 and A*a <= K:
        b = (K- A*a) // B
        ans += cmb(N, a, p)*cmb(N, b, p)%p

print(ans%p)

Buggy python submission (verdict: Time Limit Exceeded):
# 拡張ユークリッド互除法
# gcd(a,b) と ax + by = gcd(a,b) の最小整数解を返す
def extgcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = extgcd(b % a, a)
        return g, x - (b // a) * y, y

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    gcd, x, y = extgcd(a,m)
    return (m+x%m)%m



N, A, B, K = map(int, input().split())

mod = 998244353
ans = 0
for a in range(N+1):
    if (K - A*a) % B == 0 and A*a <= K:
        b = (K- A*a) // B
        res_a = 1
        for i in range(1,N+1):
            res_a = res_a*i%mod
        for i in range(1,a+1):
            res_a = res_a*mod_inv(i,mod)%mod
        for i in range(1,(N-a)+1):
            res_a = res_a*mod_inv(i,mod)%mod
        res_b = 1
        for i in range(1,N+1):
            res_b = res_b*i%mod
        for i in range(1,b+1):
            res_b = res_b*mod_inv(i,mod)%mod
        for i in range(1,(N-b)+1):
            res_b = res_b*mod_inv(i,mod)%mod
        ans += res_a*res_b%mod

print(ans%mod)



Fixed submission:
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

N, A, B, K = map(int, input().split())

p = 998244353
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans = 0

for a in range(N+1):
    if (K - A*a) % B == 0 and A*a <= K:
        b = (K- A*a) // B
        ans += cmb(N, a, p)*cmb(N, b, p)%p

print(ans%p)