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

Fixed submission:
from collections import deque

def read_pair():
    return map(int, input().strip().split())

# Read graph
N, M = read_pair()
adj = [[] for x in range(N)]
rev = [[] for y in range(N)]

outdegree = [0] * N
for i in range(M):
    x, y = read_pair()

    # Use 0-indexed labels
    x -= 1
    y -= 1

    adj[x].append(y)
    rev[y].append(x)
    outdegree[x] += 1

maxpath = [0] * N
q = deque()

for x in range(N):
    if outdegree[x] == 0:
        q.append(x)

while q:
    x = q.popleft()
    for y in adj[x]:
        maxpath[x] = max(maxpath[x], 1 + maxpath[y])
    for z in rev[x]:
        outdegree[z] -= 1
        if outdegree[z] == 0:
            q.append(z)

print(max(maxpath))

Buggy submission (verdict: Runtime Error):
def read_pair():
    return map(int, input().strip().split())

# Read graph
N, M = read_pair()
adj = [[] for x in range(N)]
for i in range(M):
    x, y = read_pair()
    adj[x - 1].append(y - 1)

memo = [None] * N

def longest_path(x, memo):
    if memo[x] is not None:
        return memo[x]

    result = 0
    for y in adj[x]:
        result = max(result, 1 + longest_path(y, memo))
    memo[x] = result
    return result

result = 0
for x in range(N):
    result = max(result, longest_path(x, memo))
print(result)

Buggy submission (verdict: Runtime Error):
def read_pair():
    return map(int, input().strip().split())

# Read graph
N, M = read_pair()
adj = [[] for x in range(N + 1)]
for i in range(M):
    x, y = read_pair()
    adj[x].append(y)

memo = [None] * (N + 1)

def longest_path(x, memo):
    if memo[x] is not None:
        return memo[x]

    result = 0
    for y in adj[x]:
        result = max(result, 1 + longest_path(y, memo))
    memo[x] = result
    return result

result = 0
for x in range(1, N + 1):
    result = max(result, longest_path(x, memo))
print(result)

Buggy submission (verdict: Runtime Error):
def read_pair():
    return map(int, input().split())

# Read graph
N, M = read_pair()
adj = [[] for i in range(N + 1)]
for i in range(M):
    x, y = read_pair()
    adj[x].append(y)

memo = [None] * (N + 1)

def longest_path(x, memo):
    if memo[x] is not None:
        return memo[x]

    result = 0
    for y in adj[x]:
        result = max(result, 1 + longest_path(y, memo))
    memo[x] = result
    return result

result = 0
for x in range(1, N + 1):
    result = max(result, longest_path(x, memo))
print(result)
Problem p03160 (python)

Fixed submission:
N = int(input())
arr = list(map(int,input().rstrip().split()))
dparr= [-1 for i in range(N)]
dparr[0] = 0
dparr[1] = abs(arr[0]-arr[1])
for num in range(2,N):
  dparr[num] = min(dparr[num-2]+ abs(arr[num]-arr[num-2]), dparr[num-1]+ abs(arr[num]-arr[num-1]))
print(dparr[-1])

Buggy submission (verdict: Runtime Error):
def frogOne(N, arr):
    dparr= [-1 for i in range(N)]
    dparr[0] = 0
    dparr[1] = abs(arr[0]-arr[1])
    for num in range(2,N):
        dparr[num] = min(dparr[num-2]+ abs(arr[num]-arr[num-2]), dparr[num-1]+ abs(arr[num]-arr[num-1]))
    return dparr[-1]


 if __name__ == '__main__':
   N = int(input())
   arr = list(map(int,input().rstrip().split()))
   print(frogOne(N, arr))
Problem p03160 (python)

Fixed submission:
N = int(input())
h = list(map(int, input().split()))
    
inf = 10**9
dp = [0] + [inf]*N
    
for i in range(1,N):
    if i == 1:
        dp[1] = abs(h[1]-h[0])
    else:
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
    
print(dp[N-1])

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

inf = -1
dp = [0] + [inf]*N
    
