Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math

N = int(input())
tmp = 0
sum = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            tmp = math.gcd(i,j)
            sum = sum + math.gcd(tmp,k)
            
print(sum)

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = int(input())
a = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            a = a + int(gcd(i,j,k))
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

# gcd(*numbers):
   # return reduce(math.gcd, numbers)

#def gcd_list(numbers):
   # return reduce(math.gcd, numbers)

N = int(input())
a = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            a = a + int(reduce(math.gcd,{i,j,k}))
print(a)

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = int(input())
a = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            a = a + int(gcd(i,j,k))
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = int(input())
a = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            a = a + int(gcd(i,j,k))
print(a)

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = int(input())
a = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            a = a + int(gcd(i,j,k))
print(a)
Buggy python submission (verdict: Runtime Error):
import sympy
sympy.divisors(10**9)

n = int(input())
L = len(sympy.divisors(n))
i,j = sympy.divisors(n)[L//2-1], sympy.divisors(n)[L//2]

if (n**0.5).is_integer():
    print(int(2*(n**0.5-1)))
else:
    print(i+j-2)

Fixed submission:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n = int(input())
L = len(make_divisors(n))
i,j = make_divisors(n)[L//2-1], make_divisors(n)[L//2]

if (n**0.5).is_integer():
    print(int(2*(n**0.5-1)))
else:
    print(i+j-2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
ans = [0]*n

for i in range(n):
    tmp = A.index(i+1)
    ans[i] = tmp+1
    
print(' '.join([str(n) for n in ans]))

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
ans = [0]*n

for i,j in enumerate(A):
    ans[j-1] = i+1    
print(' '.join([str(n) for n in ans]))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
ans = [0]*n

for i in range(n):
    tmp = A.index(i+1)
    ans[i] = tmp+1
    
print(' '.join([str(n) for n in ans]))

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
ans = [0]*n

for i,j in enumerate(A):
    ans[j-1] = i+1    
print(' '.join([str(n) for n in ans]))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
ans = []

for i in range(n):
    tmp = A.index(i+1)
    ans.append(tmp+1)
    
print(' '.join([str(n) for n in ans]))

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
ans = [0]*n

for i,j in enumerate(A):
    ans[j-1] = i+1    
print(' '.join([str(n) for n in ans]))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n,k,q = map(int,input().split())
A = []
ans = np.array([k]*n)
tmp = np.array([1]*n)
for _ in range(q):
    a = int(input())
    A.append(a)

for i in A:
    ans -= tmp
    ans[i-1] += 1

for j in ans:
    if j >= 1:
        print('Yes')
    else:
        print('No')

Fixed submission:
n,k,q = map(int,input().split())


if k <= q:
    
    A = []
    for _ in range(q):
        a = int(input())
        A.append(a)

    ans = [0]*n

    from collections import Counter
    cnt = Counter(A)
    for key,v in cnt.items():
        if v >= q-k+1:
            ans[key-1] = 1

    for i in range(n):
        if ans[i] == 0:
            print('No')
        else:
            print('Yes')
        
else:
    for _ in range(n):
        print('Yes')
Buggy python submission (verdict: Runtime Error):
A,B = int(input())
x = (B-A)/(A-1)+1
print(x)

Fixed submission:
A,B = map(int,input().split())
N = -(-(B-A)//(A-1)) + 1
print(N)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = []
for _ in range(n):
    tmp = int(input())
    A.append(tmp)

for i in range(n):
    L = A.pop(0)
    print(max(A))
    A.append(L)

Fixed submission:
n = int(input())
A = []
for _ in range(n):
    tmp = int(input())
    A.append(tmp)

m = max(A)
L = sorted(A)
L.sort(reverse = True)

if L[1] == m:
    for _ in range(n):
        print(m)
else:
    for i in range(n):
        if A[i] == m:
            A.pop(i)
            print(max(A))
            A.append(0)
        else:
            print(m)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
A =[]
for _ in range(m):
    l,r = map(int,input().split())
    tmp = [i for i in range(l,r+1)]
    A += tmp

from collections import Counter
cnt = Counter(A)
ans = []

for k,v in cnt.items():
    if v == m:
        ans.append(k)
print(len(ans))


Fixed submission:
n,m = map(int,input().split())
L = []
R = []

for _ in range(m):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)
tmp = min(R)-max(L)+1

if tmp >= 1:
    print(tmp)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
s = input()
t = [0]*len(s)

for i in range(len(s)):
    if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
        t[i] = 1

ans = []
tmp = 0
for j in t:
    if j == 1:
        tmp += 1
    else:
       ans.append(tmp)
       tmp = 0
print(max(ans))

Fixed submission:
s = input()
t = [0]*len(s)

for i in range(len(s)):
    if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
        t[i] = 1

ans = []
tmp = 0
for j in t:
    if j == 1:
        tmp += 1
    else:
       ans.append(tmp)
       tmp = 0
ans.append(tmp)

print(max(ans))
Buggy python submission (verdict: Runtime Error):
n = list(map(int,input().split()))
n.sort()
ans = ''.join(n)

if ans == 1479:
    print('YES')
else:
    print('NO')

Fixed submission:
n = list(map(str,input().split()))
n.sort()
ans = ''.join(n)

if ans == '1479':
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())

##2つの整数a,bに対し，最大公約数g,最小公倍数lとおくと，
##ab=gl

g = math.gcd(2,N)
l = 2*N/g

print(int(l))

Fixed submission:
a = 2
N = int(input())

#最大公約数
def gcd(a,N):
    while N!=0:
        a,N = N, a%N
    return a
##2つの整数a,bに対し，最大公約数g,最小公倍数lとおくと，
##ab=gl
print(int(a*N/gcd(a,N)))
Buggy python submission (verdict: Runtime Error):
A = []
B = []
C = []

for i in range(1,100):
    t0 = i
    t1 = i*100
    t2 = i*100*100
    A.append(t0)
    B.append(t1)
    C.append(t2)

d,n = map(int,input().split())

if d == 0:
    print(A[n-1])
elif d == 1:
    print(B[n-1])
else:
    print(C[n-1])

Fixed submission:
A = []
B = []
C = []

for i in range(1,101):
    t0 = i
    t1 = i*100
    t2 = i*100*100
    A.append(t0)
    B.append(t1)
    C.append(t2)

d,n = map(int,input().split())

if d == 0:
    if n == 100:
        print(101)
    else:
        print(A[n-1])
elif d == 1:
    if n == 100:
        print(100*101)
    else:
        print(B[n-1])
else:
    if n == 100:
        print(100*100*101)
    else:
        print(C[n-1])
Buggy python submission (verdict: Runtime Error):
a,b = int(input())
ab = a*b

if ab%2 == 0:
    print('Even')
else:
    print('Odd')

Fixed submission:
a,b = map(int,input().split())
ab = a*b

if ab%2 == 0:
    print('Even')
else:
    print('Odd')
Buggy python submission (verdict: Runtime Error):
s = list(str(input()))
if s[0]=='Y' and s[1]=='A' and s[2]=='K' and s[3]=='I':
    print('Yes')
else:
    print('No')

Fixed submission:
import sys
s = list(str(input()))
if len(s)<4:
    print('No')
    sys.exit()
if s[0]=='Y' and s[1]=='A' and s[2]=='K' and s[3]=='I':
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
s = list(map(str,input().split()))
if s[0]=='Y' and s[1]=='A' and s[2]=='K' and s[3]=='I':
    print('Yes')
else:
    print('No')

Fixed submission:
import sys
s = list(str(input()))
if len(s)<4:
    print('No')
    sys.exit()
if s[0]=='Y' and s[1]=='A' and s[2]=='K' and s[3]=='I':
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
a,op,b=input().split
a = int(a)
b = int(b)

if op == '+':
    print(a+b)
elif op == '-':
    print(a-b)

Fixed submission:
a,op,b=input().split()
a = int(a)
b = int(b)

if op == '+':
    print(a+b)
elif op == '-':
    print(a-b)
Buggy python submission (verdict: Runtime Error):
s = list(input())
ans = []

for i in s:
    if i == 'B':
        ans.pop()
    else:
        ans.append(i)

print("".join(ans))

Fixed submission:
s = list(input())
a = []
# print(s)
 
for i in range(len(s)):
    if s[i]== "0":
        a.append("0")
    elif s[i] == "1":
        a.append("1")
    else:
        if len(a)> 0:
            a.pop()
print("".join(a))
Buggy python submission (verdict: Time Limit Exceeded):
def main(n):
    ans = 0
    for k in range(1, n+1):
        for f in range(1,n//k+1):
            ans += k*f
    return ans

n = int(input())
print(main(n))

Fixed submission:
n = int(input())
ans = 0
for i in range(1,n+1):
    tmp = n//i
    ans += (tmp*(tmp+1)//2)*i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9+7
MAXN = 2*10**6+5
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

K = int(input())
S = input()
R = len(S)
N = K + R
ans = 0
for r in range(R,N+1):
    power = pow(25, N-r, MOD)
    ans += nCr(N, r) * power % MOD
    ans %= MOD
print(ans)


Fixed submission:
MOD = 10**9+7
MAXN = 2*10**6+5
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

K = int(input())
S = input()
R = len(S)
N = K + R
ans = 0
for r in range(R,N+1):
    power = pow(25, N-r, MOD)
    ans += nCr(N, r) * power % MOD
    ans %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline
MOD = 998244353

N, S = map(int, input().split())
A = list(map(int, (input().split())))
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += dp[i][j]*2
        dp[i+1][j] %= MOD
        if j+A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= MOD
print(dp[-1][S])

Fixed submission:
import sys
input = sys.stdin.buffer.readline
MOD = 998244353

N, S = map(int, input().split())
A = list(map(int, (input().split())))
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += dp[i][j]*2
        dp[i+1][j] %= MOD
        if j+A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= MOD
print(dp[-1][S])
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 998244353
MAXN = 2*(10**5)+10
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod


N, M, K = map(int, input().split())
ans = 0
for i in range(K+1):
    tmp = pow(M-1, N-i-1, MOD) * M % MOD
    tmp *= nCr(N-1,i,MOD)
    ans += tmp % MOD
    ans %= MOD
print(ans)

Fixed submission:
MOD = 998244353
MAXN = 2*(10**5)+10
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod


N, M, K = map(int, input().split())
ans = 0
for i in range(K+1):
    tmp = pow(M-1, N-i-1, MOD) * M % MOD
    tmp *= nCr(N-1,i,MOD)
    ans += tmp % MOD
    ans %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
# def input(): return sys.stdin.readline().rstrip()
# input = sys.stdin.readline
input = sys.stdin.buffer.readline

N = int(input())
A = sorted(zip(map(int, (input().split())) ,range(N)), reverse=True)

dp = [[0]*(N+1) for _ in range(N+1)]
ans = 0
for i in range(N):
    for j in range(i+1):
        dp[i+1][j]   = max(dp[i+1][j], dp[i][j] + A[i][0] * abs(A[i][1] - (N-1-(i-j))))
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + A[i][0] * abs(A[i][1] - j))

for i in range(N):
    ans = max(ans, dp[N][i])

print(ans)


Fixed submission:
import sys
# def input(): return sys.stdin.readline().rstrip()
# input = sys.stdin.readline
input = sys.stdin.buffer.readline

N = int(input())
A = sorted(zip(map(int, (input().split())) ,range(N)), reverse=True)

dp = [[0]*(N+1) for _ in range(N+1)]
ans = 0
for i in range(N):
    for j in range(i+1):
        dp[i+1][j]   = max(dp[i+1][j], dp[i][j] + A[i][0] * abs(A[i][1] - (N-1-(i-j))))
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + A[i][0] * abs(A[i][1] - j))

for i in range(N):
    ans = max(ans, dp[N][i])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = sorted(zip(map(int, (input().split())) ,range(N)), reverse=True)
# print(A)

dp = [[0]*(N+1) for _ in range(N+1)]
ans = 0
for i in range(N):
    for j in range(i+1):
        dp[i+1][j]   = max(dp[i+1][j], dp[i][j] + A[i][0] * abs(A[i][1] - (N-1-(i-j))))
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + A[i][0] * abs(A[i][1] - j))

for i in range(N):
    ans = max(ans, dp[N][i])

print(ans)


Fixed submission:
import sys
# def input(): return sys.stdin.readline().rstrip()
# input = sys.stdin.readline
input = sys.stdin.buffer.readline

N = int(input())
A = sorted(zip(map(int, (input().split())) ,range(N)), reverse=True)

dp = [[0]*(N+1) for _ in range(N+1)]
ans = 0
for i in range(N):
    for j in range(i+1):
        dp[i+1][j]   = max(dp[i+1][j], dp[i][j] + A[i][0] * abs(A[i][1] - (N-1-(i-j))))
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + A[i][0] * abs(A[i][1] - j))

