Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,v=[int(k) for k in input().split()]
li=[]
for i in range(n):
  li.append([int(k) for k in input().split()])
  
dp=[[0 for i in range(v+1)] for j in range(n+1)]
for a in range(1,n+1):
  for b in range(1,v+1):
    if(li[a-1][0]<=b):
      dp[a][b]=max(li[a-1][1]+dp[a-1][b-li[a-1][0]],dp[a-1][b])
    else:
      dp[a][b]=dp[a-1][b]
print(dp[n][v])      
      
  


Fixed submission:
n,w=[int(k) for k in input().split()]
li=[]
 
 
ans=0
for i in range(n):
    li.append([int(k) for k in input().split()])
dp=[[0 for i in range(100001)] for j in range(n+1)]
for i in range(1,100001):
    dp[0][i]=10**10
dp[0][0]=0    
for a in range(1,n+1):
    for b in range(0,100001):
        if(li[a-1][1]<=b):
            x=li[a-1][0]+dp[a-1][b-li[a-1][1]]
            y=dp[a-1][b]
            dp[a][b]=min(x,y)
        else:
            dp[a][b]=dp[a-1][b]
        if dp[a][b]<=w:
          ans=max(ans,b)
 
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,v=[int(k) for k in input().split()]
li=[]
for i in range(n):
  li.append([int(k) for k in input().split()])
  
dp=[[0 for i in range(v+1)] for j in range(n+1)]
for a in range(1,n+1):
  for b in range(1,v+1):
    if(li[a-1][0]<=b):
      dp[a][b]=max(li[a-1][1]+dp[a-1][b-li[a-1][0]],dp[a-1][b])
    else:
      dp[a][b]=dp[a-1][b]
print(dp[n][v])      
      
  


Fixed submission:
n,w=[int(k) for k in input().split()]
li=[]
 
 
ans=0
for i in range(n):
    li.append([int(k) for k in input().split()])
dp=[[0 for i in range(100001)] for j in range(n+1)]
for i in range(1,100001):
    dp[0][i]=10**10
dp[0][0]=0    
for a in range(1,n+1):
    for b in range(0,100001):
        if(li[a-1][1]<=b):
            x=li[a-1][0]+dp[a-1][b-li[a-1][1]]
            y=dp[a-1][b]
            dp[a][b]=min(x,y)
        else:
            dp[a][b]=dp[a-1][b]
        if dp[a][b]<=w:
          ans=max(ans,b)
 
 
print(ans)
Buggy python submission (verdict: Runtime Error):
def dfs(a,adjl,visited,dp):
  for i in adjl[a]:
    if visited[i]==0:
      visited[i]=1
      dfs(i,adjl,visited,dp)
 
    dp[a]=max(dp[a],1+dp[i])
n,m=map(int,input().split())
li=[]
for i in range(m):
  li.append([int(k) for k in input().split()])
adjl=[[] for j in range(n+1)]
for k in range(len(li)):
  adjl[li[k][0]].append(li[k][1])
visited=[0]*(n+1)
dp=[0]*(n+1)
for a in range(1,n+1):
  if visited[a]==0:
    visited[a]=1
    dfs(a,adjl,visited,dp)
print(max(dp))

  

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
def dfs(a,adjl,visited,dp):
  for i in adjl[a]:
    if visited[i]==0:
      visited[i]=1
      dfs(i,adjl,visited,dp)
 
    dp[a]=max(dp[a],1+dp[i])
n,m=map(int,input().split())
li=[]
for i in range(m):
  li.append([int(k) for k in input().split()])
adjl=[[] for j in range(n+1)]
for k in range(len(li)):
  adjl[li[k][0]].append(li[k][1])
visited=[0]*(n+1)
dp=[0]*(n+1)
for a in range(1,n+1):
  if visited[a]==0:
    visited[a]=1
    dfs(a,adjl,visited,dp)
print(max(dp))

Buggy python submission (verdict: Runtime Error):
def dfs(a,adjl,visited,dp):
  for i in adjl[a]:
    if visited[i]==0:
      visited[i]=1
      dfs(i,adjl,visited,dp)
 
    dp[a]=max(dp[a],1+dp[i])
n,m=map(int,input().split())
li=[]
for i in range(m):
  li.append([int(k) for k in input().split()])
adjl=[[] for j in range(n+1)]
for k in range(len(li)):
  adjl[li[k][0]].append(li[k][1])