for i in range(1,N):
    dp[1] = abs(h[1]-h[0])
    else:
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
    
print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))
dp = [0]*N+1
    
for i in range(1,N):
    if i == 1:
        dp[1] = abs(h[1]-h[0])
    else:
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
    
print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))
dp = [0 for i in range(10)]
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))
dp = [0 for i in range(10)]
def aFrog(N,h):
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    for i in range(2,N):
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
    return dp[N-1]

print(aFrog(N,h))

Buggy submission (verdict: Runtime Error):
def aFrog(N,h):
    dp = [0 for i in range(10)]
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    print(dp)
    for i in range(2,N):
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
    return dp[N-1]

N = int(input())
h = list(map(int, input().split()))
print(aFrog(N,h))
Problem p03160 (python)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
dp = [1000000000+5 for i in range(n)]
dp[0] = 0
for i in range(n):
    for j in range(i+1, i+3):
        if j < n:
            dp[j] = min(dp[j], dp[i] + abs(h[i]-h[j]))
print(dp[n-1])

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

dp = [-1]*(n+1)

def helper(n):
    if n <= 0:
        return float('inf')
    elif n == 1:
        return 0
    elif dp[n] != -1:
        return dp[n]
    else:
        if n-1 >= 0 and n-2 >= 0:
            l = abs(h[n-1]-h[n-2])+helper(n-1)
        else:
            l = float('inf')
        if n-1 >= 0 and n-3 >= 0:
            r = abs(h[n-1]-h[n-3]) + helper(n-2)
        else:
            r = float('inf')
        dp[n] = min(l, r)
        return dp[n]

print(helper(n))

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

dp = [-1]*(n+1)

def helper(n):
    if n <= 0:
        return float('inf')
    elif n == 1:
        return 0
    elif dp[n] != -1:
        return dp[n]
    else:
        dp[n] = min(abs(h[n-1]-h[n-2])+helper(n-1), abs(h[n-1]-h[n-3]) + helper(n-2))
        return dp[n]

print(helper(n))
Problem p03162 (python)

Fixed submission:
n = int(input())
c = []
dp = [0]*3
# for i in range(n):
#     c.append(list(map(int, input().split())))
for i in range(n):
    c = list(map(int, input().split()))
    new_dp = [0]*3
    for j in range(3):
        for k in range(3):
            if j != k:
                new_dp[k] = max(new_dp[k], dp[j] + c[k])
    dp = new_dp[:]
print(max(dp))

Buggy submission (verdict: Runtime Error):
n = int(input())
c = [0]*n
dp = [0]*n
for i in range(n):
    c = list(map(int, input().split()))
    new_dp = [0]*3
    for j in range(3):
        for k in range(3):
            if j != k:
                new_dp[k] = max(new_dp[k], dp[j] + c[k])
    dp = new_dp[:]
print(max(dp))
Problem p03160 (python)

Fixed submission:
n = int(input())
s = input().split()
for i in range(n):
  s[i] = int(s[i])
memo = [0 for i in range(n)]
memo[0] = 0
for i in range(1,n):
  if i==1:
      memo[i] = memo[i-1]+abs(s[i]-s[i-1])
  else:
      memo[i] = min(memo[i-1]+abs(s[i]-s[i-1]), memo[i-2]+abs(s[i]-s[i-2]))
