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

Fixed submission:
def knapSack(W, wt, val, n): 
	K = [[0 for x in range(W+1)] for x in range(n+1)] 

	
	for i in range(n+1): 
		for w in range(W+1): 
			if i==0 or w==0: 
				K[i][w] = 0
			elif wt[i-1] <= w: 
				K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]) 
			else: 
				K[i][w] = K[i-1][w] 

	return K[n][W] 




q=list(map(int,input().split()))
n=q[0]
W=q[1]
v=[0]*n
w=[0]*n
for _ in range(n):
  r=list(map(int,input().split()))
  w[_]=r[0]
  v[_]=r[1]
  




print(knapSack(W,w,v,n))

Buggy submission (verdict: Runtime Error):
l=list(map(int,input().split.()))
n=l[0]
w=l[1]
wa=[0]*n
va=[0]*n
for i in range(n):
  ll=list(map(int,input().split.()))
  wa[i]=ll[0]
  va[i]=ll[1]
dp=[[0 for j in range(w+1)] for i in range(n+1)]
for i in range(1,n+1):
  for j in range(1,w+1):
    if wa[i-1]<j:
      dp[i][j]=dp[i-1][j]
    else:
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-wa[i-1]]+va[i-1])
print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
l=list(map(int,input().split.()))
n=l[0]
w=l[1]
wa=[0]*n
va=[0]*n
for i in range(n):
  g=input()
  wa[i]=int(g[0])
  va[i]=int(g[2])
dp=[[0 for j in range(w+1)] for i in range(n+1)]
for i in range(1,n+1):
  for j in range(1,w+1):
    if wa[i-1]<j:
      dp[i][j]=dp[i-1][j]
    else:
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-wa[i-1]]+va[i-1])
print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
# A Dynamic Programming based Python Program for 0-1 Knapsack problem 
# Returns the maximum value that can be put in a knapsack of capacity W 
def knapSack(W, wt, val, n): 
	K = [[0 for x in range(W+1)] for x in range(n+1)] 

	# Build table K[][] in bottom up manner 
	for i in range(n+1): 
		for w in range(W+1): 
			if i==0 or w==0: 
				K[i][w] = 0
			elif wt[i-1] <= w: 
				K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]) 
			else: 
				K[i][w] = K[i-1][w] 

	return K[n][W] 




q=list(map(int,input().split()))
n=q[0]
W=q[1]
v=[0]*n
w=[0]*n
for _ in range(n):
  r=list(map(int,input().split()))
  w[_]=r[0]
  v[_]=r[1]
  




print(knapsack(W,w,v,n))

Buggy submission (verdict: Runtime Error):

def knapsack(W,v,w,n,d):
    
    if n<0:
        return 0
    
    if d[W][n]!=-1:
        return d[W][n]
    if w[n]>W:
        d[W][n]=knapsack(W,v,w,n-1,d)
        return d[W][n]
    else:
        d[W][n]=max(v[n]+ knapsack(W-w[n],v,w,n-1,d),knapsack(W,v,w,n-1,d))
        return d[W][n]


q=list(map(int,input().split()))
n=q[0]
W=q[1]
v=[0]*n
w=[0]*n
for _ in range(n):
  r=list(map(int,input().split()))
  w[_]=r[0]
  v[-]=r[1]
  



d=[[-1 for j in range(n+1)] for i in range(W+1)]
print(knapsack(W,v,w,n-1,d))
Problem p03165 (python)