visited=[0]*(n+1)
dp=[0]*(n+1)
for a in range(1,n+1):
  if visited[a]==0:
    visited[a]=1
    dfs(a,adjl,visited,dp)
print(max(dp))

  
  


Fixed submission:
import sys
sys.setrecursionlimit(10**9)
def dfs(a,adjl,visited,dp):
  for i in adjl[a]:
    if visited[i]==0:
      visited[i]=1
      dfs(i,adjl,visited,dp)
 
    dp[a]=max(dp[a],1+dp[i])
n,m=map(int,input().split())
li=[]
for i in range(m):
  li.append([int(k) for k in input().split()])
adjl=[[] for j in range(n+1)]
for k in range(len(li)):
  adjl[li[k][0]].append(li[k][1])
visited=[0]*(n+1)
dp=[0]*(n+1)
for a in range(1,n+1):
  if visited[a]==0:
    visited[a]=1
    dfs(a,adjl,visited,dp)
print(max(dp))

Buggy python submission (verdict: Runtime Error):
def dfs(a,adjl,visited,dp):
  for i in adjl[a]:
    if visited[i]==0:
      visited[i]=1
      dfs(i,adjl,visited,dp)
 
    dp[a]=max(dp[a],1+dp[i])
n,m=map(int,input().split())
li=[]
for i in range(m):
  li.append([int(k) for k in input().split()])
adjl=[[] for j in range(n+1)]
for k in range(len(li)):
  adjl[li[0]].append(li[1])
visited=[0]*(n+1)
dp=[0]*(n+1)
for a in range(1,n+1):
  if visited[a]==0:
    visited[a]=1
    dfs(a,adjl,visited,dp)
print(max(dp))

  
  


Fixed submission:
import sys
sys.setrecursionlimit(10**9)
def dfs(a,adjl,visited,dp):
  for i in adjl[a]:
    if visited[i]==0:
      visited[i]=1
      dfs(i,adjl,visited,dp)
 
    dp[a]=max(dp[a],1+dp[i])
n,m=map(int,input().split())
li=[]
for i in range(m):
  li.append([int(k) for k in input().split()])
adjl=[[] for j in range(n+1)]
for k in range(len(li)):
  adjl[li[k][0]].append(li[k][1])
visited=[0]*(n+1)
dp=[0]*(n+1)
for a in range(1,n+1):
  if visited[a]==0:
    visited[a]=1
    dfs(a,adjl,visited,dp)
print(max(dp))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
li=[int(k) for k in input().split()]
dp=[False]*(n+1)
for i in range(1,k+1):
  for j in range(len(li)):
    if i-li[j]<0:
      dp[i]=True
    else:
      if dp[i-li[j]]==False:
        dp[i]=True
if dp[k]==True:
  print("First")
else:
  print("Second")
  
  


Fixed submission:
n,k=map(int,input().split())
li=[int(k) for k in input().split()]
dp=[False]*(k+1)
for i in range(1,k+1):
  for j in range(len(li)):
    if i-li[j]<0:
      continue
    if dp[i-li[j]]==False:
      dp[i]=True
      break
if dp[k]==True:
  print("First")
else:
  print("Second")

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
li=[int(k) for k in input().split()]
dp=[False]*(n+1)
for i in range(1,k+1):
  for j in range(len(li)):
    if i-li[j]<0:
      dp[i]=False
    else:
      if dp[i-li[j]]==False:
        dp[i]=True
if dp[k]==True:
  print("First")
else:
  print("Second")
  
  

Fixed submission:
n,k=map(int,input().split())
li=[int(k) for k in input().split()]
dp=[False]*(k+1)
for i in range(1,k+1):
  for j in range(len(li)):
    if i-li[j]<0:
      continue
    if dp[i-li[j]]==False:
      dp[i]=True
      break
if dp[k]==True:
  print("First")
else:
  print("Second")
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
li=[int(k) for k in input().split()]
tot=0
ans=0
def findans(tot,li,j,k):
    global ans
    if k-tot==0 :
        ans+=1
    
        return 1
    if k<0:
        return 0
    if j==len(li):
        return 0    
    for i in range(li[j]+1):
        
        x=findans(tot+i,li,j+1,k)
    
    
findans(0,li,0,k)
mod=10**9+7
print(ans%mod)

    

