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

Fixed submission:
s = input()

sg = 0
sp = 0
ans = 0

for i in range(len(s)):
    if sp+1 <= sg and s[i] == 'g':
        sp += 1
        ans += 1
    elif sp+1 > sg and s[i] == 'p':
        sg += 1
        ans -= 1
    elif sp+1 <= sg and s[i] == 'p':
        sp += 1
    else:
        sg += 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()

subsg = []
subsp = []

sg = 0
sp = 0
ans = 0
for i in range(N):
    if s[i] == 'g':
        sg += 1
    else:
        sp += 1
    subsg.append(sg)
    subsp.append(sp)

for i in range(N):
    if subsp <= subsg:
        ans += 1
    
print(ans)
Problem p03037 (python)

Fixed submission:
def main():

    N,M=map(int,input().split())
    #undivList=[map(int,(input().split())) for _ in range(N)]
    undivList=[]
    for _ in range(M):
        l=map(int,input().split())
        undivList +=l
    atmax=max(undivList[0::2])
    atmin=min(undivList[1::2])
    
    if atmax>atmin:
        print(0)
    else:
        print(abs(atmax-atmin)+1)



if __name__== "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():

    N,M=map(int,input().split())
    #undivList=[map(int,(input().split())) for _ in range(N)]
    undivList=[]
    for _ in range(M):
        l=map(int,input().split())
        undivList +=l
    atmax=max(undivList[0::2])
    atmin=min(undivList[1::2])
    
    if atmax-atmin < 0:
		print(0)
    else:
		print(abs(atmax-atmin)+1)

    


if __name__== "__main__":
    main()
Problem p03262 (python)

Fixed submission:
import fractions
from functools import reduce

def main():

    N,X= map(int,input().split())
    targetList = list(map(int,input().split()))
    targetList.append(X)
    targetList.sort()
    diffList = []

    if N > 2:
        for i in range(N-1):
            diffList.append(targetList[i+1] - targetList[i])

    elif N==2:
        for i in targetList:
            diffList.append(i)
    else:
        print(abs(targetList[0]-targetList[1]))
        exit()

    print(reduce(fractions.gcd,diffList))

        
    
if __name__== "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def main():

    N,X= map(int,input().split())
    targetList = list(map(int,input().split()))
    targetList.append(X)
    targetList.sort()
    diffList = []

    if N !=1:

        for i in range(N-1):
            diffList.append(targetList[i+1] - targetList[i])
    else:
        print(abs(targetList[0]-targetList[1]))
        exit()


    print(reduce(math.gcd,diffList))

        
    
if __name__== "__main__":
    main()
Problem p03289 (python)

Fixed submission:
from collections import Counter

def main():

    S = list(input())
    head = S.pop(0)
    cList = []
    flag  = False
    flag1 = False
    flag2 = False

    if head == 'A':
        flag = True
    
    for i,j in enumerate(S[1:-1]):
        if j=='C':
            cList.append(i+1)
    if len(cList)==1:
        flag1=True
        S.pop(cList[0])
        
    if ''.join(S).islower():
        flag2 = True
    
    if flag and flag1 and flag2:
        print('AC')
    else:
        print('WA')


    
if __name__== "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import Counter

def main():

    S = list(input())
    head = S.pop(0)
    cList = []
    flag  = False
    flag1 = False
    flag2 = False

    if head == 'A':
        flag = True
    
    for i,j in enumerate(S[1:-2]):
        if j=='C':
            cList=S.pop(i+1)
    if len(cList)==1:
        flag1=True
    
    if ''.join(S).islower():
        flag2 = True
    
    if flag and flag1 and flag2:
        print('AC')
    else:
        print('WA')


    
if __name__== "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import Counter

def main():

    S = list(input())
    head = S.pop(0)
    cList = []
    flag  = False
    flag1 = False
    flag2 = False

    if head == 'A':
        flag = True
    
    for i,j in enumerate(S[1:-2]):
        if j=='C':
            cList=S.pop(i)
    if len(cList)==1:
        flag1=True
    
    if ''.join(S).islower():
        flag2 = True
    
    if flag and flag1 and flag2:
        print('AC')
    else:
        print('WA')


    
if __name__== "__main__":
    main()
Problem p03331 (python)

Fixed submission:

def main():
    ans = sum(list(map(int,list(input()))))
    if  ans!=1:
        print(ans)
    else:
        print(10)
 

    
if __name__== "__main__":
    main()

Buggy submission (verdict: Runtime Error):