print(memo[n-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input().split()
for i in range(n):
  s[i] = int(s[i])
memo = [0 for i in range(n+1)]
memo[0] = 0
memo[1] = 0
for i in range(2,n+1):
  memo[i] = min(memo[i-1]+abs(s[i]-s[i-1]), memo[i-2]+abs(s[i]-s[i-2]))
print(memo[n])
Problem p03160 (python)

Fixed submission:
n=int(input())
infy=float('inf')
arr=[int(x) for x in input().split()]
arr.append(0)
val=[infy]*(n+1)
val[0]=0
for i in range(0,n-1):
    val[i+1]=min(val[i+1],abs(arr[i+1]-arr[i])+val[i])
    val[i+2]=min(val[i+2],abs(arr[i+2]-arr[i])+val[i])

print(val[n-1])

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
infy=math.inf
arr=[int(x) for x in input().split()]
arr.append(0)
val=[infy]*(n+1)
val[0]=0
for i in range(0,n-1):
    val[i+1]=min(val[i+1],abs(arr[i+1]-arr[i])+val[i])
    val[i+2]=min(val[i+2],abs(arr[i+2]-arr[i])+val[i])

print(val[n-1])

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
infy=math.inf
arr=[int(x) for x in input().split()]
arr.append(0)
val=[infy]*(n+1)
val[0]=0
for i in range(0,n-1):
    val[i+1]=min(val[i+1],abs(arr[i+1]-arr[i])+val[i])
    val[i+2]=min(val[i+2],abs(arr[i+2]-arr[i])+val[i])

print(val[n-1])
Problem p03164 (python)

Fixed submission:
n,w=[int(x) for x in input().split()]

lw=w
totval=0
wei=[]
val=[]
for test in range(n):
    cw, v = [int(x) for x in input().split()]
    wei.append(cw)
    val.append(v)
    totval+=v

dp=[float('inf')]*(totval+1)
dp[0]=0
for item in range(n):
    for j in range(totval,val[item]-1,-1):
        dp[j]=min(dp[j-val[item]]+wei[item],dp[j])
    #print(dp)
ans=0
for i in range(totval+1):
    if dp[i] <=w:
        ans=i
print(ans)

Buggy submission (verdict: Runtime Error):
n,w=[int(x) for x in input().split()]
dp=[0]*(w+1)
lw=w
for test in range(n):
    cw, v = [int(x) for x in input().split()]
    temp=[0]*(w+1)
    for i in range(1,w+1):
        if cw <= i :
            temp[i]=max(dp[i],v+dp[i-cw])
        else:
            temp[i]=max(dp[i],temp[i-1])
    dp=temp[:]
    #print(dp)
print(dp[w])
Problem p03161 (python)

Fixed submission:
import sys
def frog2(N,h,k):
    dp=[sys.maxsize-1]*N
    dp[0]=0
    for i in range(N):
        for j in range(i+1,i+k+1):
            if j<N:
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))
    return dp[N-1]

N,k=map(int,input().split())
h=list(map(int,input().split()))
print(frog2(N,h,k))

Buggy submission (verdict: Runtime Error):
import sys
def frog2(N,h,k):
    dp=[sys.maxsize-1]*N
    dp[0]=0
    for i in range(N):
        for j in range(i+1,i+k+1):
            if j<N:
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))
    return dp[N-1]

N,k=map(int,input().split())
h=list(map(int,input().split()))
print(frog2(N,h,k))

Buggy submission (verdict: Runtime Error):
def frog2(N,h,k):
    dp=[sys.maxsize-1]*N
    dp[0]=0
    for i in range(N):
        for j in range(i+1,i+k+1):
            if j<N:
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))
    return dp[N-1]

N,k=map(int,input().split())
h=list(map(int,input().split()))
print(frog2(N,h,k))
Problem p03163 (python)

Fixed submission:
def knapsackBottomUp(wt,price,c,n):
    dp=[[0 for x in range(c+1)] for y in range(n+1)]
    for i in range(n+1):
        for w in range(c+1):
            if i==0 or w==0:
                dp[i][w]=0
            else:
                inc=exc=0
                if wt[i-1]<=w:
                    inc=price[i-1]+dp[i-1][w-wt[i-1]]
                exc=dp[i-1][w]
                dp[i][w]=max(inc,exc)
    
    return dp[n][c]
  
n,c=map(int,input().split())
wt=[]
price=[]
for _ in range(n):
    w,v=map(int,input().split())
    wt.append(w)
    price.append(v)
print(knapsackBottomUp(wt,price,c,n))

