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

Fixed submission:
s = input()

ans = True

while len(s) > 0:
    if len(s) == 1:
        print('No')
        exit(0)
    if s[0] == 'h' and s[1] == 'i':
        s = s[2:]
    else:
        ans = False
        break

if ans:
    print('Yes')
else:
    print('No')

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

ans = True

if len(s) == 1:
    print('No')
    exit(0)

while len(s) > 0:
    if s[0] == 'h' and s[1] == 'i':
        s = s[2:]
    else:
        ans = False
        break

if ans:
    print('Yes')
else:
    print('No')

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

ans = True

while len(s) > 0:
    if s[0] == 'h' and s[1] == 'i':
        s = s[2:]
    else:
        ans = False
        break

if ans:
    print('Yes')
else:
    print('No')
Problem p02885 (python)

Fixed submission:
a,b = input().split()
a=int(a)
b=int(b)
temp=a-2*b
if temp<=0:
  temp=0
print(temp)

Buggy submission (verdict: Runtime Error):
a,b = input().split()
a=int(a)
b=int(b)
temp=a-2b
if temp<=0:
  temp=0
print(temp)
Problem p03238 (python)

Fixed submission:
n=int(input())
if n==1:
    print("Hello World")
elif n==2:
    a=int(input())
    b=int(input())
    print(a+b)

Buggy submission (verdict: Runtime Error):
n=int(input())
if n==1:
    print("Hello Wrold ")
elif n==2
    a=int(input())
    b=int(input())
    print(a+b)
Problem p03469 (python)

Fixed submission:
y,m,d=input().split('/')

y=int(y)
y+=1
y=str(y)
print(y+'/'+m+'/'+d)

Buggy submission (verdict: Runtime Error):
y,m,d=input().split('/')

y=int(y)
y+=1
y=str(y)\
print(y+'/'+m+'/'+d)
Problem p03998 (python)

Fixed submission:
s1=input()
s2=input()
s3=input()
s_list=[s1, s2, s3]
next_item=0
while(1):
    if len(s_list[0])==0 and next_item==0:
        print("A")
        break
    elif len(s_list[1])==0 and next_item==1:
        print("B")
        break
    elif len(s_list[2])==0 and next_item==2:
        print("C")
        break
    temp=s_list[next_item][0]
    s_list[next_item]=s_list[next_item][1:]
    if(temp=='a'):
        next_item=0
    elif(temp=='b'):
        next_item=1
    else:
        next_item=2

Buggy submission (verdict: Runtime Error):
s1=input()
s2=input()
s3=input()
s_list=[s1, s2, s3]
next=0
while(len(s_list[0])>=1 and len(s_list[1])>=1 and len(s_list[2])>=1):
    temp=s_list[next][0]
    s_list[next]=s_list[next][1:]
    next=temp
if len(s_list[0])==0:
    print("A")
elif len(s_list[1])==0:
    print("B")
else:
    print("C")
Problem p02731 (python)

Fixed submission:
import sys, math

sys.setrecursionlimit(10 ** 9)
from collections import defaultdict

IA = lambda: map(int, input().split())
IAS = lambda: map(str, input().split())

sum=0
for i in range(10):
    sum+=1
n = int(input())
print("{:.12f}".format(pow(n, 3) / 27.0))

Buggy submission (verdict: Runtime Error):
import sys,math
sys.setrecursionlimit(10**9)
from collections import defaultdict
 
IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())
sum=100
for i in range(1:100):
  sum=sum+1
n=int(input())
print("{:.12f}".format(pow(n,3)/27.0))
Problem p02761 (python)

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


li_num = [ list(map(int,input().split())) for i in range(m)]

invalid = False

#print(n)
#print(m)
#print(li_num)

if n == 1:
  li_ans = [0]
else:
  li_ans = [0] * n
  li_ans[0] = 1

arr = list(map(list, set(map(tuple, li_num))))
arr.sort(key=lambda x: x[0])

if n != 1 and [1,0] in arr:
  invalid = True

#print(arr)

if not invalid:
    arr_keta = [x[0] for x in arr]
    if len(arr_keta) != len(set(arr_keta)):
        invalid = True

if invalid:
  print(-1)
else:
  for i in arr:
    s = i[0] - 1
    li_ans[s] = i[1]
  ans_num = int("".join(map(str, li_ans)))
  print(ans_num)

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


