Buggy python submission (verdict: Time Limit Exceeded):
def calc_factorial(n):
    if n == 0:
        return 1
    else:
        num = 1
        for i in range(2, n+1):
            num = num * i
        return num


def calc_comb(n, k, fact_N):
    if 0 in [n, k, n-k]:
        return 1
    else:
        return int(fact_N/(calc_factorial(k)*calc_factorial(N-k)))


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

count = 0
num_A = 0
fact_N = calc_factorial(N)

for num_A in range(K//A + 1):
    left_beauty = K - num_A * A
    if left_beauty < 0:
        break
    # print("left_b: {}".format(left_beauty))

    if left_beauty % B == 0:
        # print("OK")
        num_B = int(left_beauty / B)

        comb_A = calc_comb(N, num_A, fact_N)
        comb_B = calc_comb(N, num_B, fact_N)
        count += comb_A * comb_B

        # print("comb_A: {}, comb_B: {}, count: {}".format(comb_A, comb_B, count))

print(count % 998244353)


Fixed submission:
N, A, B, K = map(int, input().split(" "))
mod = 998244353
ncr = [1] * (N + 1)
v = 1

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

pat = 0
for a in range(N + 1):
    if (K - (a * A) < 0):
        break
    if (K - (a * A)) % B == 0 and ((K - (a * A)) // B) <= N:
        pat += ncr[a] * ncr[(K - (a * A)) // B]
        pat %= mod

print(pat % mod)

Buggy python submission (verdict: Time Limit Exceeded):
def calc_factorial(n):
    if n == 0:
        return 1
    else:
        num = 1
        for i in range(2, n+1):
            num = num * i
        return num


def calc_comb(n, k, fact_N):
    if 0 in [n, k, n-k]:
        return 1
    else:
        return int(fact_N/(calc_factorial(k)*calc_factorial(N-k)))


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

count = 0
num_A = 0
max_A = int(K / A)
fact_N = calc_factorial(N)

for num_A in range(N):
    left_beauty = K - num_A * A
    if left_beauty < 0:
        break
    # print("left_b: {}".format(left_beauty))

    if left_beauty % B == 0:
        # print("OK")
        num_B = int(left_beauty / B)

        comb_A = calc_comb(N, num_A, fact_N)
        comb_B = calc_comb(N, num_B, fact_N)
        count += comb_A * comb_B

        # print("comb_A: {}, comb_B: {}, count: {}".format(comb_A, comb_B, count))

print(count % 998244353)


Fixed submission:
N, A, B, K = map(int, input().split(" "))
mod = 998244353
ncr = [1] * (N + 1)
v = 1

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

pat = 0
for a in range(N + 1):
    if (K - (a * A) < 0):
        break
    if (K - (a * A)) % B == 0 and ((K - (a * A)) // B) <= N:
        pat += ncr[a] * ncr[(K - (a * A)) // B]
        pat %= mod

print(pat % mod)

Buggy python submission (verdict: Time Limit Exceeded):
def calc_factorial(n):
    if n == 0:
        return 1
    else:
        num = 1
        for i in range(2, n+1):
            num = num * i
        return num


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

count = 0
num_A = 0
max_A = int(K / A)
fact_N = calc_factorial(N)

for num_A in range(N):
    left_beauty = K - num_A * A
    # print("left_b: {}".format(left_beauty))

    if left_beauty % B == 0:
        # print("OK")
        num_B = int(left_beauty / B)

        comb_A = int(fact_N/(calc_factorial(num_A)*calc_factorial(N-num_A)))
        comb_B = int(fact_N/(calc_factorial(num_B) * calc_factorial(N - num_B)))

        count += comb_A * comb_B

        # print("comb_A: {}, comb_B: {}, count: {}".format(comb_A, comb_B, count))

print(count % 998244353)


Fixed submission:
N, A, B, K = map(int, input().split(" "))
mod = 998244353
ncr = [1] * (N + 1)
v = 1

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

pat = 0
for a in range(N + 1):
    if (K - (a * A) < 0):
        break
    if (K - (a * A)) % B == 0 and ((K - (a * A)) // B) <= N:
        pat += ncr[a] * ncr[(K - (a * A)) // B]
        pat %= mod

print(pat % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N, A, B, K = list(map(int, input().split(" ")))

def kaijo(n):
    if n == 0:
        return 1
    else:
        num = 1
        for i in range(2, n+1):
            num = num * i
        return num

count = 0
num_AB = -1
while True:
    num_AB += 1
    if num_AB * (A+B) > K:
        break

    left_beauty = K - num_AB * (A+B)

    num_A = -1
    while True:
        num_A += 1
        # print("left_b: {}".format(left_beauty))
        if num_A * A > left_beauty:
            break
        elif num_A > N:
            break
        else:
            left_left_beauty = left_beauty - num_A * A

            if left_left_beauty % B == 0:
                num_B = int(left_left_beauty / B)
                num_nan = N - num_AB - num_A - num_B

                all_comb = kaijo(N)/(kaijo(num_AB)*kaijo(num_A)*kaijo(num_B)*kaijo(num_nan))
                count += int(all_comb)
                # print(num_A, num_B, num_AB, num_nan)
                # print(all_comb)

# print("=====")
print(count % 998244353)

Fixed submission:
N, A, B, K = map(int, input().split(" "))
mod = 998244353
ncr = [1] * (N + 1)
v = 1

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

pat = 0
for a in range(N + 1):
    if (K - (a * A) < 0):
        break
    if (K - (a * A)) % B == 0 and ((K - (a * A)) // B) <= N:
        pat += ncr[a] * ncr[(K - (a * A)) // B]
        pat %= mod

print(pat % mod)