Buggy submission (verdict: Runtime Error):
def knapsack(wt,price,n,c,dp):
    if n<0 or c==0:
        return 0
    if dp[n][c]!=-1:
        return dp[n][c]
    inc=exc=0
    if c>=wt[n]:
        inc=price[n]+knapsack(wt,price,n-1,c-wt[n],dp)
    exc=0+knapsack(wt,price,n-1,c,dp)
    dp[n][c]=max(inc,exc)
    return max(inc,exc)

n,c=map(int,input().split())
wt=[]
price=[]
for _ in range(n):
    w,v=map(int,input().split())
    wt.append(w)
    price.append(v)
dp=[[-1 for x in range(c+1)] for y in range(n+1)]
print(knapsack(wt,price,n-1,c,dp))
Problem p03165 (python)

Fixed submission:
s=input()
t=input()
dp=[[0 for i in range(len(t)+1)] for j in range(len(s)+1)]
#print(lcs(s,t,0,0," ",dp))

for i in range(1,len(s)+1):
    for j in range(1,len(t)+1):
        if s[i-1]==t[j-1]:
            dp[i][j]=1+(dp[i-1][j-1])
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])

x=len(s)
y=len(t)
ans=""
while x!=0 and y!=0:
    if dp[x-1][y]==dp[x][y]:
        x-=1
    elif dp[x][y-1]==dp[x][y]:
        y-=1
    else:
        ans=t[y-1]+ans
        x-=1
        y-=1
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
dp=[[0 for i in range(len(t)+1)] for j in range(len(s)+1)]
#print(lcs(s,t,0,0," ",dp))

for i in range(1,len(s)+1):
    for j in range(1,len(t)+1):
        if s[i-1]==t[j-1]:
            dp[i][j]=1+(dp[i-1][j-1])
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])

printD(dp,len(t),len(s))

x=len(s)
y=len(t)
ans=""
while x!=0 and y!=0:
    if dp[x-1][y]==dp[x][y]:
        x-=1
    elif dp[x][y-1]==dp[x][y]:
        y-=1
    else:
        ans=t[y-1]+ans
        x-=1
        y-=1
print(ans)
Problem p03160 (python)

Fixed submission:
N  = int(input())
h =  list(map(int , input().split(' ')))
#N = 6
#h = [30,10,60 , 10, 60,50]

dp =[-1]*(N)
dp[N-1] = 0
dp[N-2] = abs(h[N-2] - h[N-1])

m=N-3

while m>=0:
    diff = 0
    index  = 0
    diff = min(abs(h[m]-h[m+2]) + dp[m+2]  ,  abs(h[m]-h[m+1])+dp[m+1])
    dp[m] = diff 
    m -=1
print(dp[m+1])

Buggy submission (verdict: Runtime Error):

import copy
H, W = list(map(int , input().split(' ')))

arr =  []
h_ar = []
for _ in range(W):
    h_ar.append(0)
dp =[]
for _ in range(H):
    dp.append(copy.deepcopy(h_ar))


for _ in range(H):
    w  =  list(map(str , input().split(' ')))
    arr.append(w)


flag= False
for h in range(H-1,-1,-1):
    if arr[h][W-1]=='#':

        dp[h][W-1]=-1
        flag =  True
    if flag:
        dp[h][W-1]=-1
    else:
        dp[h][W-1]=1
    
flag = False
for w in range(W-1,-1,-1):
    if arr[H-1][w]=='#':
        dp[H-1][w]=-1
        flag =  True
    if flag:
        dp[H-1][w]=-1
    else:
        dp[H-1][w]=1



for row in range(H-1,0,-1):
    for col in range(W-1,0,-1):
        if arr[row-1][col-1]=='#':
            dp[row-1][col-1]=-1
        elif dp[row][col-1] ==-1 or dp[row-1][col]==-1:
            dp[row-1][col-1] = max(dp[row][col-1],  dp[row-1][col])
        elif dp[row][col-1] > -1 and dp[row-1][col]>-1:
             dp[row-1][col-1] = dp[row][col-1] +  dp[row-1][col]

print(dp[0][0]%(10**9+7))
Problem p03165 (python)

