Buggy python submission (verdict: Runtime Error):
N = int(input())
h = list(map(int , input().split()))
dp = [-1]*N
import sys
sys.setrecursionlimit(100000)
def dfs(i,c):
    if i == N:
        return 10000
    if dp[i] != -1:
        return dp[i]
    else:
        if i == N-1:
            return abs(h[i] - c)
        dp[i] = min(dfs(i+1, h[i])+abs(h[i]-c),dfs(i+2, h[i])+abs(h[i]-c))
        return dp[i]
print(dfs(0,h[0]))


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

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
h = list(map(int , input().split()))
dp = [[-1]*10000 for i in range(N)]
import sys
sys.setrecursionlimit(10000000)
def dfs(i,c):
    if i == N:
        return 10000
    if dp[i][c] != -1:
        return dp[i][c]
    else:
        if i == N-1:
            return abs(h[i] - c)
        dp[i][c] = min(dfs(i+1, h[i])+abs(h[i]-c),dfs(i+2, h[i])+abs(h[i]-c))
        return dp[i][c]
print(dfs(0,h[0]))

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

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
h = list(map(int , input().split()))
dp = [[-1]*10000 for i in range(N)]
import sys
sys.setrecursionlimit(100000)
def dfs(i,c):
    if i == N:
        return 10000
    if dp[i][c] != -1:
        return dp[i][c]
    else:
        if i == N-1:
            return abs(h[i] - c)
        dp[i][c] = min(dfs(i+1, h[i])+abs(h[i]-c),dfs(i+2, h[i])+abs(h[i]-c))
        return dp[i][c]
print(dfs(0,h[0]))

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

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
h = list(map(int , input().split()))
dp = [[0]*10000 for i in range(N)]
import sys
sys.setrecursionlimit(100000)
def dfs(i,c):
    if i == N:
        return 10000
    if dp[i][c] >0:
        return dp[i][c]
    else:
        if i == N-1:
            return abs(h[i] - c)
        dp[i][c] = min(dfs(i+1, h[i])+abs(h[i]-c),dfs(i+2, h[i])+abs(h[i]-c))
        return dp[i][c]
print(dfs(0,h[0]))


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

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
h = list(map(int , input().split()))
dp = [[0]*10000 for i in range(N)]
def dfs(i,c):
    if i == N:
        return 10000
    if dp[i][c] >0:
        return dp[i][c]
    else:
        if i == N-1:
            return abs(h[i] - c)
        dp[i][c] = min(dfs(i+1, h[i])+abs(h[i]-c),dfs(i+2, h[i])+abs(h[i]-c))
        return dp[i][c]
print(dfs(0,h[0]))


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

Buggy python submission (verdict: Runtime Error):
N = int(input())
h = list(map(int , input().split()))

def dfs(i,c):
    if i == N:
        return 10000
    if i == N-1:
        return abs(h[i] - c)
    return min(dfs(i+1, h[i])+abs(h[i]-c),dfs(i+2, h[i])+abs(h[i]-c))

print(dfs(0,h[0]))


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