Fixed submission:
n,k=map(int,input().split())
li=[int(K) for K in input().split()]
dp=[[0 for j in range(k+1)] for i in range(n+1)]
dp[0][0]=1
for b in range(1,n+1):
  dp[b][0]=1
mod=10**9+7  
for i in range(1,n+1):
  sums=[0]*(k+1)
  sums[0]=1
  for j in range(1,k+1):
    sums[j]=(sums[j-1]+dp[i-1][j])%mod
  for a in range(k+1):
    res=sums[a]
    if(a-li[i-1]-1)>=0:
      res=(res-sums[a-li[i-1]-1]+mod)%mod
    dp[i][a]=res
print(dp[n][k])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")

def findsum(li):

    for i in range(1,len(li)+1):
        tot[i]=tot[i-1]+li[i-1]
    #print(tot)

def findans(start,end,li):
  global tot
  #print("HI")
  if(start>=end):
    return 0
  if(dp[start][end]!=-1):
    return dp[start][end]
  ans = INF
  for k in range(start,end+1):


      ans=min(findans(start,k,li)+findans(k+1,end,li),ans)
  dp[start][end]=ans+(tot[end+1]-tot[start])
  return dp[start][end]
n=int(input())
li=[int(k) for k in input().split()]
tot=[0]*(len(li)+1)
findsum(li)
dp=[[-1 for i in range(n)]for k in range(n)]
print(findans(0,n-1,li))


Fixed submission:
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")

def findsum(li):

    for i in range(1,len(li)+1):
        tot[i]=tot[i-1]+li[i-1]
    #print(tot)

def findans(start,end,li):
  global tot
  #print("HI")
  if(start>=end):
    return 0
  if(dp[start][end]!=-1):
    return dp[start][end]
  ans = INF
  for k in range(start,end):


      ans=min(findans(start,k,li)+findans(k+1,end,li),ans)
  dp[start][end]=ans+(tot[end+1]-tot[start])
  return dp[start][end]
n=int(input())
li=[int(k) for k in input().split()]
tot=[0]*(len(li)+1)
findsum(li)
dp=[[-1 for i in range(n)]for k in range(n)]
print(findans(0,n-1,li))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")
def findans(start,end,li):
  #print("HI")
  if(start>=end):
    return 0
  if(dp[start][end]!=-1):
    return dp[start][end]
  ans = INF
  for k in range(start,end+1):

      ans=min(findans(start,k,li)+findans(k+1,end,li),ans)
      dp[start][end]=ans+sum(li[start:end+1])
  return dp[start][end]
n=int(input())
li=[int(k) for k in input().split()]
dp=[[-1 for i in range(n)]for k in range(n)]
print(findans(0,n-1,li))


Fixed submission:
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")

def findsum(li):

    for i in range(1,len(li)+1):
        tot[i]=tot[i-1]+li[i-1]
    #print(tot)

def findans(start,end,li):
  global tot
  #print("HI")
  if(start>=end):
    return 0
  if(dp[start][end]!=-1):
    return dp[start][end]
  ans = INF
  for k in range(start,end):


      ans=min(findans(start,k,li)+findans(k+1,end,li),ans)
  dp[start][end]=ans+(tot[end+1]-tot[start])
  return dp[start][end]
n=int(input())
li=[int(k) for k in input().split()]
tot=[0]*(len(li)+1)
findsum(li)
dp=[[-1 for i in range(n)]for k in range(n)]
print(findans(0,n-1,li))
Buggy python submission (verdict: Time Limit Exceeded):
def mincost(n, k, A):
    dp = [0] * n
    for i in range(1, n):
        dp[i] = float('inf')
        for j in range(i - 1, i - k - 1, -1):
            if j >= 0:
                dp[i] = min(dp[i], dp[j] + abs(A[j] - A[i]))
    return dp[n - 1]


if __name__ == '__main__':
    n, k = list(map(int, input().split()))
    A = list(map(int, input().split()))
    res = mincost(n, k, A)
    print(res)


Fixed submission:
def mincost(n, k, A):
    dp = [0] * n
    for i in range(1, n):
        dp[i] = float('inf')
        for j in range(i - 1, i - k - 1, -1):
            if j >= 0:
                dp[i] = min(dp[i], dp[j] + abs(A[j] - A[i]))
    return dp[n - 1]
 
 
