Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def knapsackBottomUp(wt,price,c,n,m):
    dp=[[float('inf') for x in range(m+1)] for y in range(n+1)]
    for l in range(n+1):
        dp[l][0]=0


    for i in range(1,n+1):
        wi=wt[i];vi=price[i]
        for V in range(1,m+1):
            if vi <= V:
                dp[i][V]=min(wi+dp[i-1][V-vi],dp[i-1][V])
            else:
                dp[i][V]=dp[i-1][V]

    res=0
    for i in range(m+1):
        if dp[n][i]<=c:
            res=i
    return res 
n,c=map(int,input().split())
wt=[]
price=[]
wt.append(0)
price.append(0)
for _ in range(n):
    w,v=map(int,input().split())
    wt.append(w)
    price.append(v)
max_val=sum(price)

print(knapsackBottomUp(wt,price,c,n,max_val))

Fixed submission:
inf=10**10
def knapsackBottomUp(wt,price,c,n,m):
    dp=[[inf for x in range(m+1)] for y in range(n+1)]
    for l in range(n+1):
        dp[l][0]=0


    for i in range(1,n+1):
        wi=wt[i];vi=price[i]
        for V in range(1,m+1):
            if vi <= V:
                dp[i][V]=min(wi+dp[i-1][V-vi],dp[i-1][V])
            else:
                dp[i][V]=dp[i-1][V]

    res=0
    for i in range(m+1):
        if dp[n][i]<=c:
            res=i
    print(res)
n,c=map(int,input().split())
wt=[]
price=[]
wt.append(0)
price.append(0)
for _ in range(n):
    w,v=map(int,input().split())
    wt.append(w)
    price.append(v)
max_val=sum(price)
knapsackBottomUp(wt,price,c,n,max_val)

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

Fixed submission:
inf=10**10
def knapsackBottomUp(wt,price,c,n,m):
    dp=[[inf for x in range(m+1)] for y in range(n+1)]
    for l in range(n+1):
        dp[l][0]=0


    for i in range(1,n+1):
        wi=wt[i];vi=price[i]
        for V in range(1,m+1):
            if vi <= V:
                dp[i][V]=min(wi+dp[i-1][V-vi],dp[i-1][V])
            else:
                dp[i][V]=dp[i-1][V]

    res=0
    for i in range(m+1):
        if dp[n][i]<=c:
            res=i
    print(res)
n,c=map(int,input().split())
wt=[]
price=[]
wt.append(0)
price.append(0)
for _ in range(n):
    w,v=map(int,input().split())
    wt.append(w)
    price.append(v)
max_val=sum(price)
knapsackBottomUp(wt,price,c,n,max_val)
Buggy python 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)

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

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 python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
arr = list(map(int, input().split()))

MAX = 10**9

