Buggy python submission (verdict: Runtime Error):
def getMinCost(arr,i,n,cache):
    if i > n-2:
        return 0
    if cache[i] != float("inf"): return cache[i]
    op1 = abs(arr[i] - arr[i+1]) + getMinCost(arr,i+1,n,cache)
    op2 = abs(arr[i] - arr[i+2]) + getMinCost(arr,i+2,n,cache) if i != n-2 else float("inf")
    cache[i] = min(op1,op2)
    return cache[i]

n = int(input())
arr = [int(i) for i in input().split()]
cache = [float("inf") for i in range(n)]
print(getMinCost(arr,0,n,cache))


Fixed submission:
n = int(input())
arr = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
for i in range(1,n):
    op1 = abs(arr[i]-arr[i-1]) + dp[i-1]
    op2 = abs(arr[i]-arr[i-2]) + dp[i-2] if i != 1 else float("inf")
    dp[i] = min(op1,op2)
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
def getMinCost(arr,i,n,cache):
    if i >= n-1:
        return 0
    if cache[i] != 0: return cache[i]
    op1 = abs(arr[i] - arr[i+1]) + getMinCost(arr,i+1,n,cache)
    op2 = abs(arr[i] - arr[i+2]) + getMinCost(arr,i+2,n,cache) if i != n-2 else float("inf")
    cache[i] = min(op1,op2)
    return cache[i]

n = int(input())
arr = [int(i) for i in input().split()]
cache = [0 for i in range(n)]
print(getMinCost(arr,0,n,cache))


Fixed submission:
n = int(input())
arr = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
for i in range(1,n):
    op1 = abs(arr[i]-arr[i-1]) + dp[i-1]
    op2 = abs(arr[i]-arr[i-2]) + dp[i-2] if i != 1 else float("inf")
    dp[i] = min(op1,op2)
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
def getMinCost(arr,i,n,cache):
    if i >= n-1:
        return 0
    if cache[i] != -1: return cache[i]
    op1 = abs(arr[i] - arr[i+1]) + getMinCost(arr,i+1,n,cache)
    op2 = abs(arr[i] - arr[i+2]) + getMinCost(arr,i+2,n,cache) if i <= len(arr)-3 else float("inf")
    cache[i] = min(op1,op2)
    return cache[i]

n = int(input())
arr = [int(i) for i in input().split()]
cache = [-1 for i in range(n)]
print(getMinCost(arr,0,n,cache))

Fixed submission:
n = int(input())
arr = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
for i in range(1,n):
    op1 = abs(arr[i]-arr[i-1]) + dp[i-1]
    op2 = abs(arr[i]-arr[i-2]) + dp[i-2] if i != 1 else float("inf")
    dp[i] = min(op1,op2)
print(dp[n-1])

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

Fixed submission:
n = int(input())
arr = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
for i in range(1,n):
    op1 = abs(arr[i]-arr[i-1]) + dp[i-1]
    op2 = abs(arr[i]-arr[i-2]) + dp[i-2] if i != 1 else float("inf")
    dp[i] = min(op1,op2)
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n - int(input())
arr = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
for i in range(1,n):
    op1 = abs(arr[i]-arr[i-1]) + dp[i-1]
    op2 = abs(arr[i]-arr[i-2]) + dp[i-2]
    dp[i] = min(op1,op2)
dp[n-1]

Fixed submission:
n = int(input())
arr = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
for i in range(1,n):
    op1 = abs(arr[i]-arr[i-1]) + dp[i-1]
    op2 = abs(arr[i]-arr[i-2]) + dp[i-2] if i != 1 else float("inf")
    dp[i] = min(op1,op2)
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
def getMinCostJump(arr,i,n,cache):
    if i > n: return 0
    if i == n: return 0
    if cache[i] != 0:
        return cache[i]
    op1,op2 = 0,0
    if (i+1) < n:
        op1 += abs(arr[i] -arr[i+1]) + getMinCostJump(arr,i+1,n,cache)
    if (i+2) < n:
        op2 += abs(arr[i] -arr[i+2]) + getMinCostJump(arr,i+2,n,cache)
    cache[i] = min(op1,op2)
    return cache[i]
n = int(input())
arr = [int(i) for i in input().split()]
cache = [0 for i in range(n+1)]
print(getMinCostJump(arr,0,n,cache))  

Fixed submission:
n = int(input())
arr = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
for i in range(1,n):
    op1 = abs(arr[i]-arr[i-1]) + dp[i-1]
    op2 = abs(arr[i]-arr[i-2]) + dp[i-2] if i != 1 else float("inf")
    dp[i] = min(op1,op2)
print(dp[n-1])