Fixed submission:
def solve(s1,s2):
    rows=len(s1)
    cols=len(s2)
    dp=[[0]*(cols+1) for i in range(rows+1)]
    for i in range(1,rows+1):
        for j in range(1,cols+1):
            if s1[i-1]==s2[j-1]:
                dp[i][j]=dp[i-1][j-1]+1
            else:
                dp[i][j]=max(dp[i-1][j],dp[i][j-1])
                
    max_len=dp[rows][cols]
    result=[""]*(max_len+1)
    result[max_len]=""
    i=rows
    j=cols
    while i>0 and j>0:
        if s1[i-1]==s2[j-1]:
            result[max_len-1]=s1[i-1]
            max_len -=1
            i -=1
            j -=1
        elif dp[i-1][j]>dp[i][j-1]:
            i -=1
        else:
            j -=1
    return "".join(result)
            
                
#     if i==n or j==m:
#         return result
#     if s1[i]==s2[j]:
#         result +=s1[i]
#         return result+solve(s1,s2,n,m,i+1,j+1,result)
#     else:
#         left=solve(s1,s2,n,m,i+1,j,result)
#         right=solve(s1,s2,n,m,i,j+1,result)
#         if left:
#             result
        
        ##return max(solve(s1,s2,n,m,i+1,j,result),solve(s1,s2,n,m,i,j+1,result))
s1=input()
s2=input()
n=len(s1)
m=len(s2)
result=""
print(solve(s1,s2))

Buggy submission (verdict: Runtime Error):
def solve(s1,s2,n,m,i,j):
    if i==n or j==m:
        return 0
    if s1[i]==s2[j]:
        return 1+solve(s1,s2,n,m,i+1,j+1)
    else:
        return max(solve(s1,s2,n,m,i+1,j),solve(s1,s2,n,m,i,j+1))
s1=input()
s2=input()
n=len(s1)
m=len(s2)
print(solve(s1,s2,n,m,0,0))
Problem p03160 (python)

Fixed submission:
import sys
def mincost(n,h):
    dp=[-1 for i in range(n)]
    dp[n-1]=0
    dp[n-2]=abs(h[n-2]-h[n-1])
    for i in range(n-3,-1,-1):
        dp[i]=min(dp[i+1]+abs(h[i+1]-h[i]),dp[i+2]+abs(h[i+2]-h[i]))
    return dp[0]    

n=int(input())
h=[int(x) for x in input().split()]
print(mincost(n,h))

Buggy submission (verdict: Runtime Error):
from sys import stdin, gettrace
import sys
 
if not gettrace():
    def input():
        return next(stdin)[:-1]
 
 
# def input():
#    return stdin.buffer.readline()
 
def main():
    def mincost(n,h):
    	dp=[-1 for i in range(n)]
    	dp[n-1]=0
    	dp[n-2]=abs(h[n-2]-h[n-1])
    	for i in range(n-3,-1,-1):
        	mn=min(i+k+1,n)
        	mnm=sys.maxsize
        	for j in range(i+1,mn):
            	mnm=min(dp[j]+abs(h[j]-h[i]),mnm)
        	dp[i]=mnm    
    	return dp[0]

	n,k=map(int,input().split())
	h=[int(x) for x in input().split()]
	print(mincost(n,h))
 
 
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
def mincost(n,h,i,dp):
    if i==(n-1):
        return 0
    elif i==(n-2):
        return abs(h[n-1]-h[i])
    mncost=sys.maxsize
    for j in range(i+1,i+3):
        if dp[j]==-1:
            cost=mincost(n,h,j,dp)
            dp[j]=cost
        else:
            cost=dp[j]
        mncost=min(mncost,cost+abs(h[j]-h[i]))
    return mncost

n=int(input())
h=[int(x) for x in input().split()]
dp=[-1 for i in range(n)]
print(mincost(n,h,0,dp))
Problem p03162 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def maxcost(li,n,i,strt,dp):
    if i==(n-1):
        return li[i][strt]
    mx=-sys.maxsize
    for l in range(3):
        if l!=strt:
            if dp[i+1][l]==-1:
                cost=maxcost(li,n,i+1,l,dp)
                dp[i+1][l]=cost
            else:
                cost=dp[i+1][l]
            mx=max(mx,cost+li[i][strt])
    return mx