def main():

    if sum(list(map(int,list(input())))) !=1:
        print(sum(list(map(int,list(input())))))
    else:
        print(10)
 

    
if __name__== "__main__":
    main()
Problem p03415 (python)

Fixed submission:

a=input()
b=input()
c=input()
print(a[0]+b[1]+c[2])

Buggy submission (verdict: Runtime Error):
a＝input()
b＝input()
c＝input()
print(a[0]+b[1]+c[2])

Buggy submission (verdict: Runtime Error):
a＝input()
b＝input()
c＝inpit()
print(a[0]+b[1]+c[2])
Problem p03555 (python)

Fixed submission:
a=input()
b=input()
print('YES' if a[-1::-1]==b else 'NO')

Buggy submission (verdict: Runtime Error):
a=input()
b=input'()
print('YES' if a[-1::-1]==b else 'NO')
Problem p03597 (python)

Fixed submission:
N = int(input())
A = int(input())
print(N*N-A)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = int(input())
print(N*N-a)
Problem p03657 (python)

Fixed submission:
a,b=map(int,input().split())
print( 'Possible' if a%3==0 or b%3==0 or (a+b)%3==0  else 'Impossible')

Buggy submission (verdict: Runtime Error):
print('Possible' if int(input())%3==0 else 'Impossible')
Problem p02678 (python)

Fixed submission:
from collections import deque
n, m = map(int, input().split())

adj_list = [[] for i in range(n)]

for i in range(m):
  _, __ = map(int, input().split())
  _ -= 1
  __ -= 1
  adj_list[_].append(__)
  adj_list[__].append(_)
  
distance = [None for i in range(n)]
updated_from = [None for i in range(n)]

newly_visited = deque([0])
distance[0] = 0

while len(newly_visited) > 0:
  now = newly_visited.popleft()
  for i in adj_list[now]:
    if distance[i] is not None: continue
    newly_visited.append(i)
    distance[i] = distance[now] + 1
    updated_from[i] = now

# i に到達できてれば distance[i] ==（0 から i までの距離）
# i に到達できてなければ distance[i] == None   
    
"""
print(distance)

for i in range(n):
  # i から 0 に行く経路を求める
  now = i
  path = [now]
  while now != 0:
    now = updated_from[now]
    path.append(now)
  print(i, path) 
"""

print("Yes")
for i in range(1, n):
  print(updated_from[i] + 1)

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())

adj_list = [[] for i in range(n)]

for i in range(m):
  _, __ = map(int, input().split())
  _ -= 1
  __ -= 1
  adj_list[_].append(__)
  adj_list[__].append(_)
  
distance = [None for i in range(n)]
updated_from = [None for i in range(n)]

newly_visited = deque([0])
distance[0] = 0

while len(newly_visited) > 0:
  now = newly_visited.popleft()
  for i in adj_list[now]:
    if distance[i] is not None: continue
    newly_visited.append(i)
    distance[i] = distance[now] + 1
    updated_from[i] = now

# i に到達できてれば distance[i] ==（0 から i までの距離）
# i に到達できてなければ distance[i] == None   
    
"""
print(distance)

for i in range(n):
  # i から 0 に行く経路を求める
  now = i
  path = [now]
  while now != 0:
    now = updated_from[now]
    path.append(now)
  print(i, path) 
"""

print("Yes")
for i in range(n):
  print(updated_from[i] + 1)
Problem p02946 (python)

Fixed submission:
k, x = map(int, input().split())
print(' '.join(map(str, list(range(x-k+1, x+k)))))

Buggy submission (verdict: Runtime Error):
k, x = map(int, input().split())
print(' '.join(list(range(x-k+1, x+k))))
Problem p03161 (python)

Fixed submission:
N, K = map(int, input().split(' '))
h = [None] + list(map(int, input().split(' ')))

dp = [None for _ in range(N+1)]
# dp[0], dp[1], ..., dp[N] が用意される

dp[1] = 0
for k in range(2, N+1): # k = 2, ..., N
  candidate = []
  for i in range(1, K+1): # i = 1, 2, ..., K
    if k - i <= 0:
      break
    candidate.append(dp[k-i] + abs(h[k] - h[k-i]))
  dp[k] = min(candidate)

print(dp[N])

Buggy submission (verdict: Runtime Error):
import numpy as np
N, K = map(int, input().split(' '))
h = np.array([-1] + list(map(int, input().split(' '))), dtype=np.int64)