li_num = [ list(map(int,input().split())) for i in range(m)]

invalid = False

#print(n)
#print(m)
#print(li_num)

if n == 1:
  li_ans[0] = 0
else:
  li_ans = [0] * n
  li_ans[0] = 1

arr = list(map(list, set(map(tuple, li_num))))
arr.sort(key=lambda x: x[0])

if n != 1 and [1,0] in arr:
  invalid = True

#print(arr)

if not invalid:
    arr_keta = [x[0] for x in arr]
    if len(arr_keta) != len(set(arr_keta)):
        invalid = True

if invalid:
  print(-1)
else:
  for i in arr:
    s = i[0] - 1
    li_ans[s] = i[1]
  ans_num = int("".join(map(str, li_ans)))
  print(ans_num)
Problem p02767 (python)

Fixed submission:
from sys import stdin
 
n = int(input())
k = [int(x) for x in stdin.readline().rstrip().split()]

k.sort()

ave = round(sum(k) / len(k) )

#print(ave)

def calc_pow(n):
    i = pow(n - ave, 2) 
    return i
  
j = map(calc_pow, k)

print(sum(j))

Buggy submission (verdict: Runtime Error):
n = int(input())
k = [int(x) for x in stdin.readline().rstrip().split()]

k.sort()

ave = round(sum(k) / len(k) )

#print(ave)

def calc_pow(n):
    i = pow(n - ave, 2) 
    return i
  
j = map(calc_pow, k)

print(sum(j))
Problem p02801 (python)

Fixed submission:
C = input()
C_next = chr(ord(C) + 1)
print(C_next)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N, M = map(int, input().split())
P = [input().split() for _ in range(M)]
X = defaultdict(int)
ac = 0
wa = 0
for pi in P:
    i = int(pi[0])
    s = pi[1]
    if X[i-1] == 0:
        if s == 'WA':
            wa += 1
        else:
            ac += 1
            X[i-1] = 1

print(ac, wa)
Problem p02747 (python)

Fixed submission:
s = input()

if len(s)%2 == 0:
    x = len(s)//2
    if "hi"*x == s:
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

ans = "Yes"
for i in range(0, len(s), 2):
    if s[i] != "h" or s[i+1] != "i":
        ans = "No"
        break

print(ans)
Problem p02761 (python)

Fixed submission:
n, m = map(int, input().split())
s, c = [], []
for _ in range(m):
    _s, _c = map(int, input().split())
    s.append(_s-1)
    c.append(_c)

for i in range(1000):
    *t, = map(int, list(str(i)))

    if len(t) != n:
        continue

    ok = True
    for j in range(m):
        if t[s[j]] != c[j]:
            ok = False
            break
    if ok:
        print(i)
        quit()

