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

Fixed submission:
L = input()
 
for i in range(0,int(len(L))):
	if (i % 2) == 0:
		if L[i] == "L": #奇数
			print("No")
			break
	elif (i % 2) == 1:
		if L[i] == "R":
			print("No")
			break
else:print("Yes")

Buggy submission (verdict: Runtime Error):
S = input()
 
for i in range(0,int(len(S)):
	if i % 2 == 0:
		if L[i] == "L": #奇数
			print("No")
		break
	elif i % 2 == 1
		if L[i] == "R":
			print("No")
		break
else:print("Yes")
Problem p02911 (python)

Fixed submission:
N,K,Q = map(int, input().split())

P = [0] * N


for i in range(Q):
	A = int(input())
	P[A-1] += 1


for j in range(0,len(P)):
	if K - Q + P[j] > 0:
		print('Yes')
	else:
		print('No')

Buggy submission (verdict: Runtime Error):
N,K,Q = map(int, input().split()))
 
A = []
 
for _ in range(Q):
    A.append(int(input()))
	
P = [K] * N
 
r = 0
 
for i in range(0,len(A)):
	r = A[i] - 1
	P[r] += 1
	P = list(map(lambda x: x-1,P))
	
for i in range(0,len(P)):
	if P[i] > 0:
		print("Yes")
	else:print("No")
Problem p02917 (python)

Fixed submission:
N = int(input())
B = list(map(int, input().split()))

A = [0] * N


for i in range(N-1):
  A[i] = min(B[i-1],B[i])

A[0] = B[0]
A[N-1] = B[N-2]


print(sum(A))

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

A = [0] * N


for i in range(N-1):
  A[i] = min(B[i-1],B[i])

A[0] = min(B[0],B[1])
A[N-1] = B[N-2]

print(sum(A))

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

A = [0] * N


for i in range(N-1):
  A[i] = min(B[i-1],B[i])

A[0] = min(B[0],B[1])
A[N-1] = B[N-2]

print(A)

print(sum(A))
Problem p02918 (python)

Fixed submission:
N,K = map(int,input().split())
S = input()

score = 0

for i in range(1,N):
  if S[i] == S[i - 1]:
    score += 1
    
ans = min(score + 2 * K,N - 1)

print(ans)

Buggy submission (verdict: Runtime Error):
def swap():
  N,K = map(int,input().split())
  S = list(input())
  l = 0
  r = N - 1
  ans = 0
  while K > 0:
    for i in range(0,N - 1):
      if S[i] != S[i + 1]:
        left = i + 1
        break
    for j in range(N - 1,-1,-1):
      if S[j] != S[j - 1]:
        right = j
        break
    if left == right:
      right = N
    for i in range(left,right):
      s = S[i]
      if s == "L":
        S[i] = "R"
      else:
        S[i] = "L"
    K -= 1
  
  for i in range(0,N):
    j = (-i - 1)
    if S[i] == "L" and S[i] == S[i - 1] and i > 0:
      ans += 1
    if S[j] == "R" and S[j + 1] == S[j] and i > 0:
      ans += 1

  print(ans)
  
swap()
Problem p02921 (python)

Fixed submission:
S = input()
T = input()

counter = 0

for i in range(0,3):
  if S[i] == T[i]:
    counter += 1
    
print(counter)

Buggy submission (verdict: Runtime Error):
print(sum([int(i) for i in range(int(input()))]))

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [int(i) for i in input().split()]

counter = 0

max_n = 0

for i in range(1,N):
	if L[i] <= L[i-1]:
		counter += 1
	else:
		max_m = max(max_n,counter)
		ct = 0
			
print(max(max_n,counter))

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [int(i) for i in input().split()]

counter = 0

max_n = 0

for i in range(N-1):
	if L[i] <= L[i-1]:
		counter += 1
	else:
		max_m = max(max_n,counter)
		ct = 0
			
print(max(max_n,counter))
Problem p02922 (python)

Fixed submission:
A, B = map(int, input().split())
 
