Harryxun/testdata huggingface dataset:
Buggy python 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])



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 python 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]))

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 python submission (verdict: Time Limit Exceeded):
n,k=list(map(int,input().split()))
data=[int(x) for x in input().split()]
ans=[0]*n
for q in range(1,n):
    min=abs(data[q]-data[q-1])+ans[q-1]
    for w in range(q-2,q-k-1,-1):
        if(w>=0):
            val=abs(data[q]-data[w])+ans[w]
            #print(val)
            if(val<min):
                min=val
        else:
            break
    #print(min)
    ans[q]=min
print(ans[-1])


Fixed submission:
n,k=list(map(int,input().split()))
data=[int(x) for x in input().split()]
ans=[0]*n
for q in range(1,n):
    min=abs(data[q]-data[q-1])+ans[q-1]
    for w in range(q-2,q-k-1,-1):
        if(w>=0):
            val=abs(data[q]-data[w])+ans[w]
            #print(val)
            if(val<min):
                min=val
        else:
            break
    #print(min)
    ans[q]=min
print(ans[-1])
Buggy python 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))

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 python 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])

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 python submission (verdict: Time Limit Exceeded):
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])

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 python 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])

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 python 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])

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 python 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)

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 python submission (verdict: Time Limit Exceeded):
from collections import deque
def bfs(vertices, start):      
    q = deque()
    q.append(start)
    while q:
        u = q.popleft()                          
        for v in vertices[u]:
            if vis[v]==0 or (vis[u]+1>vis[v]) :
                vis[v]=vis[u]+1
                q.append(v)
    return max(vis)
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)
vis = [0]*(n+1) 
vis[0]=1
m=0
while 0 in vis:
	i=vis.index(0)
	vis[i]=1
	m=max(m,bfs(v,i))
print(m-1)

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 python 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()

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 python 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()

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 python 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])

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 python submission (verdict: Time Limit Exceeded):

n,k = map(int,input().split())
arr = list(map(int,input().split()))
dp = [float("inf")]*len(arr)
dp[0] = 0
for i in range(len(arr)):
    for jump in range(i+1,i+k+1):
        if(jump<len(arr)):
            dp[jump] = min(dp[jump],dp[i]+abs(arr[jump]-arr[i]))
print(dp[-1]) 

Fixed submission:

n,k = map(int,input().split())
arr = list(map(int,input().split()))
dp = [float("inf")]*len(arr)
dp[0] = 0
cost = 0
for i in range(len(arr)):
    for jump in range(i+1,i+k+1):
        if(jump<len(arr)):
            dp[jump] = min(dp[jump],dp[i]+abs(arr[jump]-arr[i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):

if __name__ == "__main__":
    n,k = map(int,input().split())
    arr = list(map(int,input().split()))
    dp = [float("inf")]*len(arr)
    dp[0] = 0
    cost = 0
    for i in range(len(arr)):
        for jump in range(i+1,i+k+1):
            if(jump<len(arr)):
                dp[jump] = min(dp[jump],dp[i]+abs(arr[jump]-arr[i]))
    print(dp[-1]) 

Fixed submission:

n,k = map(int,input().split())
arr = list(map(int,input().split()))
dp = [float("inf")]*len(arr)
dp[0] = 0
cost = 0
for i in range(len(arr)):
    for jump in range(i+1,i+k+1):
        if(jump<len(arr)):
            dp[jump] = min(dp[jump],dp[i]+abs(arr[jump]-arr[i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):

if __name__ == "__main__":
    n,k = map(int,input().split())
    arr = list(map(int,input().split()))
    dp = [float("inf")]*len(arr)
    curr = 1 
    dp[0] = 0
    dp[1] = abs(arr[1]-arr[0])
    cost = 0
    for i in range(2,len(arr)):
        x = i-1
        c = 0
        while(x>=0 and c<k):
            dp[i]= min(dp[i],dp[x]+abs(arr[i]-arr[x]))
            x -= 1
            c += 1 
    print(dp[-1]) 

Fixed submission:

n,k = map(int,input().split())
arr = list(map(int,input().split()))
dp = [float("inf")]*len(arr)
dp[0] = 0
cost = 0
for i in range(len(arr)):
    for jump in range(i+1,i+k+1):
        if(jump<len(arr)):
            dp[jump] = min(dp[jump],dp[i]+abs(arr[jump]-arr[i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):

if __name__ == "__main__":
    n,k = map(int,input().split())
    arr = list(map(int,input().split()))
    dp = [-1]*len(arr)
    curr = 1 
    dp[0] = 0
    dp[1] = abs(arr[1]-arr[0])
    cost = 0
    for i in range(2,len(arr)):
        m = float("inf")
        x = i-1
        c = 0
        while(x>=0 and c<k):
            m= min(m,dp[x]+abs(arr[i]-arr[x]))
            x -= 1
            c += 1 
        dp[i] = m
    print(dp[-1]) 

Fixed submission:

n,k = map(int,input().split())
arr = list(map(int,input().split()))
dp = [float("inf")]*len(arr)
dp[0] = 0
cost = 0
for i in range(len(arr)):
    for jump in range(i+1,i+k+1):
        if(jump<len(arr)):
            dp[jump] = min(dp[jump],dp[i]+abs(arr[jump]-arr[i]))
print(dp[-1])
Buggy python 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])


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 python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys


def DP_K(h,dp,k,i):
    ans = sys.maxsize
    for j in range(1,min(i,k)+1):
        ml = abs( h[i] - h[i-j] ) + dp[i-j]
        ans = min( ans, ml)
    return ans


def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    
    for i in range(1,N):
       dp[i] =  DP_K(h,dp,K,i)
        
    print(dp[-1])
    
    
if __name__=='__main__':
    main()

Fixed submission:
import numpy as np

if __name__=='__main__':
    N,K = map(int,input().split())
    hight = list( map(int,input().split()))
    hight = np.array(hight + [0]*(K+2))
    max_h = 10**9
    dp = [max_h]*(N+K+2)
    dp[0] = 0
    dp = np.array(dp)

    for i in range(N):
        a = hight[i]
        b = hight[i+1:i+K+1]
        np_abs = np.abs(b-a)
        dp[i+1:i+K+1] = np.minimum(np_abs+dp[i],dp[i+1:i+K+1])

        
    print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = (int(x) for x in input().split())
dp = [0] * (W+1) # Maximum value of items we can carry at weight
for _ in range(N):
  w, v = (int(x) for x in input().split())
  for cur in range(W, w-1, -1):
    dp[cur] = max(dp[cur-w]+v, dp[cur])

print(dp[W])

Fixed submission:
N, W = (int(x) for x in input().split())
dp = [0] * (W+1) # Maximum value of items we can carry at weight
for _ in range(N):
  w, v = (int(x) for x in input().split())
  for cur in range(W, w-1, -1):
    dp[cur] = max(dp[cur-w]+v, dp[cur])

print(dp[W])
Buggy python 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])

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 python 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])

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 python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
l=list(map(int,input().split()))
d=[0]*n
d[0]=0
for i in range(1,n):
    x=l[i]
    d[i]=min([d[j]+abs(l[j]-x) for j in range(max(0,i-k),i)])