n=int(input())
li=[]
for i in range(n):
    temp=[int(x) for x in input().split()]
    li.append(temp)
dp=[[-1 for j in range(3)] for i in range(n)]
print(max(maxcost(li,n,0,0,dp),maxcost(li,n,0,1,dp),maxcost(li,n,0,2,dp)))

Buggy submission (verdict: Runtime Error):
import sys
def maxcost(li,n,i,strt,dp):
    if i==(n-1):
        return li[i][strt]
    mx=-sys.maxsize
    for l in range(3):
        if l!=strt:
            if dp[i+1][l]==-1:
                cost=maxcost(li,n,i+1,l,dp)
                dp[i+1][l]=cost
            else:
                cost=dp[i+1][l]
            mx=max(mx,cost+li[i][strt])
    return mx


n=int(input())
li=[]
for i in range(n):
    temp=[int(x) for x in input().split()]
    li.append(temp)
dp=[[-1 for j in range(3)] for i in range(n)]
print(max(maxcost(li,n,0,0,dp),maxcost(li,n,0,1,dp),maxcost(li,n,0,2,dp)))

Buggy submission (verdict: Runtime Error):
from sys import stdin, gettrace
import sys
 
if not gettrace():
    def input():
        return next(stdin)[:-1]
 
 
# def input():
#    return stdin.buffer.readline()

def maxcost(li,n,i,strt,dp):  
  if i==(n-1):
    return li[i][strt]
  mx=-sys.maxsize
  for l in range(3):
    if l!=strt:
      if dp[i+1][l]==-1:
        cost=maxcost(li,n,i+1,l,dp)
        dp[i+1][l]=cost
      else:
        cost=dp[i+1][l]
      mx=max(mx,cost+li[i][strt])
  return mx

def main():
  n=int(input())
  li=[]
  for i in range(n):
    temp=[int(x) for x in input().split()]
  li.append(temp)
  dp=[[-1 for j in range(3)] for i in range(n)]
  print(max(maxcost(li,n,0,0,dp),maxcost(li,n,0,1,dp),maxcost(li,n,0,2,dp)))
 
 
if __name__ == "__main__":
    main()
Problem p03165 (python)

Fixed submission:
s1=input()
s2=input()
n1,n2=len(s1),len(s2)
dp=[[-1 for j in range(n2+1)] for i in range(n1+1)]
for i in range(n1,-1,-1):
    for j in range(n2,-1,-1):
        if i==n1 or j==n2:
            dp[i][j]=0
        else:
            if s1[i]==s2[j]:
                dp[i][j]=1+dp[i+1][j+1]
            else:
                dp[i][j]=max(dp[i][j+1],dp[i+1][j])
n=""
i,j=0,0
while i<n1 and j<n2:
    if dp[i][j]==dp[i+1][j]:
        i+=1
    elif dp[i][j]==dp[i][j+1]:
        j+=1
    else:
        n+=s1[i]
        i+=1
        j+=1
print(n)

Buggy submission (verdict: Runtime Error):
from sys import stdin, gettrace
 
if not gettrace():
    def input():
        return next(stdin)[:-1]
 
 
# def input():
#    return stdin.buffer.readline()

def recursion(s1,s2,i,j,n1,n2,dp):
    if i>=n1 or j>=n2:
        return ""   
    if s1[i]==s2[j]:
        if dp[i+1][j+1]==-1:
            string=recursion(s1,s2,i+1,j+1,n1,n2,dp)
            dp[i+1][j+1]=string
        else:
            string=dp[i+1][j+1]
        return s1[i]+string
    else:
        if dp[i+1][j]==-1:
            x=recursion(s1,s2,i+1,j,n1,n2,dp)
            dp[i+1][j]=x
        else:
            x=dp[i+1][j]
        if dp[i][j+1]==-1:
            y=recursion(s1,s2,i,j+1,n1,n2,dp)
            dp[i][j+1]=y
        else:
            y=dp[i][j+1]
        if len(x)>len(y):
            return x
        else:
            return y