dp = np.array([-1 for _ in range(N+1)], dtype=np.int64)
# dp[0], dp[1], ..., dp[N] が用意される

dp[1] = 0
for k in range(2, N+1): # k = 2, ..., N
  """
  candidate = []
  for i in range(1, K+1): # i = 1, 2, ..., K
    if k - i <= 0:
      break
    candidate.append(dp[k-i] + abs(h[k] - h[k-i]))
  """
  start_index = max(1, k - K + 1)
  # candidate = [
  #     dp[start_index] + abs(h[k] - h[start_index]),
  #     dp[start_index+1] + abs(h[k] - h[start_index+1]),
  #     ...,
  #     dp[k-1] + abs(h[k] - h[k-1]),
  # ]
  candidate = dp[start_index:k] + np.abs(h[k] - h[start_index:k])
  dp[k] = np.min(candidate)

print(dp[N])

Buggy submission (verdict: Runtime Error):
import numpy as np
N, K = map(int, input().split(' '))
h = np.array([-1] + list(map(int, input().split(' '))), dtype=np.int64)

dp = np.array([-1 for _ in range(N+1)], dtype=np.int64)
# dp[0], dp[1], ..., dp[N] が用意される

dp[1] = 0
for k in range(2, N+1): # k = 2, ..., N
  """
  candidate = []
  for i in range(1, K+1): # i = 1, 2, ..., K
    if k - i <= 0:
      break
    candidate.append(dp[k-i] + abs(h[k] - h[k-i]))
  """
  start_index = max(1, k - K + 1)
  # candidate = [
  #     dp[start_index] + abs(h[k] - h[start_index]),
  #     dp[start_index+1] + abs(h[k] - h[start_index+1]),
  #     ...,
  #     dp[k-1] + abs(h[k] - h[k-1]),
  # ]
  candidate = dp[start_index:k] + np.abs(h[k] - h[start_index:k])
  dp[k] = np.minimum(candidate)

print(dp[N])
Problem p03238 (python)

Fixed submission:
n=int(input())
if n==1:
  print('Hello World')
else:
  a=int(input());b=int(input())
  print(a+b)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,[input() for i in range(3)])
print('Hello World' if n==1 else a+b)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
print('Hello World' if n==1 else a+b)
Problem p03251 (python)

Fixed submission:
n,m,x,y=map(int,input().split());x=max(list(map(int,input().split()))+[x]);y=min(list(map(int,input().split()))+[y]);print('No War'if x<y else'War')

Buggy submission (verdict: Runtime Error):
n,m,x,y=map(int,input().split());x=max(list(map(int,input.split()))+[x]);y=min(list(map(int,input.split()))+[y]);print('No War'if x<y else'War')
Problem p03292 (python)

Fixed submission:
x = list(map(int, input().split()))
print(max(x) - min(x))

Buggy submission (verdict: Runtime Error):
x = map(int, input().split())
print(max(x) - min(x))

Buggy submission (verdict: Runtime Error):
a=list(map(int,split(input())))
print(max(a)-min(a))
Problem p03296 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n+1):
  if i==0 or i==n or a[i-1] != a[i]:
    if i!=0:
      ans += cnt // 2
    cnt = 1
  else:
    cnt += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n+1):
  if i==0 or i==n & a[i-1] != a[i]:
    if i!=0:
      ans += cnt // 2
    cnt = 1
  else:
    cnt += 1
print(ans)
Problem p03611 (python)

Fixed submission:
import numpy as np;c=[0]*10**5;input()
for i in map(int,input().split()):
    c[i]+=1
print(max([sum(c[i:i+3]) for i in range(10**5)]))

Buggy submission (verdict: Runtime Error):
c=[0]*114514;input();for i in map(int,input().split()):;    c[i]+=1;print(max([sum(c[i:i+3]) for i in range(100000)]))
Problem p03719 (python)

Fixed submission:
p=list(map(int,input().split()));print('Yes' if p[0]<=p[2]<=p[1] else 'No')

Buggy submission (verdict: Runtime Error):
p=map(int,input().split());print('Yes'if p[0]<=p[2]<=p[1]else'No')