for i in range(N):
    ans = max(ans, dp[N][i])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
N = int(input())
A = list(map(int, (input().split())))

ans = 0
for p in permutations(range(N)):
    tmp = 0
    for i in range(N):
        tmp += A[i] * abs(i-p[i])
    ans = max(ans, tmp)

print(ans)


Fixed submission:
import sys
# def input(): return sys.stdin.readline().rstrip()
# input = sys.stdin.readline
input = sys.stdin.buffer.readline

N = int(input())
A = sorted(zip(map(int, (input().split())) ,range(N)), reverse=True)

dp = [[0]*(N+1) for _ in range(N+1)]
ans = 0
for i in range(N):
    for j in range(i+1):
        dp[i+1][j]   = max(dp[i+1][j], dp[i][j] + A[i][0] * abs(A[i][1] - (N-1-(i-j))))
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + A[i][0] * abs(A[i][1] - j))

for i in range(N):
    ans = max(ans, dp[N][i])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

INF = 1001001001
N, X, Y = map(int, input().split())
d = [[INF]*N for _ in range(N)]
for i in range(N):
    d[i][i] = 0
for i in range(N-1):
    d[i][i+1] = 1
    d[i+1][i] = 1
d[X-1][Y-1] = 1
d[Y-1][X-1] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])

