Buggy python submission (verdict: Time Limit Exceeded):
P = 998244353

N, S = map(int, input().split())
A = list(map(int, input().split()))

dp = [[[0]*3 for i in range(S+1)] for _ in range(N)]

dp[0][0][0] = 1
dp[0][0][1] = 1
if A[0] <= S:
    dp[0][A[0]][1] = 1

for i in range(1, N):
    dp[i][0][0] = 1
    dp[i][0][1] = dp[i-1][0][1] + 1
    dp[i][S][2] = dp[i-1][S][2] + dp[i-1][S][1]
    if A[i] == S:
        dp[i][S][2] += 1 + dp[i-1][0][1]
        dp[i][S][1] += dp[i-1][0][1] + 1
    elif A[i] < S:
        dp[i][A[i]][1] += 1 + dp[i-1][0][1]
    for j in range(1, S+1):
        dp[i][j][1] += dp[i-1][j][1]
        if j + A[i] < S:
            dp[i][j+A[i]][1] += dp[i-1][j][1]
        elif j + A[i] == S:
            dp[i][S][2] += dp[i-1][j][1]
            dp[i][S][1] += dp[i-1][j][1]
        dp[i][j][0] %= P
        dp[i][j][1] %= P
        dp[i][j][2] %= P

print(dp[N-1][S][2])

Fixed submission:
P = 998244353

N, S = map(int, input().split())
A = list(map(int, input().split()))

dp0 = [[0]*(S+1) for _ in range(N)]
dp1 = [[0]*(S+1) for _ in range(N)]
dp2 = [[0]*(S+1) for _ in range(N)]

dp0[0][0] = 1
dp1[0][0] = 1
if A[0] <= S:
    dp1[0][A[0]] = 1

for i in range(1, N):
    dp0[i][0] = 1
    dp1[i][0] = dp1[i-1][0] + 1
    dp2[i][S] = dp2[i-1][S] + dp1[i-1][S]
    if A[i] == S:
        dp2[i][S] += dp1[i-1][0] + 1
        dp1[i][S] += dp1[i-1][0] + 1
    elif A[i] < S:
        dp1[i][A[i]] += 1 + dp1[i-1][0]
    for j in range(1, S+1):
        dp1[i][j] += dp1[i-1][j]
        if j + A[i] < S:
            dp1[i][j+A[i]] += dp1[i-1][j]
        elif j + A[i] == S:
            dp2[i][S] += dp1[i-1][j]
            dp1[i][S] += dp1[i-1][j]
        dp0[i][j] %= P
        dp1[i][j] %= P
        dp2[i][j] %= P

print(dp2[N-1][S])

Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
data = list(map(int, input().split()))

MOD = 998244353
# dp = [[0]*(3000+1) for _ in range(N)]
# ans = 0

# for i, num in enumerate(data):
#     dp[i][num] = 1
#     for j in range(i):
#         for k in range(S-num, 0, -1):
#             if dp[j][k] >= 1:
#                 dp[j][k+num] += dp[j][k]
#             if k == num:
#                 dp[j][num] += 1
#     for j in range(i+1):
#         ans += dp[j][S]
#     ans %= MOD

# print(ans)

ans = 0
dp = [[] for _ in range(3001)]
dp[0] = [0]
for i, num in enumerate(data):
    for j in range(S-num, -1, -1):
        for item in dp[j]:
            dp[j+num] += [item+(1<<i)]

for item in dp[S]:
    for i in range(N+1):
        if item < (1<<i):
            a = N - i + 1
            break
    for i in range(N):
        if item & (1<<i) != 0:
            b = i + 1
            break
    ans = (a*b+ans)%MOD

print(ans)


Fixed submission:
P = 998244353

N, S = map(int, input().split())
A = list(map(int, input().split()))

dp0 = [[0]*(S+1) for _ in range(N)]
dp1 = [[0]*(S+1) for _ in range(N)]
dp2 = [[0]*(S+1) for _ in range(N)]

dp0[0][0] = 1
dp1[0][0] = 1
if A[0] <= S:
    dp1[0][A[0]] = 1

