Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03166 (python)

Fixed submission:
import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline

def a():
    N, M = map(int, rl().split())
    li = [[] for _ in range(N)]
    deg = [0] * N
    for _ in range(M):
        a, b = map(int, rl().split())
        a -= 1
        b -= 1
        li[a].append(b)
        deg[b] += 1
    d = collections.deque([i for i in range(N) if deg[i] == 0])
    dp = [0] * N
    while d:
        i = d.popleft()
        for j in li[i]:
            deg[j] -= 1
            if deg[j] == 0:
                dp[j] = max(dp[j] ,dp[i] + 1)
                d.append(j)
    print(max(dp))
a()

Buggy submission (verdict: Runtime Error):
import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline

def a():
    N, M = map(int, rl().split())
    li = [[] for _ in range(N)]
    deg = [0] * N
    for _ in range(M):
        a, b = map(int, rl().split())
        a -= 1
        b -= 1
        li[a].append(b)
        deg[b] = 1
    d = collections.deque([i for i in range(N) if deg[i] == 0])
    dp = [0] * N
    while d:
        i = d.popleft()
        for j in li[i]:
            deg[j] -= 1
            if deg[j] == 0:
                dp[j] = max(dp[j] ,dp[i] + 1)
                d.appendleft(j)
    print(max(dp))
a()

Buggy submission (verdict: Runtime Error):
import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline

def a():
    N, M = map(int, rl().split())
    li = [[] for _ in range(N)]
    deg = [0] * N
    for _ in range(M):
        a, b = map(int, rl().split())
        a -= 1
        b -= 1
        li[a].append(b)
        deg[b] = 1
    deg = collections.deque([i for i in range(N) if deg[i] == 0])
    dp = [0] * N
    while deg:
        i = deg.popleft()
        for j in li[i]:
            dpj = dp[j]
            dpi = dp[i]
            if dpj < dpi + 1:
                dp[j] = dpi + 1
            deg.appendleft(j)
    print(max(dp))
a()
Problem p03260 (python)

Fixed submission:
import sys

rm = lambda: map(int, sys.stdin.buffer.readline().split())

a, b = rm()
print('No' if a == 2 or b == 2 else 'Yes')

Buggy submission (verdict: Runtime Error):
import sys

ri = lambda: int(sys.stdin.readline())

print('No' if ri() == 2 or ri() == 2 else 'Yes')
Problem p03273 (python)

Fixed submission:
import sys
import numpy as np

rm = lambda: map(int, sys.stdin.readline().split())
rr = lambda: sys.stdin.readline().rstrip()

h, w = rm()
li = np.array([np.array(list(rr())) for _ in range(h)])
li2 = []
li3 = []
for i in li:
  if '#' in i:
    li2.append(i)
li2 = np.array(li2).T
for i in li2:
  if '#' in i:
    li3.append(i)
li3 = np.array(li3).T
for i in li3:
  print(''.join(i))

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))

h, w = rm()
li = np.array([np.array(rl()) for _ in range(h)])
li2 = np.array([])
li3 = np.array([])
for i in li:
  if '#' not in i:
    li2.append(i)
li2 = li2.T
for i in li2:
  if '#' not in i:
    li3.append(i)
for i in li3.T:
  print(''.join(i))
Problem p03474 (python)

Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b = rm()
s = rr()
for i in range(a):
    if s[i] not in '0123456789':
        print('No')
        exit()
for i in range(b):
    if s[a+1+i] not in '0123456789':
        print('No')
        exit()
if s[a] != '-':
  print('No')
  exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b = rm()
s = rr()
for i in range(a):
    if int(s[i]) not in range(10):
        print('No')
        exit()
for i in range(b):
    if int(s[a+1+i]) not in range(10):
        print('No')
        exit()
print('Yes')
Problem p03545 (python)

Fixed submission:
li = []
s = input()
li2 = []
for i in range(4):
  li.append(int(s[i]))
n1 = 4
def func(n, t):
  if n == 1:
    if t == li[0]:
      return True
    else:
      return False
  if func(n-1, t+li[n-1]):
    li2.append('-')
    return True
  elif func(n-1, t-li[n-1]):
    li2.append('+')
    return True
  else:
    return False
if func(n1, 7):
  print("{0}{4}{1}{5}{2}{6}{3}=7".format(li[0], li[1], li[2], li[3], li2[0], li2[1], li2[2]))

Buggy submission (verdict: Runtime Error):
li = []
s = input()
li2 = []
for i in range(4):
  li.append(s[i])