print(-1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
s, c = [], []
for i in range(m):
    _s, _c = map(int, input().split())
    s.append(_s)
    c.append(_c)

for i in range(1000):
    *t, = map(int, list(str(i)))

    if len(t) != n:
        continue

    ok = True
    for j in range(m):
        if t[s[j]] != c[j]:
            ok = False
            break

    if ok:
        print(i)
        quit()

print(-1)
Problem p02814 (python)

Fixed submission:
import fractions
n, m = map(int, input().split())
*a, = map(int, input().split())

lcm = a[0]//2

for x in a:
    x //= 2
    g = fractions.gcd(lcm, x)
    if (lcm//g)%2 != (x//g)%2:
        print(0)
        quit()

    lcm = lcm*x//g

print((m//lcm + 1)//2)

Buggy submission (verdict: Runtime Error):
import math
import fractions
import functools
n, m = map(int, input().split())
*a, = map(int, input().split())

def lcm(a: int, b: int) -> int:
    return (a*b) // fractions.gcd(a, b)

l = functools.reduce(lcm, a)/2

ans = math.ceil((m//l)/2)
print(ans)
Problem p02971 (python)

Fixed submission:
n = int(input())
maxindex = maxvalue = 0
a = []
for i in range(n):
    _a = int(input())
    if maxvalue <= _a:
        maxvalue = _a
        maxindex = i
    a.append(_a)

for i in range(n):
    if i != maxindex:
        print(maxvalue)
        continue
    t = a[:]
    t.pop(i)
    print(max(t))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]

for i in range(n):
    t = a[:]
    print(max(t.pop(i)))
Problem p03000 (python)

Fixed submission:
n, x = map(int, input().split())
*l, = map(int, input().split())

d = 0
ans = 1
for i in range(n):
    d += l[i]
    if x < d:
        break
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
*l, = map(int, input().split())

d = 0
ans = 0
for i in range(n+1):
    if x < d:
        break
    d += l[i]
    ans += 1
print(ans)
Problem p03078 (python)

Fixed submission:
x, y, z, k = map(int, input().split())
*a, = sorted(map(int, input().split()), reverse=True)
*b, = sorted(map(int, input().split()), reverse=True)
*c, = sorted(map(int, input().split()), reverse=True)

ab = [a[i] + b[j] for j in range(y) for i in range(x)]
ab.sort(reverse=True)
ab = ab[:k]

abc = [ab[i] + c[j] for j in range(z) for i in range(len(ab))]

abc.sort(reverse=True)

for i in range(k):
    print(abc[i])

Buggy submission (verdict: Runtime Error):
import heapq
x, y, z, k = map(int, input().split())
n = [x, y, z]
if x*y*z < k:
    k = x*y*z

abc = []
for _ in range(3):
    *l, = sorted(map(int, input().split()), reverse=True)
    abc.append(l)

h = [[-(abc[0][0]+abc[1][0]+abc[2][0]), [0, 0, 0]]]
heapq.heapify(h)

index = [0, 0, 0]
se = h[:]

for _ in range(k):
    ans, iterate = heapq.heappop(h)
    print(-ans)

    for i in range(3):
        if n[i] <= iterate[i] + 1: continue

        iterate[i] += 1

        s = -(abc[0][iterate[0]]+abc[1][iterate[1]]+abc[2][iterate[2]])
        t = [s, iterate[:]]

        if t not in se:
            heapq.heappush(h, t)
            se.append(t)

        iterate[i] -= 1

Buggy submission (verdict: Runtime Error):
import heapq
x, y, z, k = map(int, input().split())
n = [x, y, z]
if x*y*z < k:
    k = x*y*z

abc = []
for _ in range(3):
    *l, = sorted(map(int, input().split()), reverse=True)
    abc.append(l)

h = [[-(abc[0][0]+abc[1][0]+abc[2][0]), [0, 0, 0]]]
heapq.heapify(h)

index = [0, 0, 0]
se = h[:]

for _ in range(k):
    ans, iter = heapq.heappop(h)
    print(-ans)

    for i in range(3):
        iter[i] += 1
        if iter[i] < n[i]:
            s = -(abc[0][iter[0]]+abc[1][iter[1]]+abc[2][iter[2]])
            t = [s, iter[:]]

            if t not in se:
                heapq.heappush(h, t)
                se.append(t)

        iter[i] -= 1

Buggy submission (verdict: Runtime Error):
import heapq
x, y, z, k = map(int, input().split())
n = [x, y, z]
abc = []
for _ in range(3):
    *l, = sorted(map(int, input().split()), reverse=True)
    abc.append(l)

h = [[-(abc[0][0]+abc[1][0]+abc[2][0]), [0, 0, 0]]]
heapq.heapify(h)

index = [0, 0, 0]
se = h[:]

for _ in range(k):
    ans, iter = heapq.heappop(h)
    print(-ans)

    for i in range(3):
        iter[i] += 1
        if iter[i] < n[i]:
            s = -(abc[0][iter[0]]+abc[1][iter[1]]+abc[2][iter[2]])
            t = [s, iter[:]]

            if t not in se:
                heapq.heappush(h, t)
                se.append(t)

        iter[i] -= 1
Problem p03087 (python)

Fixed submission:
n, q = map(int, input().split())
s = input()
numofac = [0]*len(s)
cnt = 0
for i in range(1, len(s)):
    if s[i-1] == "A" and s[i] == "C":
        cnt += 1
    numofac[i] = cnt

for _ in range(q):
    l, r = map(int, input().split())
    print(numofac[r-1]-numofac[l-1])

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

cusum = [0]*(n+1)
for i in range(len(s)):
    if s[i] == "A" and s[i+1] == "C":
        cusum[i+1] = cusum[i] + 1
    else:
        cusum[i+1] = cusum[i]

for _ in range(q):
    l, r = map(int, input().split())
    print(cusum[r-1] - cusum[l-1])
Problem p03160 (python)

Fixed submission:
n = int(input())
*h, = map(int, input().split())

dp = [float("inf")]*(n+1)
dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[i-1]+abs(h[i] - h[i-1]), dp[i])
    if i > 1:
        dp[i] = min(dp[i-2]+abs(h[i] - h[i-2]), dp[i])

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
*h, = map(int, input().split())

def rec(i: int, c: int) -> int:
    if i <= 0:
        return c
    elif i == 1:
        return rec(i-1, c+abs(h[i]-h[i-1]))

    return min(rec(i-1, c+abs(h[i]-h[i-1])), rec(i-2, c+abs(h[i]-h[i-2])))

print(rec(n-1, 0))

Buggy submission (verdict: Runtime Error):
n = int(input())
*h, = map(int, input().split())

def rec(i: int, c: int) -> int:
    if i == 0:
        return c
    elif i <= 1:
        return rec(i-1, c+abs(h[i]-h[i-1]))

    return min(rec(i-1, c+abs(h[i]-h[i-1])), rec(i-2, c+abs(h[i]-h[i-2])))

print(rec(n-1, 0))
Problem p03282 (python)

Fixed submission:
s = input()
k = int(input())

for _s in s:
    if _s == "1":
        if k == 1:
            print(1)
            break
        else:
            k -= 1
    else:
        print(_s)
        break

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

for _s in s:
    if _s == "1":
        if k == 1:
            print(1)
            break
        else:
            k -= 1
    else:
        print(i)
        break
Problem p03400 (python)

Fixed submission:
import math
n = int(input())
d, x = map(int, input().split())
ans = 0
for _ in range(n):
    a = int(input())
    ans += math.ceil(d/a)

print(ans + x)

Buggy submission (verdict: Runtime Error):
a,b=map(int, input().split())

cnt=0
for i in range(a,b):
    if str(i) == str(i)[::-1]:
        cnt+=1

print(cnt)
Problem p03624 (python)

Fixed submission:
s = sorted(set(input()))

alphabet = [chr(ord("a") + i) for i in range(26)]
ans = "None"
for actual, expected in zip(s, alphabet):
    if actual != expected:
        ans = expected
        break

if ans == "None" and s[len(s)-1] != "z":
    ans = alphabet[len(s)]
print(ans)

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

ans = "None"
for i in range(26):
    a = chr(ord("a") + i)
    if s[i] != a:
        ans = a
        break
print(ans)
Problem p03962 (python)

Fixed submission:
print(len(set(map(int, input().split()))))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
ans = [False]*100
ans[a] |= True
ans[b] |= True
ans[c] |= True

print(sum(ans))
Problem p04043 (python)

Fixed submission:
a, b, c = map(int, input().split())
print("YES" if a == b == 5 and c == 7 or a == c == 5 and b == 7 or b == c == 5 and a == 7 else "NO")

Buggy submission (verdict: Runtime Error):
n,l=map(int,input().split())
s=sorted([input() for i in range(n)])
print(*s,sep="")
Problem p03160 (python)

Fixed submission:
N = int(input())
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0

def calc_cost(now, next):
  global h_list
  global dp
  global N
  if next > N - 1: return
  if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):
    dp[next] = dp[now] + abs(h_list[next] - h_list[now])

for i in range(N):
  calc_cost(i, i + 1)
  calc_cost(i, i + 2)

print(dp[N - 1])

Buggy submission (verdict: Runtime Error):
def calc_cost(now, next):
  global h_list
  global N
  if next > N - 1: return
  if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):
    dp[next] = dp[now] + abs(h_list[next] - h_list[now])

  calc_cost(next, next + 1)
  calc_cost(next, next + 2)

N = int(input())
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0

calc_cost(0, 0)

print(dp[N - 1])

Buggy submission (verdict: Runtime Error):
def calc_cost(now, next):
  global h_list
  global N
  if next > N - 1: return
  if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):
    dp[next] = dp[now] + abs(h_list[next] - h_list[now])

  calc_cost(next, next + 1)
  calc_cost(next, next + 2)

N = int(input())
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0

calc_cost(0, 1)
calc_cost(0, 2)

print(dp[N - 1])
Problem p02755 (python)

Fixed submission:
tax = [int(n) for n in input().split()]

max_8tax = (tax[0]+1) / .08
min_8tax = tax[0] / .08
max_10tax = int((tax[1]+1) / .1) - 1
min_10tax = int(tax[1] / .1)

r = -1

for i in range(min_10tax, max_10tax):
    if min_8tax <= i and i < max_8tax:
        r = i
        break

print(r)

Buggy submission (verdict: Runtime Error):
tax = [int(n) for n in input().split()]

max_8tax = (tax[0]+1) / .08
min_8tax = (tax[0]) / .08)
max_10tax = int((tax[1]+1) / .1) - 1
min_10tax = int((tax[1]) / .1)