ans = [0]*(N-1)
for i in range(N-1):
    for j in range(i+1,N):
        ans[d[i][j]-1] += 1
for i in range(N-1):
    print(ans[i])


Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

N, X, Y = map(int, input().split())

ans = [0]*(N-1)
branch1 = X-1
branch2 = N-Y
cycle = Y-X+1
for i in range(cycle//2):   # 輪の1/2まで両側(2通り）で行ける
    ans[i] += cycle
if cycle%2==0:     # 輪は偶数（両方から同じ距離がある）
    ans[cycle//2-1] -= cycle//2
ans[0] -= 1

for i in range(branch1):
    for j in range(cycle//2):
        if cycle%2==0 and j==cycle//2-1:
            ans[i+j+1] += 1
        elif j == 0:    # 直線経路は除外
            ans[i+j+1] += 1
        else:
            ans[i+j+1] += 2
for i in range(branch2):
    for j in range(cycle//2):
        if cycle%2==0 and j==cycle//2-1:
            ans[i+j+1] += 1
        elif j == 0:    # 直線経路は除外
            ans[i+j+1] += 1
        else:
            ans[i+j+1] += 2

for i in range(branch1+branch2+1):   # 直線経路
    ans[i] += branch1+branch2+1 - i

for i in range(N-1):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int, input().split())
ans = [0]*(N-1)
for i in range(N-1):
    for j in range(i+1,N):
        dist = min(j-i, min(abs(X-1-i)+1+abs(Y-1-j), abs(Y-1-i)+1+abs(X-1-j)))
        ans[dist-1] += 1
for i in range(N-1):
    print(ans[i])

Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

N, X, Y = map(int, input().split())

ans = [0]*(N-1)
branch1 = X-1
branch2 = N-Y
cycle = Y-X+1
for i in range(cycle//2):   # 輪の1/2まで両側(2通り）で行ける
    ans[i] += cycle
if cycle%2==0:     # 輪は偶数（両方から同じ距離がある）
    ans[cycle//2-1] -= cycle//2
ans[0] -= 1

for i in range(branch1):
    for j in range(cycle//2):
        if cycle%2==0 and j==cycle//2-1:
            ans[i+j+1] += 1
        elif j == 0:    # 直線経路は除外
            ans[i+j+1] += 1
        else:
            ans[i+j+1] += 2
for i in range(branch2):
    for j in range(cycle//2):
        if cycle%2==0 and j==cycle//2-1:
            ans[i+j+1] += 1
        elif j == 0:    # 直線経路は除外
            ans[i+j+1] += 1
        else:
            ans[i+j+1] += 2

for i in range(branch1+branch2+1):   # 直線経路
    ans[i] += branch1+branch2+1 - i

for i in range(N-1):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = 1001001001

H, W, K = map(int, input().split())
S = [list(map(int, list(input()))) for _ in range(H)]
# print(S)

ans = INF
for b in range(1<<(H-1)):
    g = 0
    idx = [0]*H
    for i in range(H-1):
        if b>>i&1:
            g += 1
        idx[i+1] = g
    g += 1
    cnt = [[0]*W for _ in range(g)]
    for i in range(H):
        for j in range(W):
            cnt[idx[i]][j] += S[i][j]
    num = g-1
    now = [0]*g

    def add(j):
        global now
        for i in range(g):
            now[i] += cnt[i][j]
            if now[i] > K:
                return False
        return True

    for j in range(W):
        if add(j)==False:
            num += 1
            now = [0]*g
            if add(j)==False:
                num = INF
                break
    ans = min(ans, num)

print(ans)


Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = 1001001001

H, W, K = map(int, input().split())
S = [list(map(int, list(input()))) for _ in range(H)]
# print(S)

ans = INF
for b in range(1<<(H-1)):
    g = 0
    idx = [0]*H
    for i in range(H-1):
        if b>>i&1:
            g += 1
        idx[i+1] = g
    g += 1
    cnt = [[0]*W for _ in range(g)]
    for i in range(H):
        for j in range(W):
            cnt[idx[i]][j] += S[i][j]
    num = g-1
    now = [0]*g

    def add(j):
        global now
        for i in range(g):
            now[i] += cnt[i][j]
            if now[i] > K:
                return False
        return True

    for j in range(W):
        if add(j)==False:
            num += 1
            now = [0]*g
            if add(j)==False:
                num = INF
                break
    ans = min(ans, num)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
MOD = 998244353

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

ans = 0
dp = [[0]*(S+1) for _ in range(N+1)]
for i in range(N):
    dp[i][0] += 1       # Lがiからを足す
    for j in range(S+1):
        dp[i+1][j] += dp[i][j]             # A[i]を選ばない
        dp[i+1][j] %= MOD
        if j+A[i]<=S:
            dp[i+1][j+A[i]] += dp[i][j]    # A[i]を選ぶ
            dp[i+1][j+A[i]] %= MOD
    ans += dp[i+1][S]    # Rがiまでを足す
    ans %= MOD

print(ans)

Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
MOD = 998244353

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

ans = 0
dp = [0]*(S+1)
for i in range(N):
    dp[0] += 1      # Lがiからを足す
    next_dp = [0]*(S+1)
    for j in range(S+1):
        next_dp[j] += dp[j]             # A[i]を選ばない
        next_dp[j] %= MOD
        if j+A[i]<=S:
            next_dp[j+A[i]] += dp[j]    # A[i]を選ぶ
            next_dp[j] %= MOD
    dp = next_dp
    ans += dp[S]    # Rがiまでを足す
    ans %= MOD

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
MOD = 998244353

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

ans = 0
dp = [0]*(S+1)
for i in range(N):
    dp[0] += 1      # Lがiからを足す
    next_dp = [0]*(S+1)
    for j in range(S+1):
        next_dp[j] += dp[j]             # A[i]を選ばない
        next_dp[j] %= MOD
        if j+A[i]<=S:
            next_dp[j+A[i]] += dp[j]    # A[i]を選ぶ
            next_dp[j] %= MOD
    dp = next_dp
    ans += dp[S]    # Rがiまでを足す
    ans %= MOD

print(ans)


Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
MOD = 998244353

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

ans = 0
dp = [0]*(S+1)
for i in range(N):
    dp[0] += 1      # Lがiからを足す
    next_dp = [0]*(S+1)
    for j in range(S+1):
        next_dp[j] += dp[j]             # A[i]を選ばない
        next_dp[j] %= MOD
        if j+A[i]<=S:
            next_dp[j+A[i]] += dp[j]    # A[i]を選ぶ
            next_dp[j] %= MOD
    dp = next_dp
    ans += dp[S]    # Rがiまでを足す
    ans %= MOD

print(ans)