Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)

n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

def rec(i):
    if dp[i] != 0:
        return dp[i]
    res = 0
    if i == 1 or i == 2:
        res = abs(H[i]-H[0])
        dp[i] = res
        return res
    elif i == 0:
        return 0
    else:
        res = abs(H[i]-H[i-2])+rec(i-2)
        res = min(res,abs(H[i]-H[i-1])+rec(i-1))
        dp[i] = res
        return res

rec(n-1)

print(dp[n-1]) 

Fixed submission:
n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

for i in range(1,n):
    if i == 1 or i == 2:
        dp[i] = abs(H[i]-H[0])
    else:
        dp[i] = min(abs(H[i]-H[i-2])+dp[i-2],abs(H[i]-H[i-1])+dp[i-1])

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)

n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

def rec(i):
    if dp[i] != 0:
        return dp[i]
    res = 0
    if i == 1 or i == 2:
        res = abs(H[i]-H[0])
        dp[i] = res
        return res
    elif i == 0:
        return 0
    else:
        res = abs(H[i]-H[i-2])+rec(i-2)
        res = min(res,abs(H[i]-H[i-1])+rec(i-1))
        dp[i] = res
        return res

rec(n-1)

print(dp[n-1]) 

Fixed submission:
n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

for i in range(1,n):
    if i == 1 or i == 2:
        dp[i] = abs(H[i]-H[0])
    else:
        dp[i] = min(abs(H[i]-H[i-2])+dp[i-2],abs(H[i]-H[i-1])+dp[i-1])

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)

n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

def rec(i):
    if dp[i] != 0:
        return dp[i]
    res = 0
    if i == 1 or i == 2:
        res = abs(H[i]-H[0])
        dp[i] = res
        return res
    elif i == 0:
        return 0
    else:
        res = min(abs(H[i]-H[i-2])+rec(i-2),abs(H[i]-H[i-1])+rec(i-1))
        dp[i] = res
        return res

rec(n-1)

print(dp[n-1]) 

Fixed submission:
n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

for i in range(1,n):
    if i == 1 or i == 2:
        dp[i] = abs(H[i]-H[0])
    else:
        dp[i] = min(abs(H[i]-H[i-2])+dp[i-2],abs(H[i]-H[i-1])+dp[i-1])

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)

n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

def rec(i):
    if dp[i] != 0:
        return dp[i]
    res = 0
    if i == 1 or i == 2:
        res = abs(H[i]-H[0])
        dp[i] = res
        return res
    elif i == 0:
        return 0
    else:
        res = min(abs(H[i]-H[i-2])+rec(i-2),abs(H[i]-H[i-1])+rec(i-1))
        dp[i] = res
    return res

rec(n-1)

print(dp[n-1]) 

Fixed submission:
n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

for i in range(1,n):
    if i == 1 or i == 2:
        dp[i] = abs(H[i]-H[0])
    else:
        dp[i] = min(abs(H[i]-H[i-2])+dp[i-2],abs(H[i]-H[i-1])+dp[i-1])

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)

n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

def rec(i):
    res = 0
    if i == 1 or i == 2:
        res = abs(H[i]-H[0])
        dp[i] = res
        return res
    elif i == 0:
        return 0
    if dp[i] != 0:
        return dp[i]
    else:
        res = min(abs(H[i]-H[i-2])+rec(i-2),abs(H[i]-H[i-1])+rec(i-1))
        dp[i] = res
    return res

rec(n-1)

print(dp[n-1]) 

Fixed submission:
n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

for i in range(1,n):
    if i == 1 or i == 2:
        dp[i] = abs(H[i]-H[0])
    else:
        dp[i] = min(abs(H[i]-H[i-2])+dp[i-2],abs(H[i]-H[i-1])+dp[i-1])

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

def rec(i):
    res = 0
    if i == 1 or i == 2:
        res = abs(H[i]-H[0])
        dp[i] = res
        return res
    elif i == 0:
        return 0
    if dp[i] != 0:
        return dp[i]
    else:
        res = min(abs(H[i]-H[i-2])+rec(i-2),abs(H[i]-H[i-1])+rec(i-1))
        dp[i] = res
    return res

rec(n-1)

print(dp[n-1]) 

Fixed submission:
n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

for i in range(1,n):
    if i == 1 or i == 2:
        dp[i] = abs(H[i]-H[0])
    else:
        dp[i] = min(abs(H[i]-H[i-2])+dp[i-2],abs(H[i]-H[i-1])+dp[i-1])

print(dp[n-1])