r = -1

for i in range(min_10tax, max_10tax):
    if min_8tax <= i and i < max_8tax:
        r = i
        break

print(r)
Problem p02742 (python)

Fixed submission:
h,w=map(int,input().split())

if h != 1 and w != 1:
    if h*w % 2 == 1:
        print(str(int(h*w/2) + 1))
    else:
        print(str(int(h*w/2)))
else:
    print(str(1))

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())

if h != 1 and w != 1:
    if h*w % 2 == 1:
        print(str(int(h*w/2) + 1))
    else:
        print(str(int(h*w/2)))
elif:
    print(str(1))
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())
ans = 1

for i in range(len(S)):
  if int(S[i]) == 1:
    continue
  else:
    if i+1 <= K:
      ans = S[i]
      break

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
ans = ""

if int(S[0]) > 1:
  ans = S[0]
elif K>=100:
  for i in range(len(S)):
    if int(S[i]) > 1:
      ans = S[i]
      break
    elif i==S-1:
      ans = 1
else:
  for i in range(len(S)):
    if int(S[i]) > 1:
      if i+1 <= K:
        ans = S[i]
        break
      else:
        ans = 1
        break
    elif i==S-1:
      ans = 1
print(ans)
Problem p02761 (python)

Fixed submission:
line = input().split()
N, M = int(line[0]), int(line[1]) 