for i in range(1, N):
    dp0[i][0] = 1
    dp1[i][0] = dp1[i-1][0] + 1
    dp2[i][S] = dp2[i-1][S] + dp1[i-1][S]
    if A[i] == S:
        dp2[i][S] += dp1[i-1][0] + 1
        dp1[i][S] += dp1[i-1][0] + 1
    elif A[i] < S:
        dp1[i][A[i]] += 1 + dp1[i-1][0]
    for j in range(1, S+1):
        dp1[i][j] += dp1[i-1][j]
        if j + A[i] < S:
            dp1[i][j+A[i]] += dp1[i-1][j]
        elif j + A[i] == S:
            dp2[i][S] += dp1[i-1][j]
            dp1[i][S] += dp1[i-1][j]
        dp0[i][j] %= P
        dp1[i][j] %= P
        dp2[i][j] %= P

print(dp2[N-1][S])

Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
data = list(map(int, input().split()))

MOD = 998244353
# dp = [[0]*(3000+1) for _ in range(N)]
# ans = 0

# for i, num in enumerate(data):
#     dp[i][num] = 1
#     for j in range(i):
#         for k in range(S-num, 0, -1):
#             if dp[j][k] >= 1:
#                 dp[j][k+num] += dp[j][k]
#             if k == num:
#                 dp[j][num] += 1
#     for j in range(i+1):
#         ans += dp[j][S]
#     ans %= MOD

# print(ans)

ans = 0
dp = [[] for _ in range(3001)]
dp[0] = [0]
for i, num in enumerate(data):
    for j in range(S-num, -1, -1):
        for item in dp[j]:
            dp[j+num] += [item+(1<<i)]

for item in dp[S]:
    for i in range(N+1):
        if item < (1<<i):
            a = N - i + 1
            break
    for i in range(N):
        if item & (1<<i) != 0:
            b = i + 1
            break
    ans = (a*b+ans)%MOD

print(ans)


Fixed submission:
P = 998244353

N, S = map(int, input().split())
A = list(map(int, input().split()))

dp0 = [[0]*(S+1) for _ in range(N)]
dp1 = [[0]*(S+1) for _ in range(N)]
dp2 = [[0]*(S+1) for _ in range(N)]

dp0[0][0] = 1
dp1[0][0] = 1
if A[0] <= S:
    dp1[0][A[0]] = 1

for i in range(1, N):
    dp0[i][0] = 1
    dp1[i][0] = dp1[i-1][0] + 1
    dp2[i][S] = dp2[i-1][S] + dp1[i-1][S]
    if A[i] == S:
        dp2[i][S] += dp1[i-1][0] + 1
        dp1[i][S] += dp1[i-1][0] + 1
    elif A[i] < S:
        dp1[i][A[i]] += 1 + dp1[i-1][0]
    for j in range(1, S+1):
        dp1[i][j] += dp1[i-1][j]
        if j + A[i] < S:
            dp1[i][j+A[i]] += dp1[i-1][j]
        elif j + A[i] == S:
            dp2[i][S] += dp1[i-1][j]
            dp1[i][S] += dp1[i-1][j]
        dp0[i][j] %= P
        dp1[i][j] %= P
        dp2[i][j] %= P

print(dp2[N-1][S])

Buggy python submission (verdict: Runtime Error):
N, S = map(int, input().split())
data = list(map(int, input().split()))

MOD = 998244353
# dp = [[0]*(3000+1) for _ in range(N)]
# ans = 0

# for i, num in enumerate(data):
#     dp[i][num] = 1
#     for j in range(i):
#         for k in range(S-num, 0, -1):
#             if dp[j][k] >= 1:
#                 dp[j][k+num] += dp[j][k]
#             if k == num:
#                 dp[j][num] += 1
#     for j in range(i+1):
#         ans += dp[j][S]
#     ans %= MOD

# print(ans)

ans = 0
dp = [[] for _ in range(21)]
dp[0] = [0]
for i, num in enumerate(data):
    for j in range(S-num, -1, -1):
        for item in dp[j]:
            dp[j+num] += [item+(1<<i)]

for item in dp[S]:
    for i in range(N+1):
        if item < (1<<i):
            a = N - i + 1
            break
    for i in range(N):
        if item & (1<<i) != 0:
            b = i + 1
            break
    ans = (a*b+ans)%MOD

print(ans)


Fixed submission:
P = 998244353

N, S = map(int, input().split())
A = list(map(int, input().split()))

dp0 = [[0]*(S+1) for _ in range(N)]
dp1 = [[0]*(S+1) for _ in range(N)]
dp2 = [[0]*(S+1) for _ in range(N)]

dp0[0][0] = 1
dp1[0][0] = 1
if A[0] <= S:
    dp1[0][A[0]] = 1