X = ((B-2) // (A-1)) + 1

print(X)

Buggy submission (verdict: Runtime Error):
import math

A = int(input())
B = int(input())

X = B / A

print(math.ceil(X))

Buggy submission (verdict: Runtime Error):
import math

A = int(input())
B = int(input())

X = B / A
XX = B // A

if XX == 0:
    print(X)
else:
    print(math.ceil(X))
Problem p02923 (python)

Fixed submission:
N = int(input())
L = [int(i) for i in input().split()]

Max =  0
Count = 0
for i in range(N-1):
    if L[i] >= L[i+1]:
        Count += 1
    else:
        Count = 0
    if Count >= Max:
        Max = Count
print(Max)

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

counter = 0

max_n = 0

for i in range(0,N):
	if L[i] > L[i+1]:
		counter += 1
	else:
		max_m = max(max_m,counter)
		ct = 0
			
print(max(max_m,counter))

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

count_list = [0] * N
for i in range(0,N):
	if L[i] > L[i+1]:
		counter += 1
		count_list.append(counter)

			
print(max(count_list))

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [int(i) for i in input().split()]

count_list = []
for i in range(0,N):
	counter = 0
	for j in range(i+1,N):
		print(L[i],L[j])
		if L[i] > L[j]:
			counter = counter + 1
			
		elif L[i] <= L[j]:
			count_list.append(counter)
			break
			
print(max(count_list))
Problem p02924 (python)

Fixed submission:
N = int(input())

ans = ((2 + N - 1) * N // 2) - N
print(ans)

Buggy submission (verdict: Runtime Error):
print(sum([int(i) for i in range(N)]))
Problem p02957 (python)

Fixed submission:
L = list(map(int, input().split()))

K = (L[0] + L[1]) 

if K % 2 == 0:
	print(int(K / 2))
else:print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
A,B = int(input())

K = (A + B) 

if K % 2 == 0:
	print(int(K / 2))
else:print("IMPOSSIBLE")
Problem p02971 (python)

Fixed submission:
N = int(input())
L = []
for l in range(N):
	L.append(int(input()))

maxL = max(L)
subL = L
num = ["n"] * N

if L.count(maxL) >= 2:
	for i in range(N):
		print(maxL)
		
else:	
	for i in range(N):
		if L[i] == maxL:
			L[i] = 0
			print(max(L))
		else:
			print(maxL)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = []
for l in range(N):
	L.append(int(input()))

maxL = max(L)
num = ["n"] * N

if L.count(maxL) >= 2:
	for i in range(N):
		print(maxL)
		
else:
	L = L.remove(maxL)
	secL = max(L)
	
	for i in range(N):
		if i in num:
			print(secL)
		else:
			print(maxL)
Problem p02981 (python)

Fixed submission:
L = list(map(int, input().split()))

N = L[0]
A = L[1]
B = L[2]


train = N * A

if train < B:
	print(train)
	
else:print(B)

Buggy submission (verdict: Runtime Error):
L,R = map(int,input().split())

ans = 2019 ** 2

if R - L >= 2018:
  ans = 0
  print(ans)
else: 
  for i in range(L,R):
    for j in range(L + 1,R + 1):
      mod = (i * j) % 2019 
      if mod < ans:
        ans = mod
      elif mod == 0:
        ans = 0
        break
  print(ans)

Buggy submission (verdict: Runtime Error):
L,R = map(int,input().split())

#区間の両端を除いた数=2017より長ければ2019の倍数が含まれているので0が解

ans = 2019 ** 2

for i in range(L,R):
  for j in range(L + 1,R):
    mod = (i * j) % 2019 
    if mod < ans:
      ans = mod
    elif mod == 0:
      ans = 0
      break
print(ans)
Problem p02983 (python)

Fixed submission:
L,R = map(int,input().split())

ans = 2019 ** 2

if R - L >= 2018:
  ans = 0
  print(ans)
else: 
  for i in range(L,R):
    for j in range(L + 1,R + 1):
      mod = (i * j) % 2019 
      if mod < ans:
        ans = mod
      elif mod == 0:
        ans = 0
        break
  print(ans)

Buggy submission (verdict: Runtime Error):
L,R = map(int,input().split())

#区間の両端を除いた数=2017より長ければ2019の倍数が含まれているので0が解
if R - L >= 2018:
  print(0)
else:
  ans = 2018 ** 2
  for i in range(L,R):
    for j in range(L + 1,R):
      mod = (i * j) % 2019 
      if mod < ans:
        ans = mod
      elif mod == 0:
        ans = 0
        break
print(ans)

Buggy submission (verdict: Runtime Error):
L,R = map(int,input().split())

ans = 2020

for i in range(L,R + 1):
  l = i % 2019
  r = (i + 1) % 2019
  if l * r < ans:
    ans = l * r
  if r = 0:
    ans = 0
    break
    
print(ans)
Problem p02993 (python)

Fixed submission:
L = input()

for i in range(0,len(L)-1):
	if L[i] == L[i+1]:
		print("Bad")
		break
else:print("Good")

Buggy submission (verdict: Runtime Error):
A,B,C,D = map(int,input().split())
 
cList = []
 
dList = []
 
numList = []
 
supC = (B // C)
infC = (A // C)
 
supD = (B // D)
infD = (A // D)
 
for i in range(A,B+1):
	numList.append(i)
 
 
for i in range(infC,supC+1):
	cList.append(i * C)
 
for i in range(infD,supD+1):
	dList.append(i * D)
	
numList = len(set(numList) - set(cList) - set(dList))
 
print(numList)
A,B,C,D = map(int,input().split())

cList = []

dList = []

numList = []

supC = (B // C)
infC = (A // C)

supD = (B // D)
infD = (A // D)

for i in range(A,B+1):
	numList.append(i)


for i in range(infC,supC+1):
	cList.append(i * C)

for i in range(infD,supD+1):
	dList.append(i * D)
	
numList = len(set(numList) - set(cList) - set(dList))

print(numList)
Problem p03000 (python)

Fixed submission:
N,X = map(int,input().split())
L = list(map(int,input().split()))

D = [0] * (N + 1)

counter = 0

for i in range(1,len(L)+1):
	D[i] = D[i - 1] + L[i - 1]
	
	
for i in range(0,len(D)):
	if D[i] <= X:
		counter += 1
	
print(counter)

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

D = [0] * (N + 1)

counter = 0

for i in range(1,len(L)):
	D[i] = D[i - 1] + L[i - 1]
	print(D)
	
	
for i in range(0,len(D)):
	if D[i] <= X:
	counter += 1
	
print(counter)
Problem p03074 (python)

Fixed submission:
from operator import add
from collections import deque
from itertools import accumulate

N,K = map(int,input().split())
S = input()

if N == 1:
  if S == "1" or K >= 1:
    print(1)
  else:
    print(0)
    
else:
  num = []
  cnt = 1
  ans = 0
  M = 2 * K + 1

  for i in range(1,N):
    if S[i] == S[i - 1]:
      cnt += 1
    else:
      num.append(cnt)
      cnt = 1
  num.append(cnt)

  if S[0] == "0":
    num = [0] + num
  
  acc = list(accumulate(num,add))
  acc = [0] + acc
  A = len(acc)
  
  for left in range(0,A,2):
    right = min(A - 1,left + M)
    ans = max((acc[right] - acc[left]),ans)
    
  print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
input = sys.stdin.readline

N,K = map(int,input().split())
S = input()

if N == 1:
  if S == "1" or K >= 1:
    print(1)
  else:
    print(0)
    
else:
  num = deque([])
  if S[0] == "0":
    num.append(0)
  cnt = 1
  ans = 0
  M = 2 * K + 1
  
  for i in range(1,N):
    if S[i] == S[i - 1]:
      cnt += 1
    else:
      num.append(cnt)
      cnt = 1
      
    if len(num) > M:
      num.popleft()

    if S[i - 1] == "1":
      ans = max(sum(num),ans)
    
    if i == N - 1:
      num.append(cnt)
      if len(num) > M:
        num.popleft()
      if S[i] == "1":
        ans = max(sum(num),ans)
  
  print(ans)
Problem p03086 (python)

Fixed submission:
S = input()

partial = ""

conditions = ["A","T","G","C"]

conlist = []

con = 0

for i in range(0,len(S)):
	if S[i] in conditions:
		for j in range(0,i+1):
			if S[j] in conditions:
				con +=1
			if (S[j] not in conditions) or j == i:
				conlist.append(con)
				con = 0
				

if len(conlist) > 0:
	print(max(conlist))
else:print(0)

Buggy submission (verdict: Runtime Error):
S = input()
 
partial = ""
 
conditions = ["A","T","G","C"]
 
conlist = []
 
con = 0
 
for i in range(0,len(S)):
	if S[i] in conditions:
		for j in range(0,i+1):
			if S[j] in conditions:
				con +=1
			if (S[j] not in conditions) or j == i:
				conlist.append(con)
				con = 0
				
 
print(max(conlist))

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

partial = ""

conditions = ["A","T","G","C"]

conlist = []

con = 0

for i in range(0,len(S)):
	if S[i] in conditions:
		for j in range(0,i):
			if S[j] in conditions:
				con +=1
			if (S[j] not in conditions) or j == i:
				conlist.append(con)
				con = 0
				

print(max(conlist))

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

partial = ""

conditions = ["A","T","G","C"]

conlist = []

con = 0

for i in range(0,len(S)):
	if S[i] in conditions:
		for j in range(0,i+1):
			if S[j] in conditions:
				con +=1
			if (S[j] not in conditions) or j == i:
				conlist.append(con)
				con = 0
				

print(max(conlist))
Problem p03087 (python)

Fixed submission:
N, Q = map(int, input().split())
S = input()
cons = [0] * (N + 1)

for i in range(N - 1):
  #隣り合う2文字(S[i] + S[i + 1])が"AC"である数の累積和を予め記録しておく
  #愚直に計算すると最悪でN * Q = 10 ** 6となるため、下準備をして再計算を防ぐ
  ##ACACTACGなら[0,1,1,2,2,2,3,3]
  cons[i + 1] = cons[i] + (1 if S[i] + S[i + 1] == 'AC' else 0)

for i in range(Q):
  l,r = map(int, input().split())
  #予め記録してあるACの累積数を引けば範囲内のACの数が求められる
  #ACと単位が2文字であるためrを1つ左にずらしておく(1引かないとCがはみ出てしまう)
  print(cons[r - 1] - cons[l - 1])

Buggy submission (verdict: Runtime Error):
N , Q = map(int,input().split())
S = input()
L = [list(map(int,input().split())) for i in range(Q)]

cut = ""

conlist = []

for i in range(Q):
	cut = S[L[i][0]-1:L[i][1]]
	conlist.append(cut.count("AC"))
	print(cut)
print(max(conlist))
Problem p03105 (python)

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

print(min(B//A,C))

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

white = (H * W) - (W * a) - ((H - a) * b)

print(white)
Problem p03147 (python)

Fixed submission:
N = int(input())

H = list(map(int,input().split()))

flowers = [0] * N

start = 0
end = 0

con = 0

while flowers != H:
	for i in range(0,N):
		if H[i] > flowers[i]:
			start = i
			for j in range(i,N):
				if H[j] == flowers[j]:
					end = j
					break
				else:
					end = N
			break


	for k in range(start,end):
		flowers[k] += 1
	con += 1
	start = 0
	end = 0
	
	


print(con)

Buggy submission (verdict: Runtime Error):
N = int(input())

height = list(map(int,input().split()))

ans = 0
interval = 0

for i in range(N):
  #区間が足りない時
  if height[i] > interval:
　　#今の区間と必要な区間の差分を取って足し、新たな区間の数を定義する
　　##順番に注意 先にintervalに定義すると、
   ##ansがそれに影響されるためansが差分の分だけ余分にに大きくなる
    ans += height[i] - interval
    interval += height[i] - interval
  #区間が多い時、必要な数に減らす
  else:
    interval = height[i]

print(ans)
Problem p03160 (python)

Fixed submission:
N = int(input())

H = list(map(int,input().split()))

C = [0] * (N)

C[0] = 0
C[1] = abs(H[1] - H[0])

for i in range(2,N):

    a = abs(H[i] - H[i - 2]) + C[i - 2]
    b = abs(H[i] - H[i - 1]) + C[i - 1]
    C[i] = min(a,b)

print(C[-1])

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
L = sorted( [ [int(i) for i in input().split()] for _ in range(N) ] )

dp = [0] * (W + 1)
cnt = 0

for w, v in L:
    #重さを足し合わせていき合計を求める
    cnt = cnt + w
    #W=重さの制約とこれまでの重さの合計のうち、
    #小さい方から品物iの重さまで、逆順にfor文を回す
    ##3,8-5,...15-7
    for i in range(min(cnt, W), w - 1, -1):
        #同じ重さでより価値が高い組み合わせがあれば価値を更新する
        ## w < Wの制約があり、i - wとその値を参照してから更新しているため、
        ## Wの制約を満たさない値を持つことはない
        ### 方法上、持ち得ない重さに持ち得ない値がつくことがあるが、
        ### それらが解 = 最大値になることはない
        ### (解を求める過程でついでに足されたり足されなかったりするだけなので)
        if dp[i] < dp[i - w] + v:
            dp[i] = dp[i - w] + v

print(max(dp))
Problem p03161 (python)

Fixed submission:
N,K = map(int,input().split() )
H = list(map(int, input().split()))

dp = [0] * N

#Hの値Hiとそのインデックスiを取り出す
#dpの初期値は0なので1から始める
for i,Hi in enumerate(H[1:],1):
  #過去範囲の切り取り、リスト範囲をはみ出ないようにmaxが0になるように
  s = max(0,i-K)
  
  #K個分の範囲について、zip関数で各iについてコストを計算し、
  #最小値を計算
  dp[i] = min([t + abs(Hi - hl) for hl,t in zip(H[s:i], dp[s:i])])

#dpリストの最後尾
print(dp[N - 1])

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

SUP = 10 ** 6

dp = [SUP] * N

#0 ~ K - 1
for i in range(0,min(N,K)):
  dp[i] = abs(H[i] - H[0])
  
if N <= K:
  print(dp[-1])
  
else:
  #K ~ N
  for i in range(K,N):
    d = SUP
    
    for j in range(K,0,-1):
      dm = abs(H[i] - H[i - j]) + dp[i - j]
      print(abs(H[i] - H[i - j]),dp[i - j],dm)
      if d > dm:
        d = dm
    dp[i] = d
  
  print(dp[-1])
Problem p03162 (python)

Fixed submission:
N = int(input())
L = []

for i in range(N):
  l = list(map(int,input().split()))
  L.append(l)
  
dp = [[0,0,0] for i in range(N)]
dp[0] = [L[0][0],L[0][1],L[0][2]]

for i in range(1,N):
  for j in range(3):
    dp[i][j] = max(dp[i - 1][(j + 1) % 3],dp[i - 1][(j + 2) % 3]) + L[i][j]
    
print(max(dp[N - 1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
L = []

for i in range(N):
  l = list(map(int,input().split()))
  L.append(l)
  
dp = [[0,0,0] for i in range(N + 1)]
dp[1] = [L[1][0],L[1][1],L[1][2]]

for i in range(2,N +1):
  for j in range(3):
    dp[i][j] = max(dp[i - 1][(j + 1) % 3],dp[i-1][(j + 2) % 3] + L[i][j])
    
print(max(dp[N]))
Problem p03163 (python)

Fixed submission:
N, W = map(int, input().split())
L = sorted( [ [int(i) for i in input().split()] for _ in range(N) ] )

dp = [0] * (W + 1)
cnt = 0

for w, v in L:
    #重さを足し合わせていき合計を求める
    cnt = cnt + w
    #W=重さの制約とこれまでの重さの合計のうち、
    #小さい方から品物iの重さまで、逆順にfor文を回す
    ##3,8-5,...15-7
    for i in range(min(cnt, W), w - 1, -1):
        #同じ重さでより価値が高い組み合わせがあれば価値を更新する
        ## w < Wの制約があり、i - wとその値を参照してから更新しているため、
        ## Wの制約を満たさない値を持つことはない
        ### 方法上、持ち得ない重さに持ち得ない値がつくことがあるが、
        ### それらが解 = 最大値になることはない
        ### (解を求める過程でついでに足されたり足されなかったりするだけなので)
        if dp[i] < dp[i - w] + v:
            dp[i] = dp[i - w] + v

print(max(dp))

Buggy submission (verdict: Runtime Error):
import sys
from numba import jit

@jit
def main():
  input = sys.stdin.readline
  
  N, W = map(int, input().split())
  L = [list(map(int,input().split())) for i in range(N)]
  dp = [[0] * (W + 1) for i in range(N + 1)]
  
  for i in range(N):
    weight = L[i][0]
    value = L[i][1]
    for w in range(W + 1):
      if w >= weight:
        dp[i + 1][w] = max(dp[i][w],dp[i][w - weight] + value)
      else:
        dp[i + 1][w] = dp[i][w]
        
  print(dp[-1][W])

if __name__ == '__main__':
  main()
Problem p03164 (python)

Fixed submission:
import numpy as np

N , W = map(int,input().split())
dp = np.full(N * 1000 + 1,W + 1)
dp[0] = 0

for i in range(N):
  w,v = map(int,input().split())
  dp[v:] = np.minimum(dp[v:],dp[:-v] + w)

print(np.max(np.where(dp <= W)))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np

N, W = map(int, input().split())

dp = np.zeros([N + 1,W + 1],dtype=int)

print(dp)

for i in range(N):
  weight, value = map(int, input().split())
  dp[i + 1] = dp[i]
  dp[i + 1, weight:] = np.maximum(dp[i + 1,weight:], dp[i,:W - weight + 1] + value)

print(dp[N][W])

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
L = [list(map(int,input().split())) for i in range(N)]

dp = [0] * (W + 1)
cnt = 0

for w, v in L:
  cnt = cnt + w
  ##3,8-5,...15-7
  for i in range(min(cnt, W), w - 1, -1):
    if dp[i] < dp[i - w] + v:
      dp[i] = dp[i - w] + v

print(max(dp))

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
L = sorted([list(map(int,input().split())) for i in range(N)])

dp = [0] * (W + 1)
con = 0

for w, v in L:
  con += w
  for i in range(min(con, W), w - 1, -1):
    if dp[i] < dp[i - w] + v:
      dp[i] = dp[i - w] + v

print(max(dp))
Problem p03165 (python)

Fixed submission:
import numpy as np
#文字列をASCII codeのリストで管理
S = np.array([ord(i) - 97 for i in input()], dtype=int)
T = np.array([ord(i) - 97 for i in input()], dtype=int)
ls = len(S)
lt = len(T)
#S[i] == T[j]であれば、i * j行列の[i,j]成分が1となる行列
equal = np.equal.outer(S,T).astype(int)
#print(equal)
 
dp = [np.zeros(lt + 1,dtype = int)]
#print(dp)
for i in range(ls):
  #追加された最後のdp列をx,newDPとする
  x = dp[-1].copy()
  newDP = x.copy()
  #一致しているところで1を足し、そうでないところはそのまま
  newDP[1:] = np.maximum(x[:-1] + equal[i],newDP[1:])
  #dp[i] = i以前のdpの最大値に更新
  np.maximum.accumulate(newDP, out = newDP)
  #最大共通部分を計算するだけなら一列のdp列を使い回せば良いが
  #文字列の復元のために、dp列を追加する
  dp.append(newDP)
  #print(dp)
 
 
ans = ""
i, j = ls, lt
#数列の復元と文字列への復元
while i > 0 and j > 0:
  if S[i - 1] == T[j - 1]:
    ans += chr(S[i - 1] + 97)
    i -= 1
    j -= 1
    continue
  if dp[i][j] == dp[i - 1][j]:
    i -= 1
  else:
    j -= 1

#リバース
print(ans[::-1])

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

def LCS():
  X = input()
  Y = input()
  
  dp = np.zeros([len(Y) + 1,len(X) + 1],dtype = int)
  for y in range(len(Y)):
    for x in range(len(X)):
      if Y[y] == X[x]:
        #Xのi文字目とYのj文字目が一致した時のみ値が更新される
        #文字列が一致する直線、i - 1,j - 1目までの最大一致数に、1を足す
        dp[y + 1][x + 1] = dp[y][x] + 1
        
      else:
        dp[y + 1][x + 1] = max(dp[y][x + 1],dp[y + 1][x])
        
    
  x = len(X)
  y = len(Y)
  ans = ""
  
  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:
      ans = Y[y - 1] + ans
      y,x = y - 1,x - 1
  
  print(ans)
  
LCS()
Problem p03231 (python)

Fixed submission:
import fractions
  
def lcm(a,b):
  return (a * b) // fractions.gcd(a, b)

N,M = map(int,input().split())
S = input()
T = input()

if M > N:
  N,M = M,N
  S,T = T,S

X = lcm(N,M)

n = N // fractions.gcd(N,M)
m = M // fractions.gcd(N,M)

for i in range(0,X,m):
  if S[0] != T[0]:
    print(-1)
    break
  elif i % n == 0:
    s = i // n
    t = i // m
    if S[t] != T[s]:
      print(-1)
      break
else:
  print(X)

Buggy submission (verdict: Runtime Error):
import fractions
  
def lcm(a,b):
  return (a * b) // fractions.gcd(a, b)

N,M = map(int,input().split())
S = input()
T = input()

if M > N:
  N,M = M,N
  S,T = T,S

X = lcm(N,M)

n = N // fractions.gcd(N,M)
m = M // fractions.gcd(N,M)

for i in range(0,X,n):
  if S[0] != T[0]:
    print(-1)
    break
  elif i % m == 0:
    if S[n] != T[m]:
      print(-1)
      break
else:
  print(X)

Buggy submission (verdict: Runtime Error):
import fractions
  
def lcm(a,b):
  return (a * b) // fractions.gcd(a, b)

N,M = map(int,input().split())
S = input()
T = input()

if M > N:
  N,M = M,N
  S,T = T,S

X = lcm(N,M)

n = N // fractions.gcd(N,M)
m = M // fractions.gcd(N,M)

for i in range(0,X + 1,m):
  if S[0] != T[0]:
    print(-1)
    break
  elif i % n == 0:
    if S[n] != T[m]:
      print(-1)
      break
else:
  print(X)

Buggy submission (verdict: Runtime Error):
import fractions
  
def lcm(a,b):
  return (a * b) // fractions.gcd(a, b)

N,M = map(int,input().split())
S = input()
T = input()

if M > N:
  N,M = M,N
  S,T = T,S

X = lcm(N,M)

if fractions.gcd(N,M) == 1 and S[0] == T[0]:
  print(X)
else:
  n = N // fractions.gcd(N,M)
  A = [i * n for i in range(0,N)]
  m = M // fractions.gcd(N,M)
  
  for i in range(X):
    if i // (n * m) == 0:
      if S[n] != T[m]:
        print(-1)
        break
  else:
    print(X)
Problem p03240 (python)

Fixed submission:
n = int(input()) 
  
data = []
p, q, r = (0, 0, 0)
for _ in range(n):
    (l, m, n) = map(int, input().split())
    data.append([l, m, n])
    if n:
        p = l
        q = m
        r = n
 
 
for x in range(101):
    for y in range(101):
        h = r + abs(p - x) + abs(q - y)
        if all(c == max(h - abs(a - x) - abs(b - y), 0) for a, b, c in data):
            print("{} {} {}".format(x, y, h))
            exit(0)

Buggy submission (verdict: Runtime Error):
N = int(input())

points = [list(map(int, input().split())) for _ in range(N)]

p = points[0][0]
q = points[0][1]
r = points[0][2]

points.sort(key=lambda x: x[2], reverse = True)

for i in range(0,101):
  for j in range(0,101):
    H= points[0][2] + point(points[0][0] - i) + abs(points[0][1] - j)
    for x,y,z in points:
      if z != max(H - abs(x - i) - abs(y - j),0):
        break
    else:
      print(i,j,H)

Buggy submission (verdict: Runtime Error):
N = int(input()) 
  
grid = []
p, q, r = (0, 0, 0)
for _ in range(n):
    (l, m, n) = map(int, input().split())
    grid.append([l, m, n])
    if N:
        p = l
        q = m
        r = n
 
 
for cx in range(101):
    for cy in range(101):
        h = r + abs(p - cx) + abs(q - cy)
        if all(c == max(h - abs(a - cx) - abs(b - cy), 0) for a, b, c in grid):
            print("{} {} {}".format(cx, cy, h))
            exit(0)

Buggy submission (verdict: Runtime Error):
N = int(input())
 
grid = []
p,q,r = (0,0,0)

for _ in range(N):
    (l,m,n) = map(int, input().split())
    grid.append([l, m, n])
    if N:
        p = l
        q = m
        r = n


#101*101通りのため、中心座標cx,cyについて全探索を行う 
for cx in range(101):
    for cy in range(101):
        #各cs,cyについての座標の高さを求める
        h = r + abs(p - cx) + abs(q - cy)
        #与えられた座標の値を順に代入していき、条件を満たすcx,cyの組み合わせに当たれば
        #出力する
        if all(c == max(h - abs(a - cx) - abs(b - cy), 0) for a, b, c in grid):
            print("{} {} {}".format(cx, cy, h))
            exit(0)
            
n = int(input())