if M == 0:
  if N == 1:
    print(0)
  else:
    print(10**(N-1))
  quit()

conds = []
for i in range(M):
  line = input().split()
  conds.append((int(line[0]),int(line[1])))
 
NUM = [-1] * N
 
isOK = True
for curCon in conds:
  s = curCon[0]
  dig = curCon[1]
  
  if NUM[s-1] == -1:
    NUM[s-1] = dig
  elif NUM[s-1] != dig:
    isOK = False
 
if N > 1:
  if NUM[0] == 0:
    isOK = False
 
if isOK != True:
  print(-1)
  quit()
else:
  if NUM[0] == -1:
    NUM[0]=1
    
  for i in range(N):
    if NUM[i] == -1:
      NUM[i] = 0
  numChar = ""
  for iNum in NUM:
    numChar += str(iNum)
  print(int(numChar))

Buggy submission (verdict: Runtime Error):
line = input().split()
N, M = int(line[0]), int(line[1]) 

if M == 0:
  return 10**N

conds = []
for i in range(M):
  line = input().split()
  conds.append((int(line[0]),int(line[1])))
 
NUM = [-1] * N
 
isOK = True
for curCon in conds:
  s = curCon[0]
  dig = curCon[1]
  
  if NUM[s-1] == -1:
    NUM[s-1] = dig
  elif NUM[s-1] > dig:
    NUM[s-1] = dig
 
if N > 1:
  if NUM[0] == -1 or NUM[0] == 0:
    isOK = False
 
if isOK != True:
  print(-1)
else:
  for i in range(N):
    if NUM[i] == -1:
      NUM[i] = 0
  numChar = ""
  for iNum in NUM:
    numChar += str(iNum)
  print(int(numChar))
Problem p02843 (python)

Fixed submission:
X = int(input())
if X < 100:
    print(0)
    exit()

w = X // 100
ans = w * 105
if X <= ans:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import itertools
from collections import defaultdict as dict
d = dict(int)

N = int(input())
S = [int(_) for _ in input()]
s = list(itertools.combinations(S, 3))

for j in range(len(s)):

    # カウントアップ
    d[s[j]] += 1

print(len(d))
Problem p02909 (python)

Fixed submission:
S = input()
if S == "Sunny":
  ans = "Cloudy"
elif S == "Cloudy":
  ans = "Rainy"
else:
  ans = "Sunny"
print(ans)

Buggy submission (verdict: Runtime Error):
S = int(input())
if S == "Sunny":
  ans = "Cloudy"
elif S == "Cloudy":
  ans = "Rainy"