n1 = 4
def func(n, t):
  if t < 0:
    return False
  elif n == 0:
    if t == 0:
      return True
    else:
      return False
  elif func(n-1, t+li[n-1]):
    li2.append('-')
    return True
  elif func(n-1, t-li[n-1]):
    li2.append('+')
    return True
  else:
    return False
if func(n1, 7):
  print(f'{li[0]}{li2[0]}{li[2]}{li2[1]}{li[3]}{li2[3]}{li[4]}=7')
Problem p03549 (python)

Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m = rm()
print((m*1900 + (n-m)*100) * 2**m)

Buggy submission (verdict: Runtime Error):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m = ri()
print((m*1900 + (n-m)*100) * 2**m)
Problem p03633 (python)

Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
import fractions
from functools import reduce

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

n = ri()
li = [ri() for _ in range(n)]
ans = 1
for i in li:
  a = fractions.gcd(i, ans)
  ans = ans * i // a
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
import fractions
from functools import reduce

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

n = ri()
li = rl()
ans = 1
for i in range(n):
  lii = li[i]
  a = fractions.gcd(lii, ans)
  ans = ans * lii // a
print(ans)
Problem p03636 (python)

Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

s = rr()
print(s[0] + str(len(s) - 2) + s[-1])

Buggy submission (verdict: Runtime Error):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

s = rr()
print(s[0] + str(len(s-2)) + s[-1])
Problem p03657 (python)

Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b = rm()
if a%3 == 0 or b%3 == 0 or (a+b)%3 == 0:
  print('Possible')
else:
  print('Impossible')

Buggy submission (verdict: Runtime Error):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b, c = rm()
if a%3 == 0 or b%3 == 0 or (a+b)%3 == 0:
  print('Possible')
else:
  print('Impossible')
Problem p03681 (python)

Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m = rm()
if n == m:
    print((math.factorial(n) * math.factorial(m) * 2) % mod)
elif abs(n-m) == 1:
    print((math.factorial(n) * math.factorial(m)) % mod)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m = rm()
if n == m:
    print((math.factorial(n) * math.factorial(m) * 2) % mod)