for i in range(1, N):
    dp0[i][0] = 1
    dp1[i][0] = dp1[i-1][0] + 1
    dp2[i][S] = dp2[i-1][S] + dp1[i-1][S]
    if A[i] == S:
        dp2[i][S] += dp1[i-1][0] + 1
        dp1[i][S] += dp1[i-1][0] + 1
    elif A[i] < S:
        dp1[i][A[i]] += 1 + dp1[i-1][0]
    for j in range(1, S+1):
        dp1[i][j] += dp1[i-1][j]
        if j + A[i] < S:
            dp1[i][j+A[i]] += dp1[i-1][j]
        elif j + A[i] == S:
            dp2[i][S] += dp1[i-1][j]
            dp1[i][S] += dp1[i-1][j]
        dp0[i][j] %= P
        dp1[i][j] %= P
        dp2[i][j] %= P

print(dp2[N-1][S])

Buggy python submission (verdict: Runtime Error):
N, S = map(int, input().split())
data = list(map(int, input().split()))

MOD = 998244353
dp = [[0]*(S+1) for _ in range(N)]
ans = 0

for i, num in enumerate(data):
    dp[i][num] = 1
    for j in range(i):
        for k in range(S-num, 0, -1):
            if dp[j][k] >= 1:
                dp[j][k+num] += dp[j][k]
            if k == num:
                dp[j][num] += 1
    for j in range(i+1):
        ans += dp[j][S]
    ans %= MOD

print(ans)

Fixed submission:
P = 998244353

N, S = map(int, input().split())
A = list(map(int, input().split()))

dp0 = [[0]*(S+1) for _ in range(N)]
dp1 = [[0]*(S+1) for _ in range(N)]
dp2 = [[0]*(S+1) for _ in range(N)]

dp0[0][0] = 1
dp1[0][0] = 1
if A[0] <= S:
    dp1[0][A[0]] = 1

for i in range(1, N):
    dp0[i][0] = 1
    dp1[i][0] = dp1[i-1][0] + 1
    dp2[i][S] = dp2[i-1][S] + dp1[i-1][S]
    if A[i] == S:
        dp2[i][S] += dp1[i-1][0] + 1
        dp1[i][S] += dp1[i-1][0] + 1
    elif A[i] < S:
        dp1[i][A[i]] += 1 + dp1[i-1][0]
    for j in range(1, S+1):
        dp1[i][j] += dp1[i-1][j]
        if j + A[i] < S:
            dp1[i][j+A[i]] += dp1[i-1][j]
        elif j + A[i] == S:
            dp2[i][S] += dp1[i-1][j]
            dp1[i][S] += dp1[i-1][j]
        dp0[i][j] %= P
        dp1[i][j] %= P
        dp2[i][j] %= P

print(dp2[N-1][S])

Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
data = list(map(int, input().split()))

MOD = 998244353
dp = [[0]*(3001) for _ in range(N)]
ans = 0

for i, num in enumerate(data):
    dp[i][num] = 1
    for j in range(i):
        for k in range(3000-num, 0, -1):
            if dp[j][k] >= 1:
                dp[j][k+num] += dp[j][k]
            if k == num:
                dp[j][num] += 1
    for j in range(i+1):
        ans += dp[j][S]
    ans %= MOD

print(ans)

Fixed submission:
P = 998244353

N, S = map(int, input().split())
A = list(map(int, input().split()))

dp0 = [[0]*(S+1) for _ in range(N)]
dp1 = [[0]*(S+1) for _ in range(N)]
dp2 = [[0]*(S+1) for _ in range(N)]

dp0[0][0] = 1
dp1[0][0] = 1
if A[0] <= S:
    dp1[0][A[0]] = 1

for i in range(1, N):
    dp0[i][0] = 1
    dp1[i][0] = dp1[i-1][0] + 1
    dp2[i][S] = dp2[i-1][S] + dp1[i-1][S]
    if A[i] == S:
        dp2[i][S] += dp1[i-1][0] + 1
        dp1[i][S] += dp1[i-1][0] + 1
    elif A[i] < S:
        dp1[i][A[i]] += 1 + dp1[i-1][0]
    for j in range(1, S+1):
        dp1[i][j] += dp1[i-1][j]
        if j + A[i] < S:
            dp1[i][j+A[i]] += dp1[i-1][j]
        elif j + A[i] == S:
            dp2[i][S] += dp1[i-1][j]
            dp1[i][S] += dp1[i-1][j]
        dp0[i][j] %= P
        dp1[i][j] %= P
        dp2[i][j] %= P

print(dp2[N-1][S])