else:
  ans = "Sunny"
print(ans)
Problem p03079 (python)

Fixed submission:

A,B,C = map(int,input().split())

if A == B == C:
    print("Yes")
else:
    print("No")

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

N, Q = map(int,input().split())
s = [_ for _ in input()]
td = [[_ for _ in input().split()] for _ in range(Q)]
GOL = [1 for _ in range(N)]

listS = defaultdict(list)
for i, word in enumerate(s):
    listS[word[0]].append(i)

for t, d in td:
    dictS = listS.get(t)
    if dictS == None:
        continue
    for idx in dictS:
        if (idx == 0 and d == "L") or (idx == N - 1 and d == "R"):
            pass
        else:
            if d == "L":
                GOL[idx - 1] += GOL[idx]
            else:
                GOL[idx + 1] += GOL[idx]

        GOL[idx] = 0

print(sum(GOL))
Problem p03165 (python)

Fixed submission:
# 最長共通部分　LCS ***未完成***
strA = input()
strB = input()
### 一致したら左上+1、そうでない場合は上か左のMAX
# / | 0 | A | B | C | B | A |
# 0 | 0 | 0 | 0 | 0 | 0 | 0 |
# B | 0 | 0 | 1 | 1 | 1 | 1 |
# B | 0 | 0 | 1 | 1 | 2 | 2 |
# A | 0 | 0 | 1 | 1 | 2 | 3 |
dp = [[0] * (len(strA) + 1) for _ in range(len(strB) + 1)]

for i, A in enumerate(strA, 1):
    for j, B in enumerate(strB, 1):
        if A == B:
            dp[j][i] = dp[j - 1][i - 1] + 1
        else:
            dp[j][i] = max(dp[j - 1][i], dp[j][i - 1])
ans = ""
cnt = 1
lstAns = dp[-1]
x, y = len(strA), len(strB)
while x > 0 and y > 0:
    if dp[y][x] == dp[y - 1][x]:
        y -= 1
    elif dp[y][x] == dp[y][x - 1]:
        x -= 1
    else:
        x -= 1
        y -= 1
        ans = strA[x] + ans

print(ans)

Buggy submission (verdict: Runtime Error):
# 最長共通部分　LCS ***未完成***
strA = input()
strB = input()
### 一致したら左上+1、そうでない場合は上か左のMAX
# / | 0 | A | B | C | B | A |
# 0 | 0 | 0 | 0 | 0 | 0 | 0 |
# B | 0 | 0 | 1 | 1 | 1 | 1 |
# B | 0 | 0 | 1 | 1 | 2 | 2 |
# A | 0 | 0 | 1 | 1 | 2 | 3 |
dp = [[0] * (len(strA) + 1) for _ in range(len(strB) + 1)]

for i, A in enumerate(strA, 1):
    for j, B in enumerate(strB, 1):
        if A == B:
            dp[j][i] = dp[j - 1][i - 1] + 1
        else:
            dp[j][i] = max(dp[j - 1][i], dp[j][i - 1])
ans = ""
cnt = 1
lstAns = dp[-1]
x, y = len(strB), len(strA)
while x > 0 and y > 0:
    if dp[x][y] == dp[x - 1][y]:
        x -= 1
    elif dp[x][y] == dp[x][y - 1]:
        y -= 1
    else:
        ans = strA[x] + ans
        x -= 1
        y -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
# 最長共通部分　LCS
strA = input()
strB = input()
### 一致したら左上+1、そうでない場合は上か左のMAX
# / | 0 | A | B | C | B | A |
# 0 | 0 | 0 | 0 | 0 | 0 | 0 |
# B | 0 | 0 | 1 | 1 | 1 | 1 |
# B | 0 | 0 | 1 | 1 | 2 | 2 |
# A | 0 | 0 | 1 | 1 | 2 | 3 |
dp = [[0] * (len(strA) + 1) for _ in range(len(strB) + 1)]

for i, A in enumerate(strA, 1):
    for j, B in enumerate(strB, 1):
        if A == B:
            dp[j][i] = dp[j - 1][i - 1] + 1
        else:
            dp[j][i] = max(dp[j - 1][i], dp[j][i - 1])
ans = ""
cnt = 1
lstAns = dp[-1]
for DP in lstAns:
    if cnt == DP:
        cnt += 1
        ans += strB[cnt - 1]
print(ans)