def main():
    s1=input()
    s2=input()
    n1,n2=len(s1),len(s2)
    dp=[[-1 for j in range(n2+1)] for i in range(n1+1)]
    print(recursion(s1,s2,0,0,len(s1),len(s2),dp))
 
 
if __name__ == "__main__":
    main()
Problem p03160 (python)

Fixed submission:
n,l=int(input()),list(map(int,input().split()))
c1,c2=0,abs(l[0]-l[1])
for i in range(2,n):
  t=c2
  c2=min(c1+abs(l[i]-l[i-2]),c2+abs(l[i]-l[i-1]))
  c1=t
print(c2)

Buggy submission (verdict: Runtime Error):
s,t=0,-1
for _ in range(int(input())):
    a,b,c=map(int,input().split())
    if t==1:
        if b>=c:
            s+=b
            t=2
        else:
            s+=c
            t=3
    elif t==2:
        if a>=c:
            s+=a
            t=1
        else:
            s+=c
            t=3
    elif t==3:
        if a>=b:
            s+=a
            t=1
        else:
            s+=b
            t=2
    else:
        if a>=b and a>=c:
            s=a
            t=1
        elif b>=c:
          	s=b
            t=2
        else:
          	s=c
            t=3
print(s)
Problem p03161 (python)

Fixed submission:
n,h=map(int,input().split())
l=list(map(int,input().split()))
c=[10**9]*n
c[0]=0
c[1]=abs(l[0]-l[1])
for i in range(2,n):
    c[i]=min( c[j]+abs(l[i]-l[j]) for j in range(max(0,i-h),i) )
print(c[-1])

Buggy submission (verdict: Runtime Error):
n,h=map(int,input().split())
l=list(map(int,input().split()))
c=[0]*n
c[1]=abs(l[0]-l[1])
for i in range(2,n):
    c[i]=min( c[j]+abs(l[i]-l[j]) for j in range(max(0,i-k),i) )
print(c[-1])

Buggy submission (verdict: Runtime Error):
n,h,l=int(input()),int(input()),list(map(int,input().split()))
c=[0]*n
c[1]=abs(l[0]-l[1])
for i in range(2,n):
  c[i]=min( c[i-j]+abs(l[i]-l[i-j]) for j in range(1,h+1) if i-j > -1 )
print(c[-1])
Problem p03162 (python)

Fixed submission:
n=int(input())
a,b,c=map(int,input().split())
for _ in range(1,n):
    aa,bb,cc=map(int,input().split())
    a,b,c=aa+max(b,c),bb+max(a,c),cc+max(a,b)
print(max(a,b,c))

Buggy submission (verdict: Runtime Error):
s=0,t=-1
for _ in range(int(input())):
    a,b,c=map(int,input().split())
    if t==1:
        if b>c:
            s+=b
            t=2
        else:
            s+=c
            t=3
    elif t==2:
        if a>c:
            s+=a
            t=1
        else:
            s+=c
            t=3
    elif t==3:
        if a>b:
            s+=a
            t=1
        else:
            s+=b
            t=2
    else:
        s+=max(a,b,c)
print(s)
Problem p03163 (python)

Fixed submission:
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
wv.sort()
cost=[[0]*(w+1) for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(w+1):
        if wv[i-1][0] <= j:
            cost[i][j]=max(wv[i-1][1]+cost[i-1][j-wv[i-1][0]],cost[i-1][j])
        else:
            cost[i][j]=cost[i-1][j]
print(cost[n][w])

Buggy submission (verdict: Runtime Error):
import numpy as np
n,w=map(int,input().split())
dp=np.zeros(w+1,dtype=np.int64)
for _ in range(n):
    we,v=map(int,input().split())
    if we > w:
        continue
    else:
        np.maximum(dp[we:],dp[:-we]+v,out = dp[we:])
print(dp[w])