Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
arr = list(map(int,input().split()))


def min_cost(arr):
    dp = [math.inf for _ in range(len(arr))]
    dp[0] = 0
    for i in range(len(arr)+1):
        for j in range(i+1,i+3):
            if   j < len(arr):
                dp[j] =  min(dp[j],dp[i] + abs(arr[i]-arr[j]))
        
    return dp[len(arr)-1]
 
print(min_cost(arr))

Fixed submission:
import math
def min_cost(arr):
    n = len(arr)
    dp = [0 for _ in range(n)]
    dp[1] = abs(arr[1]- arr[0])
    for i in range(2,n):
        dp[i] =  min(dp[i-1] + abs(arr[i] - arr[i-1]),dp[i -2 ] + abs(arr[i]-arr[i-2]))
        
    return dp[n-1]

n = input()
arr = list(map(int,input().split()))
print(min_cost(arr))

Buggy python submission (verdict: Runtime Error):
import math
def min_cost(arr):
    dp = [math.inf for _ in range(len(arr))]
    dp[0] = 0
    for i in range(len(arr)+1):
        for j in range(i+1,i+3):
            if   j < len(arr):
                dp[j] =  min(dp[j],dp[i] + abs(arr[i]-arr[j]))
        
    return dp[len(arr)-1]
 
n = input()
arr = list(map(int,input().split()))
print(min_cost(arr))

Fixed submission:
import math
def min_cost(arr):
    n = len(arr)
    dp = [0 for _ in range(n)]
    dp[1] = abs(arr[1]- arr[0])
    for i in range(2,n):
        dp[i] =  min(dp[i-1] + abs(arr[i] - arr[i-1]),dp[i -2 ] + abs(arr[i]-arr[i-2]))
        
    return dp[n-1]

n = input()
arr = list(map(int,input().split()))
print(min_cost(arr))

Buggy python submission (verdict: Runtime Error):
import math
def min_cost(arr):
    dp = [math.inf for _ in range(len(arr))]
    dp[0] = 0
    for i in range(len(arr)+1):
        for j in range(i+1,i+3):
            if   j < len(arr):
                dp[j] =  min(dp[j],dp[i] + abs(arr[i]-arr[j]))
        
    return dp[len(arr)-1]

n = input()
arr = list(map(int,input().split()))
print(min_cost(arr))

Fixed submission:
import math
def min_cost(arr):
    n = len(arr)
    dp = [0 for _ in range(n)]
    dp[1] = abs(arr[1]- arr[0])
    for i in range(2,n):
        dp[i] =  min(dp[i-1] + abs(arr[i] - arr[i-1]),dp[i -2 ] + abs(arr[i]-arr[i-2]))
        
    return dp[n-1]

n = input()
arr = list(map(int,input().split()))
print(min_cost(arr))

Buggy python submission (verdict: Runtime Error):
l=list(map(int,input().split()))
n=l[0]
w=l[1]
va=[0]*n
wa=[0]*n
for i in range(n):
        
    x=list(map(int,input().split()))
    wa[i]=x[0]
    va[i]=x[1]
dp=[[0 for i in range(w+1)] for j 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])


Fixed submission:
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]=min(abs(s[i]-s[i-1])+cost[i-1],abs(s[i]-s[i-2])+cost[i-2])
  print(cost[n-1])

Buggy python submission (verdict: Runtime Error):
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:
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]=min(abs(s[i]-s[i-1])+cost[i-1],abs(s[i]-s[i-2])+cost[i-2])
  print(cost[n-1])