if __name__ == '__main__':
    n, k = list(map(int, input().split()))
    A = list(map(int, input().split()))
    res = mincost(n, k, A)
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
def knapsack(N, C, weights, values):
    dp = [[0 for _ in range(N + 1)] for _ in range(C + 1)]
    for i in range(1, C + 1):
        for j in range(1, N + 1):
            if weights[j - 1] <= i:
                dp[i][j] = max(dp[i][j - 1], values[j - 1] + dp[i - weights[j - 1]][j - 1])
            else:
                dp[i][j] = dp[i][j - 1]
    return dp[C][N]


if __name__ == '__main__':
    n, c = list(map(int, input().split()))
    weights = [0] * n
    values = [0] * n
    for i in range(n):
        weights[i], values[i] = map(int, input().split())
    print(knapsack(n, c, weights, values))


Fixed submission:
def knapsack(N, C, weights, values):
    dp = [[0 for _ in range(N + 1)] for _ in range(C + 1)]
    for i in range(1, C + 1):
        for j in range(1, N + 1):
            if weights[j - 1] <= i:
                dp[i][j] = max(dp[i][j - 1], values[j - 1] + dp[i - weights[j - 1]][j - 1])
            else:
                dp[i][j] = dp[i][j - 1]
    return dp[C][N]
 
 
if __name__ == '__main__':
    n, c = list(map(int, input().split()))
    weights = [0] * n
    values = [0] * n
    for i in range(n):
        weights[i], values[i] = map(int, input().split())
    print(knapsack(n, c, weights, values))
Buggy python submission (verdict: Time Limit Exceeded):
num = list(map(int, input().split()))
n, tw = num[0], num[1]

w = [0]
v = [0]

for i in range(n):
    vals = list(map(int, input().split()))
    w.append(vals[0])
    v.append(vals[1])

if sum(w) < tw:
    tw = sum(w)

dp = [[0 for i in range(tw+1)] for j in range(n+1)]

for i in range(1,n+1):
    for j in range(1,tw+1):
        if w[i] > j:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], v[i] + dp[i-1][j-w[i]])

print(dp[-1][-1])




Fixed submission:
num = list(map(int, input().split()))
n, tw = num[0], num[1]

w = [0]
v = [0]

for i in range(n):
    vals = list(map(int, input().split()))
    w.append(vals[0])
    v.append(vals[1])

if sum(w) < tw:
    tw = sum(w)

dp = [[0 for i in range(tw+1)] for j in range(n+1)]

for i in range(1,n+1):
    for j in range(1,tw+1):
        if w[i] > j:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], v[i] + dp[i-1][j-w[i]])

print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
num = list(map(int, input().split()))
n, tw = num[0], num[1]

w = [0]
v = [0]

for i in range(n):
    vals = list(map(int, input().split()))
    w.append(vals[0])
    v.append(vals[1])

dp = [[0 for i in range(tw+1)] for j in range(n+1)]

for i in range(1,n+1):
    for j in range(1,tw+1):
        if w[i] > j:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], v[i] + dp[i-1][j-w[i]])

print(dp[-1][-1])




Fixed submission:
num = list(map(int, input().split()))
n, tw = num[0], num[1]

w = [0]
v = [0]

for i in range(n):
    vals = list(map(int, input().split()))
    w.append(vals[0])
    v.append(vals[1])

if sum(w) < tw:
    tw = sum(w)

dp = [[0 for i in range(tw+1)] for j in range(n+1)]

for i in range(1,n+1):
    for j in range(1,tw+1):
        if w[i] > j:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], v[i] + dp[i-1][j-w[i]])