Fixed submission:
s1 = list(input())
s2 = list(input())
n = len(s1)
m = len(s2)
dp = [[0]*(m+1) for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(1, m+1):
        if s1[i-1] == s2[j-1]:
            dp[i][j] = 1 + dp[i-1][j-1]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
res = []
i, j = n, m
while i > 0 and j > 0:
    if dp[i][j] == dp[i][j-1]:
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else:
        res.append(s1[i-1])
        i -= 1
        j -= 1
print(''.join(res[::-1]))

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.buffer.readline
s1 = input()
s2 = input()
n, m = len(s1), len(s2)
dp = [[0]*(m+1) for _ in range(n+1)]
prev = dp[0]
for i in range(1,n+1):
    dpi = dp[i]
    for j in range(1, m+1):
        if s1[i-1] == s2[j-1]:
            dpi[j] = 1 + prev[j-1]
        else:
            dpi[j] = max(prev[j], dpi[j-1])
    prev = dpi
res = ''
i, j = n, m
while i > 0 and j > 0:
    if dp[i][j] == dp[i][j-1]:
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else:
        res = s1[i-1] + res
        i -= 1
        j -= 1
print(res)
Problem p03160 (python)

Fixed submission:
a=int(input())
b=list(map(int,input().split()))
dp=[0]
dp.append(abs(b[0]-b[1]))
for i in range(2,len(b)):
    h1=abs(b[i]-b[i-1])+dp[i-1]
    h2=abs(b[i-2]-b[i])+dp[i-2]
    dp.append(min(h1,h2))
print(dp[a-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
b=list(map(int,input().split()))
dp=[0]
dp.append(abs(b[0]-b[1]))
for i in range(2,n):
    k=10**9
    for j in range(1,k+1):
        if i-j<0:
            break
        else:
            k=min(abs(b[i]-b[i-j])+dp[i-j],k)
    dp.append(k)
print(dp[n-1])
Problem p03160 (python)

Fixed submission:
n=int(input())
data=[int(x) for x in input().split()]
ans=[0]*n
ans[0]=0
ans[1]=abs(data[1]-data[0])
for q in range(2,n):
    temp2=abs(data[q]-data[q-2])+ans[q-2]
    temp1=abs(data[q]-data[q-1])+ans[q-1]
    if(temp2<temp1):
        ans[q]=temp2
    else:
        ans[q]=temp1
print(ans[-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
data=[]
t=[[0 for x in range(4)] for w in range(n+1)]
for _ in range(n):
    temp=[int(x) for x in input().split()]
    data.append(temp)
for i in range(1,n+1):
    for j in range(1,4):
        large=0
        for w in range(1,4):
            if(w==j):
                continue
            else:
                if(t[i-1][w]>large):
                    large=t[i-1][w]
        t[i][j]=data[i-1][j-1]+large
print(max(t[-1]))
Problem p03162 (python)

Fixed submission:
n=int(input())
data=[]
t=[[0 for x in range(4)] for w in range(n+1)]
for _ in range(n):
    temp=[int(x) for x in input().split()]
    data.append(temp)
for i in range(1,n+1):
    for j in range(1,4):
        large=0
        for w in range(1,4):
            if(w==j):
                continue
            else:
                if(t[i-1][w]>large):
                    large=t[i-1][w]
        t[i][j]=data[i-1][j-1]+large
print(max(t[-1]))

Buggy submission (verdict: Runtime Error):
def solve(n,pos):
    global data,helper
    if(n==-1):
        return 0
    if(helper[n][pos]!=-1):
        return helper[n][pos]
    if(pos==0):
        helper[n][pos]=max(data[n][1]+solve(n-1,1),data[n][2]+solve(n-1,2))
        return helper[n][pos]
    elif(pos==1):
        helper[n][pos] = max(data[n][0]+solve(n-1,0),data[n][2]+solve(n-1,2))
        return helper[n][pos]
    else:
        helper[n][pos] = max(data[n][1]+solve(n-1,1),data[n][0]+solve(n-1,0))
        return helper[n][pos]
n=int(input())
data=[]
helper=[[-1 for y in range(3)] for x in range(n)]
for _ in range(n):
    temp=[int(x) for x in input().split()]
    data.append(temp)
t1=data[-1][0]+solve(n-2,0)
t2=data[-1][1]+solve(n-2,1)
t3=data[-1][2]+solve(n-2,2)
print(max(t1,t2,t3))
Problem p03160 (python)

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

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[int(x) for x in input().split()]
c=0
f=[99999999999]*(n)
f[0]=0
for i in range(n):
    for j in range(i+1,i+k+1):
        if j<n:
            f[j]=min(f[j],f[i]+abs(a[i]-a[j]))
print(f[n-1])
Problem p03161 (python)

Fixed submission:
n,k=map(int,input().split())
a=[int(x) for x in input().split()]
c=0
f=[99999999999]*(n)
f[0]=0
for i in range(n):
    for j in range(i+1,i+k+1):
        if j<n:
            f[j]=min(f[j],f[i]+abs(a[i]-a[j]))
print(f[n-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[int(x) for x in input().split()]
c=0
f=[0]*(99999999)
for i in range(n):
    for j in range(i+1,i+k+1):
        f[j]=min(f[j],f[i]+abs(a[i]-a[j]))
print(f[n-1])
Problem p03164 (python)

Fixed submission:
n,w=map(int,input().split())
a,b=[0]*n,[0]*n
for i in range(n):a[i],b[i]=map(int,input().split())
mv=sum(b)
dp=[[10**10 if j!=0 else 0 for j in range(mv+1)]for i in range(n+1)]
for i in range(1,n+1):
	for j in range(1,mv+1):
		if j<b[i-1]:dp[i][j]=dp[i-1][j]
		else:dp[i][j]=min(dp[i-1][j],a[i-1]+dp[i-1][j-b[i-1]])
ans=0
for i in range(mv+1):
	if dp[-1][i]<=w:ans=i
print(ans)

Buggy submission (verdict: Runtime Error):
n,w=map(int,input().split())
a,b=[0]*n,[0]*n
for i in range(n):a[i],b[i]=map(int,input().split())
dp=[[0]*(w+1) for i in range(n+1)]
for i in range(1,n+1):
	for j in range(1,w+1):
		if j<a[i-1]:dp[i][j]=dp[i-1][j]
		else:dp[i][j]=max(dp[i-1][j],b[i-1]+dp[i-1][j-a[i-1]])
print(dp[-1][-1])
Problem p03166 (python)

Fixed submission:
import sys
input=sys.stdin.readline
#for _ in range(int(input())):
#	n=int(input())
#	n,m=map(int,input().split())
#	s=input().strip()
sys.setrecursionlimit(10**9)
def dfs(i):
	if dp[i]!=-1:return dp[i]
	c=0
	for j in v[i]:c=max(c,dfs(j)+1)
	dp[i]=c
	return c

n,m=map(int,input().split())
v=[[] for i in range(n+1)]
for i in range(m):
	x,y=map(int,input().split())
	v[x].append(y)
dp = [-1]*(n+1) 
m=0
for i in range(1,n+1):
	m=max(m,dfs(i))
print(m)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
#for _ in range(int(input())):
#	n=int(input())
#	n,m=map(int,input().split())
#	s=input().strip()

def dfs(i):
	if dp[i]!=-1:return dp[i]
	c=0
	for j in v[i]:c=max(c,dfs(j)+1)
	dp[i]=c
	return c

n,m=map(int,input().split())
v=[[] for i in range(n+1)]
for i in range(m):
	x,y=map(int,input().split())
	v[x].append(y)
dp = [-1]*(n+1) 
m=0
for i in range(1,n+1):
	m=max(m,dfs(i))
print(m)
Problem p03160 (python)

Fixed submission:
def frog1(a,n):
  dp=[0]*(n)
  dp[0]=0
  dp[1]=abs(a[1]-a[0])
  for i in range(2,n):
    dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]))
  return dp[-1]
 
def main():
  n=int(input())
  a=list(map(int,input().split()))
  print(frog1(a,n))
 
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def frog1(a,n):
  dp=[0]*(n)
  dp[0]=0
  dp[1]=abs(a[1],a[0])
  for i in range(2,n):
    dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]))
  return dp[-1]

def main():
  n=int(input())
  a=list(map(int,input().split()))
  print(frog1(a,n))
 
if __name__ == '__main__':
    main()
Problem p03162 (python)

Fixed submission:
def main():
    n=int(input())
    dp=[0]*(3)
    for _ in range(n):
        dp1=[0]*3 
        nums=list(map(int,input().split()))
        for i in range(3):
            for j in range(3):
                if i!=j:
                    dp1[j]=max(dp1[j],dp[i]+nums[j])
            
        dp=dp1
    print( max(dp[0],dp[1],dp[2]))
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def calculate(m,n):
  dp=[[0 for j in range(n)] for i in range(n)]
  best=0
  for i in range(n):
    for j in range(n):
        if i!=j:
            dp[i][j]=max(dp[i][j],dp[i][j]+m[i][j]) 
    best+=max(dp[i])
  return best
 
def main():
    n=int(input())
    m=[[n]]*(n)
    for i in range(n):
        m[i]=list(map(int,input().split())) 
    print(calculate(m,n))
 
if __name__ == '__main__':
    main()
Problem p03160 (python)

Fixed submission:
    
n = int( input() )
arr = list( map( int , input().strip().split(" ") ) )

dp = [ 0 for i in range(n) ]

for i in range(1,n):

    #one jump
    cost1 = abs(arr[i] - arr[i-1]) + dp[i-1] 
    cost2 = cost1 + 2
    # two jump
    if i != 1:
        cost2 = abs(arr[i] - arr[i-2]) + dp[i-2]

    dp[i] = min( cost1  ,cost2 )

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
input = open('file.txt').readline

    
n = int( input() )
arr = list( map( int , input().strip().split(" ") ) )

dp = [ 0 for i in range(n) ]

for i in range(1,n):

    #one jump
    cost1 = abs(arr[i] - arr[i-1]) + dp[i-1] 
    cost2 = cost1 + 2
    # two jump
    if i != 1:
        cost2 = abs(arr[i] - arr[i-2]) + dp[i-2]

    dp[i] = min( cost1  ,cost2 )

print(dp[n-1])
Problem p03160 (python)

Fixed submission:
inf = float("inf")

minPaths = {}
weights = {}

stone = int(input())
wei = tuple(map(int, input().split()))

for i in range (stone):
  minPaths[i+1] = inf
  weights[i+1] = wei[i]

#find shortest paths
minPaths[1] = 0

for node in range(1, stone + 1):
  cWeight = minPaths[node]
  
  #calculate to nwxt 2 nodes
  try:
    toP1 = abs(weights[node] - weights[node+1])
    if toP1 + cWeight < minPaths[node+1]:
      minPaths[node+1] = toP1 + cWeight

    toP2 = abs(weights[node] - weights[node+2])
    if toP2 + cWeight < minPaths[node+2]:
      minPaths[node+2] = toP2 + cWeight
  except KeyError:
    None
print (minPaths[stone])

Buggy submission (verdict: Runtime Error):
inf = float("inf")

minPaths = {}

stone, jump = map(int, input().split())
weights = tuple(map(int, input().split()))

for i in range (stone):
  minPaths[i+1] = inf

#find shortest paths
minPaths[1] = 0

for node in range(1, stone + 1):
  cWeight = minPaths[node]
  
  #calculate to next K nodes
  try:
    for go in range (1, jump + 1):
    	toNext = abs(weights[node-1] - weights[node+go-1])
        
    	if minPaths[node + go] > cWeight + toNext:
          minPaths[node + go] = cWeight + toNext
  except KeyError:
    None
print (minPaths[stone])
Problem p03160 (python)

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

Buggy submission (verdict: Runtime Error):
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
#wv.sort()
dp=[[0]*(w+1) for _ in range(n)]
for i in range(1,w+1):
    if i<wv[0][0]:
        dp[0][i]=0
    else:
        dp[0][i]=wv[0][1]
for i in range(1,n):
    for j in range(1,w+1):
        if wv[i][0]>j:
            dp[i][j]=dp[i-1][j]
        else:
            wleft=j-wv[i][0]
            dp[i][j]=max(wv[i][1]+dp[i-1][wleft],dp[i-1][j])
print(dp[-1][-1])

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

Fixed submission:
n = int(input())
arr = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
for i in range(1,n):
    op1 = abs(arr[i]-arr[i-1]) + dp[i-1]
    op2 = abs(arr[i]-arr[i-2]) + dp[i-2] if i != 1 else float("inf")
    dp[i] = min(op1,op2)
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
def getMinCost(arr,i,n,cache):
    if i > n-2:
        return 0
    if cache[i] != float("inf"): return cache[i]
    op1 = abs(arr[i] - arr[i+1]) + getMinCost(arr,i+1,n,cache)
    op2 = abs(arr[i] - arr[i+2]) + getMinCost(arr,i+2,n,cache) if i != n-2 else float("inf")
    cache[i] = min(op1,op2)
    return cache[i]

n = int(input())
arr = [int(i) for i in input().split()]
cache = [float("inf") for i in range(n)]
print(getMinCost(arr,0,n,cache))

Buggy submission (verdict: Runtime Error):
def getMinCost(arr,i,n,cache):
    if i >= n-1:
        return 0
    if cache[i] != 0: return cache[i]
    op1 = abs(arr[i] - arr[i+1]) + getMinCost(arr,i+1,n,cache)
    op2 = abs(arr[i] - arr[i+2]) + getMinCost(arr,i+2,n,cache) if i != n-2 else float("inf")
    cache[i] = min(op1,op2)
    return cache[i]

n = int(input())
arr = [int(i) for i in input().split()]
cache = [0 for i in range(n)]
print(getMinCost(arr,0,n,cache))

Buggy submission (verdict: Runtime Error):
def getMinCost(arr,i,n,cache):
    if i >= n-1:
        return 0
    if cache[i] != -1: return cache[i]
    op1 = abs(arr[i] - arr[i+1]) + getMinCost(arr,i+1,n,cache)
    op2 = abs(arr[i] - arr[i+2]) + getMinCost(arr,i+2,n,cache) if i <= len(arr)-3 else float("inf")
    cache[i] = min(op1,op2)
    return cache[i]

n = int(input())
arr = [int(i) for i in input().split()]
cache = [-1 for i in range(n)]
print(getMinCost(arr,0,n,cache))

Buggy submission (verdict: Runtime Error):
n - int(input())
arr = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
for i in range(1,n):
    op1 = abs(arr[i]-arr[i-1]) + dp[i-1]
    op2 = abs(arr[i]-arr[i-2]) + dp[i-2]
    dp[i] = min(op1,op2)
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n - int(input())
arr = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
for i in range(1,n):
    op1 = abs(arr[i]-arr[i-1]) + dp[i-1]
    op2 = abs(arr[i]-arr[i-2]) + dp[i-2]
    dp[i] = min(op1,op2)
dp[n-1]

Buggy submission (verdict: Runtime Error):
def getMinCostJump(arr,i,n,cache):
    if i > n: return 0
    if i == n: return 0
    if cache[i] != 0:
        return cache[i]
    op1,op2 = 0,0
    if (i+1) < n:
        op1 += abs(arr[i] -arr[i+1]) + getMinCostJump(arr,i+1,n,cache)
    if (i+2) < n:
        op2 += abs(arr[i] -arr[i+2]) + getMinCostJump(arr,i+2,n,cache)
    cache[i] = min(op1,op2)
    return cache[i]
n = int(input())
arr = [int(i) for i in input().split()]
cache = [0 for i in range(n+1)]
print(getMinCostJump(arr,0,n,cache))
Problem p03161 (python)

Fixed submission:
n,k = map(int,input().split())
arr = [int(i) for i in input().split()]
dp = [float("inf")] * 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],abs(arr[i]-arr[j]) + dp[i])
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
def getMinCost(arr,i,k):
    if i <= 0: return 0
    mins = float("inf")
    for j in range(1,k+1):
        if j <= i:
            mins = min(mins,abs(arr[i]-arr[i-j]) + getMinCost(arr,i-j,k))
    return mins

