Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000000)

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

def pow(n, i):
    if i == 0: return 1
    elif i == 1: return n
    elif i % 2 == 0: return pow((n * n) % mod, i//2)
    else: return (pow((n * n) % mod, i//2) * n) % mod

factorial = [1] *(N+1)
revfactorial = [1] * (N+1)
for i in range(N):
    factorial[i+1] = (factorial[i] * (i+1)) % mod
revfactorial[N] = pow(factorial[N], mod-2)
for i in reversed(range(1, N)):
    revfactorial[i] = (revfactorial[i+1] * (i+1)) % mod

ans = 0
for a in range(N+1):
    if K >= A * a:
        if (K - A * a) % B == 0:
            b = (K - A * a) // B
            apatt = (factorial[N] * revfactorial[N - a] * revfactorial[a]) % mod
            bpatt = (factorial[N] * revfactorial[N - b] * revfactorial[b]) % mod
            ans += (apatt * bpatt) % mod
            ans %= mod
print(ans)

Fixed submission:
N, A, B, K = map(int, input().split())
mod = 998244353

def pow(n, i):
    if i == 0: return 1
    elif i == 1: return n
    elif i % 2 == 0: return pow((n * n) % mod, i//2)
    else: return (pow((n * n) % mod, i//2) * n) % mod

factorial = [1] *(N+1)
revfactorial = [1] * (N+1)
for i in range(N):
    factorial[i+1] = (factorial[i] * (i+1)) % mod
revfactorial[N] = pow(factorial[N], mod-2)
for i in reversed(range(1, N)):
    revfactorial[i] = (revfactorial[i+1] * (i+1)) % mod

ans = 0
for a in range(N+1):
    if K >= A * a:
        if (K - A * a) % B == 0:
            b = (K - A * a) // B
            apatt = (factorial[N] * revfactorial[N - a] * revfactorial[a]) % mod
            if b <= N: bpatt = (factorial[N] * revfactorial[N - b] * revfactorial[b]) % mod
            else: bpatt = 0
            ans += (apatt * bpatt) % mod
            ans %= mod
print(ans)

Buggy python submission (verdict: Runtime Error):
N, A, B, K = map(int, input().split())
mod = 998244353

def pow(n, i):
    if i == 0: return 1
    elif i == 1: return n
    elif i % 2 == 0: return pow((n * n) % mod, i//2)
    else: return (pow((n * n) % mod, i//2) * n) % mod

factorial = [1] *(N+1)
revfactorial = [1] * (N+1)
for i in range(N):
    factorial[i+1] = (factorial[i] * (i+1)) % mod
revfactorial[N] = pow(factorial[N], mod-2)
for i in reversed(range(1, N)):
    revfactorial[i] = (revfactorial[i+1] * (i+1)) % mod

ans = 0
for a in range(N+1):
    if K >= A * a:
        if (K - A * a) % B == 0:
            b = (K - A * a) // B
            apatt = (factorial[N] * revfactorial[N - a] * revfactorial[a]) % mod
            bpatt = (factorial[N] * revfactorial[N - b] * revfactorial[b]) % mod
            ans += (apatt * bpatt) % mod
            ans %= mod
print(ans)

Fixed submission:
N, A, B, K = map(int, input().split())
mod = 998244353

def pow(n, i):
    if i == 0: return 1
    elif i == 1: return n
    elif i % 2 == 0: return pow((n * n) % mod, i//2)
    else: return (pow((n * n) % mod, i//2) * n) % mod

factorial = [1] *(N+1)
revfactorial = [1] * (N+1)
for i in range(N):
    factorial[i+1] = (factorial[i] * (i+1)) % mod
revfactorial[N] = pow(factorial[N], mod-2)
for i in reversed(range(1, N)):
    revfactorial[i] = (revfactorial[i+1] * (i+1)) % mod

ans = 0
for a in range(N+1):
    if K >= A * a:
        if (K - A * a) % B == 0:
            b = (K - A * a) // B
            apatt = (factorial[N] * revfactorial[N - a] * revfactorial[a]) % mod
            if b <= N: bpatt = (factorial[N] * revfactorial[N - b] * revfactorial[b]) % mod
            else: bpatt = 0
            ans += (apatt * bpatt) % mod
            ans %= mod
print(ans)

Buggy python submission (verdict: Runtime Error):
N, A, B, K = map(int, input().split())
mod = 998244353

def pow(n, i):
    if i == 1: return n
    else:
        if i % 2 == 0:
            return pow((n * n) % mod, i//2)
        else: return (pow((n * n) % mod, i//2) * n) % mod

factorial = [1] *(N+1)
revfactorial = [1] * (N+1)
for i in range(N):
    factorial[i+1] = (factorial[i] * (i+1)) % mod
revfactorial[N] = pow(factorial[N], mod-2) % mod
for i in reversed(range(1, N)):
    revfactorial[i] = (revfactorial[i+1] * (i+1)) % mod

ans = 0
for a in range(N+1):
    if K >= A * a:
        if (K - A * a) % B == 0:
            b = (K - A * a) // B
            apatt = (factorial[N] * revfactorial[N - a] * revfactorial[a]) % mod
            bpatt = (factorial[N] * revfactorial[N - b] * revfactorial[b]) % mod
            ans += (apatt * bpatt) % mod
            ans %= mod
print(ans)

Fixed submission:
N, A, B, K = map(int, input().split())
mod = 998244353

def pow(n, i):
    if i == 0: return 1
    elif i == 1: return n
    elif i % 2 == 0: return pow((n * n) % mod, i//2)
    else: return (pow((n * n) % mod, i//2) * n) % mod

factorial = [1] *(N+1)
revfactorial = [1] * (N+1)
for i in range(N):
    factorial[i+1] = (factorial[i] * (i+1)) % mod
revfactorial[N] = pow(factorial[N], mod-2)
for i in reversed(range(1, N)):
    revfactorial[i] = (revfactorial[i+1] * (i+1)) % mod

ans = 0
for a in range(N+1):
    if K >= A * a:
        if (K - A * a) % B == 0:
            b = (K - A * a) // B
            apatt = (factorial[N] * revfactorial[N - a] * revfactorial[a]) % mod
            if b <= N: bpatt = (factorial[N] * revfactorial[N - b] * revfactorial[b]) % mod
            else: bpatt = 0
            ans += (apatt * bpatt) % mod
            ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
N, A, B, K = map(int, input().split())
mod = 998244353

def paint(i, k, memo = {}):
    if i == N-1:
        if k in [A, B, A+B, 0]: return 1
        else: return 0
    try:
        return memo[(i, k)]
    except KeyError:
        ans = 0
        for c in [A, B, A+B, 0]:
            ans += paint(i+1, k-c, memo)
            ans %= mod
        memo[(i, k)] = ans
        return ans
memo = {}
print(paint(0, K, memo))

Fixed submission:
N, A, B, K = map(int, input().split())
mod = 998244353

def pow(n, i):
    if i == 0: return 1
    elif i == 1: return n
    elif i % 2 == 0: return pow((n * n) % mod, i//2)
    else: return (pow((n * n) % mod, i//2) * n) % mod

factorial = [1] *(N+1)
revfactorial = [1] * (N+1)
for i in range(N):
    factorial[i+1] = (factorial[i] * (i+1)) % mod
revfactorial[N] = pow(factorial[N], mod-2)
for i in reversed(range(1, N)):
    revfactorial[i] = (revfactorial[i+1] * (i+1)) % mod

ans = 0
for a in range(N+1):
    if K >= A * a:
        if (K - A * a) % B == 0:
            b = (K - A * a) // B
            apatt = (factorial[N] * revfactorial[N - a] * revfactorial[a]) % mod
            if b <= N: bpatt = (factorial[N] * revfactorial[N - b] * revfactorial[b]) % mod
            else: bpatt = 0
            ans += (apatt * bpatt) % mod
            ans %= mod
print(ans)