print(dp[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

dp = [[0 for i in range(len(s)+1)] for j in range(len(t)+1)]
s = "0"+s
t = "0"+t

q = []

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

i = len(t)-1
j = len(s)-1

while i != 0 and j != 0:
    if dp[i][j] != dp[i-1][j] and  dp[i][j] != dp[i][j-1]:
        q.append(t[i])
        i -= 1
        j -= 1
    elif dp[i][j] != dp[i-1][j] and  dp[i][j] == dp[i][j-1]:
        j -= 1
    elif dp[i][j] == dp[i-1][j] and  dp[i][j] != dp[i][j-1]:
        i -= 1
    else:
        i -= 1

print(''.join(q[::-1]))




Fixed submission:
### The code is worked in dp, with a 2D matrix technique.

s = input()
t = input()

dp = [[0 for i in range(len(s)+1)] for j in range(len(t)+1)]
s = "0"+s
t = "0"+t

q = []

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

i = len(t)-1
j = len(s)-1

while i != 0 and j != 0:
    if dp[i][j] != dp[i-1][j] and  dp[i][j] != dp[i][j-1]:
        q.append(t[i])
        i -= 1
        j -= 1
    elif dp[i][j] != dp[i-1][j] and  dp[i][j] == dp[i][j-1]:
        j -= 1
    elif dp[i][j] == dp[i-1][j] and  dp[i][j] != dp[i][j-1]:
        i -= 1
    else:
        i -= 1

print(''.join(q[::-1]))
Buggy python submission (verdict: Runtime Error):
import numpy as np
def knapsack(w,val,W,n,t):
    for i in range(1,n+1):
        for j in range(1,W+1):
            if w[i-1]<=j:
                t[i][j]=max(val[i-1]+t[i-1][j-w[i-1]],t[i-1][j])
            else:
                t[i][j]=t[i-1][j]
    return t[n][W]            
n,W=map(int,input().split())                
w=[]
val=[]
t=np.zeros([n+1,W+1],dtype=int)
for i in range(0,n):
    a,b=map(int,input().split())
    w.append(a)
    val.append(b)
ans=knapsack(w,val,W,n,t)
print(ans)
    

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

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



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

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



Fixed submission:
n=int(input())
h=list(map(int,input().split()))
dp=[0]*(n+1)
h.insert(0,0)
dp[2]=abs(h[2]-h[1])
for i in range(3,n+1):
    dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2])
print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[2147483647]*(n+1)
h.insert(0,0)
dp[0]=0
dp[1]=0
dp[2]=abs(h[2]-h[1])
for i in range(3,n+1):
    for j in range(i-1,max((i-k-1),0),-1):
        dp[i]=min(dp[i],abs(h[i]-h[j])+dp[j])
print(dp[n])



Fixed submission:
import sys
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[2147483647]*(n+1)
h.insert(0,0)
dp[0]=0
dp[1]=0
dp[2]=abs(h[2]-h[1])
for i in range(3,n+1):
    for j in range(i-1,max((i-k-1),0),-1):
        dp[i]=min(dp[i],abs(h[i]-h[j])+dp[j])
print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def solve():
    N, K = map(int, input().split(" "))
    heights = [int(c) for c in input().split(" ")]
    dp = [sys.maxsize] * N
    dp[0] = 0
    for i in range(1, N):
        for j in range(1, K+1):
            if i - j >= 0:
                dp[i] = min(dp[i], dp[i-j] + abs(heights[i] - heights[i-j]))
            else:
                break
    print(dp[N-1])
solve() 

Fixed submission:
import sys
def solve():
    N, K = map(int, input().split(" "))
    heights = [int(c) for c in input().split(" ")]
    dp = [sys.maxsize] * N
    dp[0] = 0
    for i in range(1, N):
        for j in range(1, K+1):
            if i - j >= 0:
                dp[i] = min(dp[i], dp[i-j] + abs(heights[i] - heights[i-j]))
            else:
                break
    print(dp[N-1])