n,k = map(int,input().split())
arr = [int(i) for i in input().split()]
print(getMinCost(arr,len(arr)-1,k))
Problem p03162 (python)

Fixed submission:
N = int(input())
matrix = []
for i in range(N):
    matrix.append([int(i) for i in input().split()])
ans = -float("inf")
dp = [[0 for i in range(4)] for j in range(len(matrix)+1)]
for i in range(len(matrix)-1,-1,-1):
    for j in range(len(matrix[0])-1,-1,-1):
        dp[i][j] = -float("inf")
        for k in range(3):
            if j != k:
                dp[i][j] = max(dp[i][j],dp[i+1][k]+matrix[i][j])
        ans = max(ans,dp[i][j])
print(ans)

Buggy submission (verdict: Runtime Error):
def pathSmMax(matrix,i,j,cache):
    if i > len(matrix)-1: return 0
    happiness = 0
    if cache[i][j] != 0:
        return cache[i][j]
    for k in range(3):
        if k != j:
            cache[i][j] = max(cache[i][j],pathSmMax(matrix,i+1,k,cache) + matrix[i][j])
    return cache[i][j]
N = int(input())
matrix = []
for i in range(N):
    matrix.append([int(i) for i in input().split()])
maxs = -float("inf")
cache = [[0 for i in range(4)] for j in range(len(matrix)+1)]
for i in range(len(matrix)):
    maxs = max(maxs,pathSmMax(matrix,0,i,cache))
