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

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

Fixed submission:



def findmin(arr,n):
  dp = [0]*n
  dp[1] = abs(arr[0]-arr[1])
  for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(arr[i-1]-arr[i]), dp[i-2]+abs(arr[i-2]-arr[i]))
  return dp[-1]

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

Buggy python submission (verdict: Runtime Error):
import math
import os
import random
import re
import sys
def dpkfindpath(a,k):
	dpath=[int(0) for _ in range(len(a))]
	for i in range(k):
		dpath[i]=abs(a[i]-a[0])
	
	for i in range(k,len(a)):
		li=[abs(a[i]-a[ik])+dpath[ik] for ik in range(i-1,i-k-1,-1) ]
		dpath[i]=min(li)
		
	return dpath[len(a)-1]
		
n,k=input().split()
n=int(n)
k=int(k)
a=input().split()
for i in range(n):
  a[i]=int(a[i])
if n>=k:
	print (dpkfindpath(a,k))


Fixed submission:
import math
import os
import random
import re
import sys
def dpfindpath(a):
	dpath=[int(0) for _ in range(len(a))]
	dpath[0]=0
	dpath[1]=abs(a[1]-a[0])
	for i in range(2,len(a)):
		dpath[i]=min(abs(a[i]-a[i-1])+dpath[i-1],abs(a[i]-a[i-2])+dpath[i-2])
	return dpath[len(a)-1]
n=int(input())
a=input().split()
for i in range(n):
  a[i]=int(a[i])
print (dpfindpath(a))

Buggy python submission (verdict: Runtime Error):
import math
import os
import random
import re
import sys
def dpkfindpath(a,k):
	dpath=[int(0) for _ in range(len(a))]
	for i in range(k):
		dpath[i]=abs(a[i]-a[0])
	
	for i in range(k,len(a)):
		m=abs(a[i]-a[i-1])+dpath[i-1]
		for j in range(1,k+1):
			if (abs(a[i]-a[i-j])+dpath[i-j])<m:
				m=abs(a[i]-a[i-j])+dpath[i-j]
		dpath[i]=m
	return dpath[len(a)-1]
		
n,k=input().split()
n=int(n)
k=int(k)
a=input().split()
for i in range(n):
  a[i]=int(a[i])
print (dpkfindpath(a,k))

Fixed submission:
import math
import os
import random
import re
import sys
def dpfindpath(a):
	dpath=[int(0) for _ in range(len(a))]
	dpath[0]=0
	dpath[1]=abs(a[1]-a[0])
	for i in range(2,len(a)):
		dpath[i]=min(abs(a[i]-a[i-1])+dpath[i-1],abs(a[i]-a[i-2])+dpath[i-2])
	return dpath[len(a)-1]
n=int(input())
a=input().split()
for i in range(n):
  a[i]=int(a[i])
print (dpfindpath(a))

Buggy python submission (verdict: Runtime Error):
import math
import os
import random
import re
import sys
def findpath(a):
  if len(a)==2:
     return abs(a[1]-a[0])    
  if len(a)==3:
    return min(abs(a[2]-a[1])+abs(a[1]-a[0]),abs(a[2]-a[0]))
  return min(abs(a[2]-a[0])+findpath(a[2::]),abs(a[1]-a[0])+findpath(a[1::]))
n=int(input())
a=input().split()
for i in range(n):
  a[i]=int(a[i])
print (findpath(a))

Fixed submission:
import math
import os
import random
import re
import sys
def dpfindpath(a):
	dpath=[int(0) for _ in range(len(a))]
	dpath[0]=0
	dpath[1]=abs(a[1]-a[0])
	for i in range(2,len(a)):
		dpath[i]=min(abs(a[i]-a[i-1])+dpath[i-1],abs(a[i]-a[i-2])+dpath[i-2])
	return dpath[len(a)-1]
n=int(input())
a=input().split()
for i in range(n):
  a[i]=int(a[i])
print (dpfindpath(a))

Buggy python submission (verdict: Runtime Error):
import math
import os
import random
import re
import sys
def findpath(a):
  if len(a)==3:
    return min(abs(a[2]-a[1])+abs(a[1]-a[0]),abs(a[2]-a[0]))
  return min(abs(a[2]-a[0])+findpath(a[2::]),abs(a[1]-a[0])+findpath(a[1::]))
n=int(input())
a=input().split()
for i in range(n):
  a[i]=int(a[i])
print findpath(a)

Fixed submission:
import math
import os
import random
import re
import sys
def dpfindpath(a):
	dpath=[int(0) for _ in range(len(a))]
	dpath[0]=0
	dpath[1]=abs(a[1]-a[0])
	for i in range(2,len(a)):
		dpath[i]=min(abs(a[i]-a[i-1])+dpath[i-1],abs(a[i]-a[i-2])+dpath[i-2])
	return dpath[len(a)-1]
n=int(input())
a=input().split()
for i in range(n):
  a[i]=int(a[i])
print (dpfindpath(a))

Buggy python submission (verdict: Runtime Error):
import math
import os
import random
import re
import sys
def findpath(a):
  if len(a)==3:
    return min(abs(a[2]-a[1])+abs(a[1]-a[0]),abs(a[2]-a[0]))
  return min(abs(a[2]-a[0])+findpath(a[2::]),abs(a[1]-a[0])+findpath(a[1::]))
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
print findpath(a)

Fixed submission:
import math
import os
import random
import re
import sys
def dpfindpath(a):
	dpath=[int(0) for _ in range(len(a))]
	dpath[0]=0
	dpath[1]=abs(a[1]-a[0])
	for i in range(2,len(a)):
		dpath[i]=min(abs(a[i]-a[i-1])+dpath[i-1],abs(a[i]-a[i-2])+dpath[i-2])
	return dpath[len(a)-1]
n=int(input())
a=input().split()
for i in range(n):
  a[i]=int(a[i])
print (dpfindpath(a))

Buggy python submission (verdict: Runtime Error):
x=int(input())
n=int(input())
arr=list(map(int,input().split()))
dp=[0]*len(arr)
dp[0]=0
dp[1]=abs(arr[1]-arr[0])
for i in range(2,len(arr)):
    dp[i]=min((dp[i-1]+abs(arr[i-1]-arr[i])),(dp[i-2]+abs(arr[i-2]-arr[i])))
print(dp[len(arr)-1])

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