Buggy submission (verdict: Runtime Error):
p=map(int,input().split());print('Yes'if p[0<=p[2]<=p[1]else'No')
Problem p03737 (python)

Fixed submission:
print(''.join([chr(ord(i[0])+ord('A')-ord('a')) for i in input().split()]))

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
if a==b: print('EQUAL')
elif a>b: print('GREATER')
else: print('LESS')
Problem p02787 (python)

Fixed submission:
# coding: utf-8
# Your code here!
def main():
    import math
    h,n = map(int, input().split())
    aa = [0]*(n+1)
    bb = [0]*(n+1)
    mp = [[None for _ in range(n+1)] for _ in range(h+1)]
    # 体力i 技の種類j
    for j in range(1, n+1):
      mp[0][j] = 0
      aa[j], bb[j] = map(int, input().split())
    for i in range(1, h+1):
        mp[i][0] = float("inf")
    for j in range(1, n+1):
        for i in range(1, h+1):
        	mp[i][j] = min(mp[i][j-1], mp[max(0, i - aa[j])][j] + bb[j])
    print(mp[h][n])

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import math
h,n = map(int, input().split())
aa = [None]
bb = [None]
mp = []
for _ in range(h + 1):
  	mpp = []
	for __ in range(n+1):
      mpp.append(None)
    mp.append(mpp)
# 体力i 技の種類j
for j in range(1, n+1):
  a, b = map(int, input().split())
  aa.append(a)
  bb.append(b)

for i in range(1, h+1):
    mp[i][0] = float("inf")
for j in range(1, n+1):
    for i in range(1, h+1):
        if i - aa[j] >= 1:
          # print(i, j, i - aa[j])
          mp[i][j] = min(mp[i][j-1], mp[i - aa[j]][j] + bb[j])
        else:
          mp[i][j] = min(mp[i][j-1], bb[j])
print(mp[h][n])
Problem p03161 (python)

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

dp = [0] + [float("inf") for _ in range(n - 1)]

for i in range(1, n):
    for j in range(1, min(i, k) + 1):
        dp[i] = min(dp[i], dp[i - j] + abs(hs[i - j] - hs[i]))
print(dp[i])

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
hs = list(map(int, input().split()))

dp = [float("inf") in range(n)]

for i in range(1, n):
    for j in range(min(i, k)):
        dp[i] = min(dp[i], dp[j] + abs(hs[j] - hs[i]))

print(dp[i])
Problem p02678 (python)

Fixed submission:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M=MI()
    edge = [[] for _ in range(N)]
    for i in range(M):
        a,b = MI_()
        edge[a].append(b)
        edge[b].append(a)
    queue = deque([0])
    dist = [inf]*N
    dist[0] = 0
    ans = [-1]*N
    while(queue):
        v = queue.popleft()
        for to in edge[v]:
            if(dist[to]==inf):
                ans[to] = v+1
                queue.append(to)
                dist[to] = dist[v] + 1

    print("Yes")
    print(*ans[1:],sep="\n")

    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
AB = []
ans = [-1] * (n) #####

edge = [[] for _ in range(n)] #edge[i] := 頂点iから伸びてる辺の行き先のリスト #####

for i in range(m):
    a,b = map(int,input().split())
    edge[a].append(b)    
    edge[b].append(a)    
    
import collections
que = collections.deque()
que.append(0) #####
    
while que:
    x = que.popleft()
    
    for to in edge[x]:
        a = x
        b = to
        
        if ans[b] == -1: #####
            ans[b] = x + 1 #####
            que.append(b)
            
print("Yes")
print(*ans,sep="\n")
Problem p03005 (python)

Fixed submission:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N, K = MI()
    if K == 1:
        print(0)
    else:
        print(N-K)
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import copy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():

    N = I()
    XY = LLIN(N)
    XY.sort()
    if N == 1:
        print(1)
        exit()
    
    count = defaultdict(int)
    for i, (x1, y1) in enumerate(XY):
        for j, (x2, y2) in enumerate(XY[i+1:]):
            dx, dy = x1 - x2, y1 - y2
            count[(dx, dy)] += 1
    print(N - max(count.values()))
    
    
                        
if __name__ == '__main__':
    main()
Problem p03043 (python)

Fixed submission:
N, K = map(int, input().split())
ans = 0
for i in range(1, N + 1):
    percent = 1
    point = i
    while K > point:
        percent /= 2
        point *= 2
    ans += percent
print(ans/N)

Buggy submission (verdict: Runtime Error):
from math import log2, ceil
N, K = map(int, input().split())
ans = 0
for i in range(1, N + 1):
    percent = (1 / 2)**(log2(ceil(K / i)))
    ans += percent
print(ans/N)
Problem p03050 (python)

Fixed submission:
import math
N = int(input())
ans=0
for i in range(1,int(math.sqrt(N)+1)):
    if i==N:
        continue
    if N//(N//i-1)!=N%((N//i-1)):
        continue
    else:
        #print(i,N//i-1,N//(N//i-1),N%((N//i-1)))
        ans+=N//i-1
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
ans=0
for i in range(1,int(math.sqrt(N)+1)):
    if N//(N//i-1)!=N%((N//i-1)):
        continue
    else:
        #print(i,N//i-1,N//(N//i-1),N%((N//i-1)))
        ans+=N//i-1
print(ans)
Problem p03064 (python)

Fixed submission:

def dp_table(*counts):  # dp[x][y]を作りたかったら dp_table(xのサイズ,yのサイズ)
    if counts:
        return [dp_table(*counts[1:]) for _ in range(counts[0])]
    else:
        return 0


def main():

    N = int(input())
    A = [int(input()) for _ in range(N)]
    mod = 998244353
    ans = pow(3, N, mod)
    sum_A = sum(A)
    dp = [[0] * (sum_A+1) for i in range(N)]
    # dp[i][j]: i番目までの中から辺をいくつか選んで、長さがjになるパターン数

    # init
    dp[0][A[0]] = 1
    dp[0][0] = 2  # 他の色のうちどちらに入れるかで2通り

    # init2
    dp2 = [[0] * (sum_A+1) for i in range(N)]  # ある二色でsum_Aを等分するパターンを数える
    dp2[0][A[0]] = 1
    dp2[0][0] = 1  # 今度は片方に集中したパターン

    # dp
    sum_now = A[0]
    for i in range(1, N):
        a = A[i]
        sum_now += a
        for length in range(sum_now+1):
            # A[i]を追加しないのなら他の２食のうちどちらに入れるかで2倍選択肢がある
            if length >= a:
                dp[i][length] = dp[i - 1][length - a] + \
                    (dp[i - 1][length] << 1)
            else:
                dp[i][length] = dp[i-1][length] << 1
            dp[i][length] %= mod

        for length in range(min(sum_now + 1, sum_A // 2 + 1)):
            if length >= a:
                dp2[i][length] = dp2[i - 1][length - a] + dp2[i - 1][length]
            else:
                dp2[i][length] = dp2[i-1][length]
            dp2[i][length] %= mod
    # print(sum(dp[N-1][sum_A//2]))
    # print(dp)
    ans -= 3*sum(dp[N-1][(sum_A+1)//2:])
    if sum_A % 2 == 0:
        ans += 3*dp2[N-1][sum_A//2]
    print(ans % mod)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

def dp_table(*counts):  # dp[x][y]を作りたかったら dp_table(xのサイズ,yのサイズ)
    if counts:
        return [dp_table(*counts[1:]) for _ in range(counts[0])]
    else:
        return 0


def main():

    N = int(input())
    A = [int(input()) for i in range(N)]
    mod = 998244353
    ans = pow(3, N, mod)
    sum_A = sum(A)
    dp = dp_table(N, sum_A + 1)
    # dp[i][j]: i番目までの中から辺をいくつか選んで、長さがjになるパターン数

    # init
    dp[0][A[0]] = 1
    dp[0][0] = 2  # 他の色のうちどちらに入れるかで2通り

    # init2
    dp2 = dp_table(N, sum_A+1)  # ある二色でsum_Aを等分するパターンを数える
    dp2[0][A[0]] = 1
    dp2[0][0] = 1  # 今度は片方に集中したパターン

    # dp
    sum_now = A[0]
    for i in range(1, N):
        a = A[i]
        sum_now += a
        for length in range(sum_now+1):
            # A[i]を追加しないのなら他の２食のうちどちらに入れるかで2倍選択肢がある
            if length >= a:
                dp[i][length] = dp[i - 1][length - a] + dp[i - 1][length] * 2
            else:
                dp[i][length] = dp[i-1][length]*2
            dp[i][length] %= mod

        for length in range(min(sum_now + 1, sum_A // 2 + 1)):
            if length >= a:
                dp2[i][length] = dp2[i - 1][length - a] + dp2[i - 1][length]
            else:
                dp2[i][length] = dp2[i-1][length]
            while (DP2[i][j] > mod):
                DP2[i][j] -= mod
            dp2[i][length] %= mod
    # print(sum(dp[N-1][sum_A//2]))
    # print(dp)
    ans -= 3*sum(dp[N-1][(sum_A+1)//2:])
    if sum_A % 2 == 0:
        ans += 3*dp2[N-1][sum_A//2]
    print(ans % mod)


if __name__ == '__main__':
    main()