print(maxs)

Buggy submission (verdict: Runtime Error):
def pathSmMax(matrix,i,j,cache):
    if i > len(matrix)-1: return 0
    happiness = 0
    if cache[i][j] != 0:
        return cache[i][j]
    for k in range(3):
        if k != j:
            happiness = max(happiness,pathSmMax(matrix,i+1,k,cache) + matrix[i][j])
    cache[i][j] = happiness
    return cache[i][j]
N = int(input())
matrix = []
for i in range(N):
	matrix.append([int(i) for i in input().split()])
maxs = -float("inf")
cache = [[0 for i in range(4)] for j in range(len(matrix)+1)]
for i in range(len(matrix)):
    maxs = max(maxs,pathSmMax(matrix,0,i,cache))
print(maxs)

Buggy submission (verdict: Runtime Error):
def pathSmMax(matrix,i,j,cache):
    if i < 0 or j < 0 or i > len(matrix)-1 or j > len(matrix[0])-1: return 0
    happiness = -float("inf")
    if cache[i][j] != 0:
        return cache[i][j]
    for k in range(3):
        if k != j:
            happiness = max(happiness,pathSmMax(matrix,i+1,k,cache) + matrix[i][j])
    cache[i][j] = happiness
    return cache[i][j]
N = int(input())
matrix = []
for i in range(N):
    matrix.append([int(i) for i in input().split()])