elif abs(n-m) == 1:
    print((math.factorial(n) * math.factorial(m) % mod)
else:
    print(0)
Problem p03694 (python)

Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
li = rl()
print(max(li) - min(li))

Buggy submission (verdict: Runtime Error):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
li = rl()
print(max(li) - min(li)
Problem p03738 (python)

Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

 
a, b = ri(), ri()
if a == b:
  print('EQUAL')
elif a > b:
  print('GREATER')
else:
  print('LESS')

Buggy submission (verdict: Runtime Error):
a, b = ri(), ri()
if a == b:
  print('EQUAL')
elif a > b:
  print('GREATER')
else:
  print('LESS')
Problem p03760 (python)

Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

o = rr()
e = rr()
s = ''
for a, b in itertools.zip_longest(o, e, fillvalue=''):
  s += a + b
print(s)

Buggy submission (verdict: Runtime Error):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

o = rr()
e = rr()
s = ''
for a, b in itertools.zip_longest(o, e, fillvalu=''):
  s += a + b
print(s)
Problem p03828 (python)

Fixed submission:
import collections
n = int(input())
li = []
for k in range(2, n+1):
  for i in range(2, int(k**0.5)+1):
    while k % i == 0:
      k //= i
      li.append(i)
  if k != 1:
    li.append(k)
c = collections.Counter(li)
ans = 1
for k, v in c.items():
  ans *= (v+1)
print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = 1
for i in range(1, n):
  a *= i
li = []
temp = 0
while a % 2 == 0:
  temp += 1
  a //= 2
else:
  li.append(temp+1)
for i in range(3, int(a**0.5)+1, 2):
  temp = 0
  while a % i == 0:
    temp += 1
    a //= i
  else:
    li.append(temp+1)
ans = 1
for i in li:
  ans *= i
else:
  print(ans)
Problem p03944 (python)

Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

w, h, n = rm()
xleft = 0
xright = w
ytop = h
ybottom = 0
for _ in range(n):
  x, y, a = rm()
  if a == 1:
    xleft = max(xleft, x)
  elif a == 2:
    xright = min(xright, x)
  elif a == 4:
    ytop = min(ytop, y)
  else:
    ybottom = max(ybottom, y)
if xleft >= xright or ybottom >= ytop:
  print(0)
else:
  print((xright-xleft)*(ytop-ybottom))

Buggy submission (verdict: Runtime Error):
import numpy as np
w,h,n=map(int,raw_input().split())
mp = np.zeros((w,h))
for i in range(n):
  xi,yi,ai=map(int,raw_input().split())
  if ai==1: # x < xi
    mp[:xi,:] = 1
  elif ai==2: # x > xi
    mp[xi:,:] = 1
  elif ai==3: # y < yi
    mp[:,:yi] = 1
  elif ai==4: # y > yi
    mp[:,yi:] = 1
print w*h - np.sum(mp)
Problem p03997 (python)

Fixed submission:
print((int(input())+int(input()))*int(input())//2)

Buggy submission (verdict: Runtime Error):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rf = lambda: map(float, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

print('test')
Problem p02601 (python)

Fixed submission:
A, B, C = map(int, input().split())
K = int(input())

for _ in range(K):
    if A >= B:
        B *= 2
    elif B >= C:
        C *= 2
    else:
        C *= 2

if (B > A) and (C > B):
    print ('Yes')
else:
    print ('No')

Buggy submission (verdict: Runtime Error):
A, B, C = map(int, input().split())

for _ in range(K):
    if A >= B:
        B *= 2
    elif B >= C:
        C *= 2
    else:
        C *= 2

if (B > A) and (C > B):
    print ('Yes')
else:
    print ('No')
Problem p02609 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

N = int(input())
X = list(input())

lst = [-1] * (4 * N + 10)
lst[0] = 0
lst[1] = 1

def calc(x):
    if lst[x] != -1:
        return lst[x]
    count = 0
    y = x
    while y:
        if y % 2 == 1:
            count += 1
        y //= 2
    lst[x] = calc(x % count) + 1
    return lst[x]



count = X.count('1') #1の数

count1 = count - 1
count2 = count + 1

# print (count)
total1 = 0
total2 = 0

for i in range(N):
    if X[N - 1 - i] == '1':
        if count1 >= 1:
            total1 += pow(2, i, count1)
            total1 %= (count1)

        total2 += pow(2, i, count2)
        total2 %= (count2)
# print ('total', total)

for i in range(N):
    if X[i] == '1':
        if count1 == 0:
            print (0)
            continue
        tmp_total = (total1 - pow(2, N - 1 - i, count1)) % count1
        amari = tmp_total % count1
        ans = calc(amari) + 1
        print (ans)
    else: # 0の時
        tmp_total = (total2 + pow(2, N - 1 - i, count2)) % count2
        amari = tmp_total % (count2)
        ans = calc(amari) + 1
        print (ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)

N = int(input())
X = list(input())

lst = [-1] * (2 * N + 10)
lst[0] = 0
lst[1] = 1

def calc(x):
    if lst[x] != -1:
        return lst[x]
    count = 0
    y = x
    while y:
        if y % 2 == 1:
            count += 1
        y //= 2
    lst[x] = calc(x % count) + 1
    return lst[x]



count = X.count('1') #1の数

count1 = count - 1
count2 = count + 1

# print (count)
total1 = 0
total2 = 0

for i in range(N):
    if X[N - 1 - i] == '1':
        total1 += pow(2, i, count1)
        total1 %= (count1)

        total2 += pow(2, i, count2)
        total2 %= (count2)
# print ('total', total)

for i in range(N):
    if X[i] == '1':
        tmp_total = (total1 - pow(2, N - 1 - i, count1)) % count1
        amari = tmp_total % count1
        ans = calc(amari) + 1
        print (ans)
    else: # 0の時
        tmp_total = (total2 + pow(2, N - 1 - i, count2)) % count2
        amari = tmp_total % (count2)
        ans = calc(amari) + 1
        print (ans)

Buggy submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7

N = int(input())
X = list(input())

lst = [-1] * (N + 10)
lst[0] = 0
lst[1] = 1

def calc(x):
    if lst[x] != -1:
        return lst[x]
    count = 0
    y = x
    while y:
        if y % 2 == 1:
            count += 1
        y //= 2
    lst[x] = calc(x % count) + 1
    return lst[x]



count = X.count('1') #1の数
# print (count)
total = 0
for i in range(N):
    if X[N - 1 - i] == '1':
        total += pow(2, i, MOD)
        total %= MOD
# print ('total', total)

for i in range(N):
    if X[i] == '1':
        tmp_total = (total - pow(2, N - 1 - i, MOD)) % MOD
        amari = tmp_total % (count - 1)
        ans = calc(amari) + 1
        print (ans)
    else: # 0の時
        tmp_total = (total + pow(2, N - 1 - i, MOD)) % MOD
        amari = tmp_total % (count + 1)
        ans = calc(amari) + 1
        print (ans)
Problem p02645 (python)

Fixed submission:
S = str(input())

print (S[:3])

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

def check(lst):
    # print (set(lst))
    if (N == lst[0]) and (len(set(lst[:-1])) == 1):
        return True
    else:
        return False

def move(lst):
    tmp = [0] * (N + 1)
    for i in range(N):
        a = lst[i]
        left = max(0, i - a)
        right = min(N, i + a + 1)
        tmp[left] += 1
        tmp[right] -= 1
    for i in range(N):
        tmp[i + 1] += tmp[i]
    return tmp

for i in range(K):
    A = move(A)
    if check(A):
        # print (i)
        break

print (*A[:-1])
Problem p02698 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

from bisect import bisect_left

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

G = [[] for _ in range(N)]

for _ in range(N - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append(v)
    G[v].append(u)


root = 0

ans = [0] * N
check = [False] * N
check[root] = True

memo = [None] * N

INF = 10 ** 10
dp = [INF] * N

def dfs(x):
    tmp = bisect_left(dp, A[x])
    memo[x] = (tmp, dp[tmp])
    dp[tmp] = A[x]
    ans[x] = bisect_left(dp, INF)
    for next_ in G[x]:
        if check[next_]:
            continue
        check[next_] = True
        dfs(next_)
    j, a = memo[x]
    dp[j] = a

dfs(root)

print (*ans, sep = '\n')

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

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

G = [[] for _ in range(N)]

for _ in range(N - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append(v)
    G[v].append(u)


root = 0

ans = [0] * N
check = [False] * N
check[root] = True

memo = [None] * N

INF = 10 ** 10
dp = [INF] * N

def dfs(x):
    tmp = bisect_left(dp, A[x])
    memo[x] = (tmp, dp[tmp])
    dp[tmp] = A[x]
    ans[x] = bisect_left(dp, INF)
    for next_ in G[x]:
        if check[next_]:
            continue
        check[next_] = True
        dfs(next_)
    j, a = memo[x]
    dp[j] = a

dfs(root)

print (*ans, sep = '\n')
Problem p02734 (python)

Fixed submission:
def main():
    MOD = 998244353

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

    DP0 = [[0] * (S + 1) for _ in range(N + 1)]
    DP1 = [[0] * (S + 1) for _ in range(N + 1)]
    DP2 = [[0] * (S + 1) for _ in range(N + 1)]

    DP0[0][0] = 1

    for i in range(N):
        DP0[i + 1][0] = DP0[i][0] 
        DP1[i + 1][0] = DP0[i][0] + DP1[i][0]
        a = A[i]
        if a > S:
            for j in range(1, S + 1):
                DP1[i + 1][j] = DP1[i][j] #以前から合計jになっている場合のみOK
        else:
            for j in range(1, a):
                DP1[i + 1][j] = DP1[i][j] #以前から合計jになっている場合のみOK
            for j in range(a, S + 1):
                DP1[i + 1][j] = (DP1[i][j] + DP0[i][j - a] + DP1[i][j - a]) % MOD
                # DP[i + 1][j][1] = (DP[i][j][0] + DP[i][j][1] + DP[i + 1][j - a][1]) % MOD

        DP2[i + 1][S] = (DP1[i][S] + DP2[i][S])
        if a <= S:
            DP2[i + 1][S] += DP0[i][S - a] + DP1[i][S - a]
        DP2[i + 1][S] %= MOD

    print (DP2[N][S])

    # for i in range(N + 1):
    #     print (DP[i])

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
MOD = 998244353

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

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

for i in range(N):
    DP[i + 1][0][0] = DP[i][0][0] 
    DP[i + 1][0][1] = DP[i][0][0] + DP[i][0][1]
    a = A[i]
    for j in range(1, a):
        DP[i + 1][j][1] = (DP[i][j][0] + DP[i][j][1]) % MOD #以前から合計jになっている場合のみOK
    for j in range(a, S + 1):
        DP[i + 1][j][1] = (DP[i][j][0] + DP[i][j][1] + DP[i][j - a][0] + DP[i][j - a][1]) % MOD

    DP[i + 1][S][2] = (DP[i][S][1] + DP[i][S][2]) % MOD
    if a <= S:
        DP[i + 1][S][2] += DP[i][S - a][0] + DP[i][S - a][1]
    DP[i + 1][S][2] %= MOD

print (DP[N][S][2])

# for i in range(N + 1):
#     print (DP[i])