solve()
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf")]*n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(abs(h[i-j] - h[i]) + dp[i-j], dp[i])
print(dp[-1])

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
dp = [0]
dp.append(abs(h[1]-h[0]))
if n > 2:
    for i in range(2,n):
        dp.append(min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf")]*n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(abs(h[i-j] - h[i]) + dp[i-j], dp[i])
print(dp[-1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf")]*n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(abs(h[i-j] - h[i]) + dp[i-j], dp[i])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
h = [0] + h
dp = [float("inf")]*(n+1)
dp[1] = 0
for i in range(1,n+1):
    for j in range(i+1,min(i+k+1,n+1)):
        dp[j] = min(abs(h[i] - h[j]) + dp[i], dp[j])
print(dp[-1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf")]*n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(abs(h[i-j] - h[i]) + dp[i-j], dp[i])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
h = [0] + h
dp = [float("inf")]*(n+1)
dp[0] = 0
dp[1] = 0
for i in range(1,n+1):
    for j in range(i+1,min(i+k+1,n+1)):
        dp[j] = min(abs(h[i] - h[j]) + dp[i], dp[j])
print(dp[-1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf")]*n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(abs(h[i-j] - h[i]) + dp[i-j], dp[i])
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
def minfunc(i,s,cost,p):
  iter=0
  k=i-1
  mini=abs(s[i]-s[i-1])+cost[i-1]
  while(k>=0 and iter<p):
    if abs(s[i]-s[k])+cost[k]<mini:
      mini=abs(s[i]-s[k])+cost[k]
    k=k-1
    iter=iter+1
  return mini
    
    


l=list(map(int,input().split()))
n=l[0]
p=l[1]
s=list(map(int,input().split()))
cost=[0]*n
cost[1]=abs(s[1]-s[0])
if n==2:
  
  print(abs(s[1]-s[0]))
  
else:
  for i in range(2,len(s)):
  	cost[i]=minfunc(i,s,cost,p)
  print(cost[n-1])


Fixed submission:
def minfunc(i,s,cost,p):
  iter=0
  k=i-1
  mini=abs(s[i]-s[i-1])+cost[i-1]
  while(k>=0 and iter<p):
    if abs(s[i]-s[k])+cost[k]<mini:
      mini=abs(s[i]-s[k])+cost[k]
    k=k-1
    iter=iter+1
  return mini
    
    


l=list(map(int,input().split()))
n=l[0]
p=l[1]
s=list(map(int,input().split()))
cost=[0]*n
cost[1]=abs(s[1]-s[0])
if n==2:
  
  print(abs(s[1]-s[0]))
  
else:
  for i in range(2,len(s)):
  	cost[i]=minfunc(i,s,cost,p)
  print(cost[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
def minfunc(i,s,cost,p):
  iter=0
  k=i-1
  mini=abs(s[i]-s[i-1])+cost[i-1]
  while(k>=0 and iter<p):
    if abs(s[i]-s[k])+cost[k]<mini:
      mini=abs(s[i]-s[k])+cost[k]
    k=k-1
    iter=iter+1
  return mini
    
    


l=list(map(int,input().split()))
n=l[0]
p=l[1]
s=list(map(int,input().split()))
cost=[0]*n
cost[1]=abs(s[1]-s[0])
if n==2:
  
  print(abs(s[1]-s[0]))
  
else:
  for i in range(2,len(s)):
  	cost[i]=minfunc(i,s,cost,p)
  print(cost[n-1])


Fixed submission:
def minfunc(i,s,cost,p):
  iter=0
  k=i-1
  mini=abs(s[i]-s[i-1])+cost[i-1]
  while(k>=0 and iter<p):
    if abs(s[i]-s[k])+cost[k]<mini:
      mini=abs(s[i]-s[k])+cost[k]
    k=k-1
    iter=iter+1
  return mini
    
    


l=list(map(int,input().split()))
n=l[0]
p=l[1]
s=list(map(int,input().split()))
cost=[0]*n
cost[1]=abs(s[1]-s[0])
if n==2:
  
  print(abs(s[1]-s[0]))
  
else:
  for i in range(2,len(s)):
  	cost[i]=minfunc(i,s,cost,p)
  print(cost[n-1])

Buggy python submission (verdict: Runtime Error):
def minfunc(i,s,cost):
  iter=0
  k=i-1
  mini=abs(s[i]-s[i-1])+cost[i-1]
  while(k>=0 and iter<100):
    if abs(s[i]-s[k])+cost[k]<mini:
      mini=abs(s[i]-s[k])+cost[k]
    k=k-1
    iter=iter+1
  return mini
    
    


n=int(input())
s=list(map(int,input().split()))
cost=[0]*n
cost[1]=abs(s[1]-s[0])
if n==2:
  
  print(abs(s[1]-s[0]))
  
else:
  for i in range(2,len(s)):
  	cost[i]=minfunc(i,s,cost)
  print(cost[n-1])

Fixed submission:
def minfunc(i,s,cost,p):
  iter=0
  k=i-1
  mini=abs(s[i]-s[i-1])+cost[i-1]
  while(k>=0 and iter<p):
    if abs(s[i]-s[k])+cost[k]<mini:
      mini=abs(s[i]-s[k])+cost[k]
    k=k-1
    iter=iter+1
  return mini
    
    


l=list(map(int,input().split()))
n=l[0]
p=l[1]
s=list(map(int,input().split()))
cost=[0]*n
cost[1]=abs(s[1]-s[0])
if n==2:
  
  print(abs(s[1]-s[0]))
  
else:
  for i in range(2,len(s)):
  	cost[i]=minfunc(i,s,cost,p)
  print(cost[n-1])