dp = [MAX for i in range(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(arr[j] - arr[i]))

print(dp[-1])


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

MAX = 10**9

dp = [MAX for i in range(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(arr[j] - arr[i]))

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

import sys
sys.setrecursionlimit(10**9)

def dfs(i):
    if distance[i] != -1:
        return distance[i]
    ans = 0
    for node in graph[i]:
        ans = max(ans, dfs(node) + 1)
    return ans

n, m = map(int, input().split())

graph = [[] for i in range(n)]
distance = [-1 for i in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)

ans = 0
for i in range(n):
    ans = max(ans, dfs(i))

print(ans)

Fixed submission:

import sys
sys.setrecursionlimit(10**9)

def dfs(i):
    if distance[i] != -1:
        return distance[i]
    ans = 0
    for node in graph[i]:
        ans = max(ans, dfs(node) + 1)
    distance[i] = ans
    return ans

n, m = map(int, input().split())

graph = [[] for i in range(n)]
distance = [-1 for i in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)

ans = 0
for i in range(n):
    ans = max(ans, dfs(i))

print(ans)
Buggy python 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()

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

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

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

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


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

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

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

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 python submission (verdict: Time Limit Exceeded):
s,t=input(),input()
m,n=len(s),len(t)
l=[[0 for i in range(n+1)] for j in range(m+1)]
for i in range(1,m+1):
    for j in range(1,n+1):
        if s[i-1]==t[j-1]:
            l[i][j]=l[i-1][j-1]+1
        else:
            l[i][j]=max(l[i-1][j],l[i][j-1])
pos=l[m][n]
i,j,lcs=m,n,['']*(pos+1)
while i>0 and j>0:
    if s[i-1] == t[j-1]:
        lcs[pos-1]=s[i-1]
        i,j,pos=i-1,j-1,pos-1
    elif l[i-1][j]>l[i][j-1]:
        i-=1
    else:
        j-=1
print(''.join(lcs))


Fixed submission:
s,t=input(),input()
m,n=len(s),len(t)
l=[[0 for i in range(n+1)] for j in range(m+1)]
for i in range(1,m+1):
    for j in range(1,n+1):
        if s[i-1]==t[j-1]:
            l[i][j]=l[i-1][j-1]+1
        else:
            l[i][j]=max(l[i-1][j],l[i][j-1])
pos=l[m][n]
i,j,lcs=m,n,['']*(pos+1)
while i>0 and j>0:
    if s[i-1] == t[j-1]:
        lcs[pos-1]=s[i-1]
        i,j,pos=i-1,j-1,pos-1
    elif l[i-1][j]>l[i][j-1]:
        i-=1
    else:
        j-=1
print(''.join(lcs))
Buggy python submission (verdict: Runtime Error):
def dfs(node,paths,dp,vis):
    vis[node]=True
    for i in range(0, len(paths[node])):
        if not vis[paths[node][i]]:
            dfs(paths[node][i],paths,dp,vis)
        dp[node]=max(dp[node],1+dp[paths[node][i]])
n,m=map(int,input().split())
paths=[[] for _ in range(n+1)]
for _ in range(m):
    a,b=map(int,input().split())
    paths[a].append(b)
dp,vis=[0]*(n+1),[False]*(n+1)
for i in range(1,n+1):
    if not vis[i]:
        dfs(i,paths,dp,vis)
print(max(dp))

Fixed submission:
import sys
sys.setrecursionlimit(10000000)
def dfs(node,paths,dp,vis):
    vis[node]=True
    for i in range(0, len(paths[node])):
        if not vis[paths[node][i]]:
            dfs(paths[node][i],paths,dp,vis)
        dp[node]=max(dp[node],1+dp[paths[node][i]])
n,m=map(int,input().split())
paths=[[] for _ in range(n+1)]
for _ in range(m):
    a,b=map(int,input().split())
    paths[a].append(b)
dp,vis=[0]*(n+1),[False]*(n+1)
for i in range(1,n+1):
    if not vis[i]:
        dfs(i,paths,dp,vis)
print(max(dp))

Buggy python submission (verdict: Runtime Error):
def dfs(node,paths,dp,vis):
    vis[node]=True
    for i in range(0, len(paths[node])):
        if not vis[paths[node][i]]:
            dfs(paths[node][i],paths,dp,vis)
        dp[node]=max(dp[node],1+dp[paths[node][i]])
n,m=map(int,input().split())
paths=[[] for _ in range(n+1)]
for _ in range(m):
    a,b=map(int,input().split())
    paths[a].append(b)
dp,vis=[0]*(n+1),[False]*(n+1)
for i in range(1,n+1):
    if not vis[i]:
        dfs(i,paths,dp,vis)
print(max(dp))


Fixed submission:
import sys
sys.setrecursionlimit(10000000)
def dfs(node,paths,dp,vis):
    vis[node]=True
    for i in range(0, len(paths[node])):
        if not vis[paths[node][i]]:
            dfs(paths[node][i],paths,dp,vis)
        dp[node]=max(dp[node],1+dp[paths[node][i]])
n,m=map(int,input().split())
paths=[[] for _ in range(n+1)]
for _ in range(m):
    a,b=map(int,input().split())
    paths[a].append(b)
dp,vis=[0]*(n+1),[False]*(n+1)
for i in range(1,n+1):
    if not vis[i]:
        dfs(i,paths,dp,vis)
print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**8)
def nop(h,w):
    if l[h-1][w-1]=='#':
        return 0
    if h==1:
        return left(w)
    elif w==1:
        return up(h)
    return nop(h-1,w)+nop(h,w-1)
def up(h):
    if l[h-1][0]=='#':
        return 0
    if h==1:
        return 1
    return up(h-1)
def left(w):
    if l[0][w-1]=='#':
        return 0
    if w==1:
        return 1
    return left(w-1)
h,w=map(int,input().split())
l=[list(input()) for _ in range(h)]
print(nop(h,w)%(10**9+7))


Fixed submission:
h,w=map(int,input().split())
l=[[1 if i=='.' else 0 for i in input()] for _ in range(h)]
for i in range(w):
    if l[0][i]==0:
        for j in range(i+1,w):
            l[0][j]=0
        break
for i in range(h):
    if l[i][0]==0:
        for j in range(i+1,h):
            l[j][0]=0
        break
for i in range(1,h):
    for j in range(1,w):
        if l[i][j]!=0:
            l[i][j]=l[i-1][j]+l[i][j-1]
print(l[h-1][w-1]%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**8)
def nop(h,w):
    if l[h-1][w-1]=='#':
        return 0
    if h==1:
        return left(w)
    elif w==1:
        return up(h)
    return nop(h-1,w)+nop(h,w-1)
def up(h):
    if l[h-1][0]=='#':
        return 0
    if h==1:
        return 1
    return up(h-1)
def left(w):
    if l[0][w-1]=='#':
        return 0
    if w==1:
        return 1
    return left(w-1)
h,w=map(int,input().split())
l=[list(input()) for _ in range(h)]
print(nop(h,w)%(10**9+7))


Fixed submission:
h,w=map(int,input().split())
l=[[1 if i=='.' else 0 for i in input()] for _ in range(h)]
for i in range(w):
    if l[0][i]==0:
        for j in range(i+1,w):
            l[0][j]=0
        break
for i in range(h):
    if l[i][0]==0:
        for j in range(i+1,h):
            l[j][0]=0
        break
for i in range(1,h):
    for j in range(1,w):
        if l[i][j]!=0:
            l[i][j]=l[i-1][j]+l[i][j-1]
print(l[h-1][w-1]%(10**9+7))
Buggy python submission (verdict: Runtime Error):
n,m=input().split()
n=int(n)
m=int(m)
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=li[1]-li[0]
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    if i-j<0:
      break
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans
print(dp[n-1])  


Fixed submission:
n=int(input())
li=[int(k) for k in input().split()]
dp=[0]*(n)
dp[0]=0
dp[1]=abs(li[1]-li[0])

for i in range(2,n):
  dp[i]=min(abs(li[i]-li[i-1])+dp[i-1],abs(li[i]-li[i-2])+dp[i-2])
#print(dp)
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n,m=input().split()
n=int(n)
m=int(m)
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=li[1]-li[0]
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans
print(dp[n-1])  


Fixed submission:
n=int(input())
li=[int(k) for k in input().split()]
dp=[0]*(n)
dp[0]=0
dp[1]=abs(li[1]-li[0])

for i in range(2,n):
  dp[i]=min(abs(li[i]-li[i-1])+dp[i-1],abs(li[i]-li[i-2])+dp[i-2])
#print(dp)
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
li=[int(k) for k in input().split()]
dp=[0]*(n)
dp[0]=li[0]
dp[1]=abs(li[1]-li[0])
for i in range(2,n):
  dp[i]=min(abs(li[i]-dp[i-1]),abs(li[i]-dp[i-2]))
return dp[n-1] 

Fixed submission:
n=int(input())
li=[int(k) for k in input().split()]
dp=[0]*(n)
dp[0]=0
dp[1]=abs(li[1]-li[0])

for i in range(2,n):
  dp[i]=min(abs(li[i]-li[i-1])+dp[i-1],abs(li[i]-li[i-2])+dp[i-2])
#print(dp)
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,m=input().split()
n=int(n)
m=int(m)
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=abs(li[1]-li[0])
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    if i-j<0:
      break
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans
#print(dp)  
print(dp[n-1])  


Fixed submission:
n,m=input().split()
n=int(n)
m=int(m)
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=abs(li[1]-li[0])
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    if i-j<0:
      break
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans
#print(dp)  
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n,m=int(input().split())
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=li[1]-li[0]
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans
print(dp[n-1])  


Fixed submission:
n,m=input().split()
n=int(n)
m=int(m)
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=abs(li[1]-li[0])
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    if i-j<0:
      break
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans
#print(dp)  
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n,m=int(input())
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=li[1]-li[0]
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans
print(dp[n-1])  


Fixed submission:
n,m=input().split()
n=int(n)
m=int(m)
li=[int(k) for k in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=abs(li[1]-li[0])
for i in range(2,n):
  ans=10**9
  for j in range(1,m+1):
    if i-j<0:
      break
    ans=min(ans,abs(li[i]-li[i-j])+dp[i-j])
  dp[i]=ans
#print(dp)  
print(dp[n-1])
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=int(input())
li=[]
for i in range(n):
  li.append([int(k) for k in input().split()])
dp=[[0 for i in range(3)] for j in range(n)]
dp[0]=li[0]

for j in range(1,n):
    for i in range(3):
        if(i==0):
            dp[j][i]=li[j][i]+max(dp[j-1][i+1],dp[j-1][i+2])
        elif(i==1):
            dp[j][i]=li[j][i]+max(dp[j-1][i-1],dp[j-1][i+1])
        elif(i==2):
            dp[j][i]=li[j][i]+max(dp[j-1][i-1],dp[j-1][i-2])    
       
#print(dp)
print(max(dp[n-1]))