maxs = -float("inf")
cache = [[0 for i in range(len(matrix[0])+1)] for j in range(len(matrix)+1)]
for i in range(len(matrix)):
    maxs = max(maxs,pathSmMax(matrix,0,i,cache))
print(maxs)
Problem p03164 (python)

Fixed submission:
N,W = map(int,input().split())
weight = [0]
value = [0]
for i in range(N):
    w,v = map(int,input().split())
    weight.append(w)
    value.append(v)
    
maxValue = sum(value)
INF = 10**10
dp = [[INF for i in range(maxValue+1)] for j in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0
for i in range(1,N+1):
    for v in range(1,maxValue+1):
        if value[i] <= v:
            dp[i][v] = min(dp[i-1][v],weight[i] + dp[i-1][v-value[i]])
        else:
            dp[i][v] = dp[i-1][v]
ans = 0
for x in range(maxValue+1):
    if dp[N][x] <= W:
        ans = x
print(ans)

Buggy submission (verdict: Runtime Error):
N,W = map(int,input().split())
weight = []
value = []
for i in range(N):
    w,v = map(int,input().split())
    weight.append(w)
    value.append(v)
maxValue = N*1000
dp = [[float("inf") for i in range(maxValue+1)] for j in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0

for i in range(1,N+1):
    for v in range(1,maxValue+1):
        dp[i][v] = dp[i-1][v]
        if value[i] > v: continue;
        dp[i][v] = min(dp[i][v],weight[i] + dp[i-1][v-value[i]])
ans = 0
for x in range(maxValue+1):
    if dp[N][x] <= W:
        ans = x
print(ans)
Problem p03244 (python)

Fixed submission:
from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
cnt1 = Counter(a[::2]).most_common(2)
c11, c12 = (cnt1 if len(cnt1) == 2 else cnt1+[('', 0)])
cnt2 = Counter(a[1::2]).most_common(2)
c21, c22 = (cnt2 if len(cnt2) == 2 else cnt2+[('', 0)])

if c11[0] != c21[0]:
    print(n - c11[1] - c21[1])
else:
    print(n - max(c11[1]+c22[1], c12[1]+c21[1]))

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
cnt1 = Counter(a[::2]).most_common(2)
c11, c12 = (cnt1 if len(cnt1) == 2 else cnt1+[('', 0)])
cnt2 = Counter(a[1::2]).most_common(2)
c21, c22 = (cnt2 if len(cnt2) == 2 else cnt2+[('', 0)])

if c11[0] != c21[0]:
    print(n - c11[1] - c21[1])
else:
    print(n - max(c11[1]+c22[1], c12[1]+c21[1]))

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
 
c1 = Counter(a[::2])
c2 = Counter(a[1::2])
c1f1 = max(c1, key = lambda k:c1[k])
c2f1 = max(c2, key = lambda k:c2[k])
 
if c1f1 != c2f1:
  return n - c1[c1f1] - c2[c2f1]
else:
  if c1[c1f1] > c2[c2f1]:
    del c2[c2f1]
    if not c2: return n-c1[c1f1]
    c2f1 = max(c2, key = lambda k:c2[k])
    return n-c1[c1f1] - c2[c2f1]
  else:
    del c1[c1f1]
    if not c1: return n-c2[c2f1]
    c1f1 = max(c1, key = lambda k:c1[k])
    return n-c1[c1f1] - c2[c2f1]