print(d[n-1])

Fixed submission:
n,k=map(int,input().split())
h=list(map(int, input().split()))
v=[0]*n
for i in range(1,n):
	u = h[i]
	v[i] = min([v[j] + abs(h[j]-u) for j in range(max(0, i-k), i)])
print(v[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
l=list(map(int,input().split()))
d=[0]*n
d[0]=0
for i in range(1,n):
    x=l[i]
    d[i]=min([d[j]+abs(x-l[j]) for j in range(max(0,i-k),i)])
print(d[n-1])

Fixed submission:
n,k=map(int,input().split())
h=list(map(int, input().split()))
v=[0]*n
for i in range(1,n):
	u = h[i]
	v[i] = min([v[j] + abs(h[j]-u) for j in range(max(0, i-k), i)])
print(v[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
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[n-1])

Fixed submission:
n,k=map(int,input().split())
h=list(map(int, input().split()))
v=[0]*n
for i in range(1,n):
	u = h[i]
	v[i] = min([v[j] + abs(h[j]-u) for j in range(max(0, i-k), i)])
print(v[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
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[n-1])

Fixed submission:
n,k=map(int,input().split())
h=list(map(int, input().split()))
v=[0]*n
for i in range(1,n):
	u = h[i]
	v[i] = min([v[j] + abs(h[j]-u) for j in range(max(0, i-k), i)])
print(v[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
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])

Fixed submission:
n,k=map(int,input().split())
h=list(map(int, input().split()))
v=[0]*n
for i in range(1,n):
	u = h[i]
	v[i] = min([v[j] + abs(h[j]-u) for j in range(max(0, i-k), i)])
print(v[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
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])

Fixed submission:
n,k=map(int,input().split())
h=list(map(int, input().split()))
v=[0]*n
for i in range(1,n):
	u = h[i]
	v[i] = min([v[j] + abs(h[j]-u) for j in range(max(0, i-k), i)])
print(v[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
l=list(map(int,input().split()))
dp=[0 for i in range(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])

Fixed submission:
n,k=map(int,input().split())
h=list(map(int, input().split()))
v=[0]*n
for i in range(1,n):
	u = h[i]
	v[i] = min([v[j] + abs(h[j]-u) for j in range(max(0, i-k), i)])
print(v[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
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])

Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
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])

Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
s=input()
t=input()
n1,n2=len(s),len(t)
dp=[[0]*(n1+1) for i in range(n2+1)]
st=''
for i in range(1,n2+1):
    for j in range(1,n1+1):
        if s[j-1]==t[i-1]:
            dp[i][j]=dp[i-1][j-1]+1
            #st+=s[j-1]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
while i>0 and j>0:
    if t[i-1]==s[j-1]:
        st=s[j-1]+st
        i-=1
        j-=1
    elif dp[i][j-1]>dp[i-1][j]:
        j-=1
    else:
        i-=1
print(st)

Fixed submission:
s=input()
t=input()
n1,n2=len(s),len(t)
dp=[[0]*(n1+1) for i in range(n2+1)]
st=''
for i in range(1,n2+1):
    for j in range(1,n1+1):
        if s[j-1]==t[i-1]:
            dp[i][j]=dp[i-1][j-1]+1
            #st+=s[j-1]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
while i>0 and j>0:
    if t[i-1]==s[j-1]:
        st=s[j-1]+st
        i-=1
        j-=1
    elif dp[i][j-1]>dp[i-1][j]:
        j-=1
    else:
        i-=1
print(st)