Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(input())
h = gil()

CM = 1e18
def rp(i, h, n, c, p):
    global CM
    if i >= n:
        ans =  c + abs(p - h[n-1])
        CM = min(ans, CM)
        return ans
    x = abs(p - h[i])
    if c+x >= CM:
        return 1e18
    return min(rp(i+1, h, n, c + x, h[i]),rp(i+2, h, n, c + x, h[i]))
    
ans = min(rp(1, h, len(h), 0, h[0]),rp(2, h, len(h), 0, h[0]))
print(ans)


Fixed submission:
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(input())
h = gil()
dp = [1e18]*(n+1)
dp[0] = 0
for i in range(n):
    for j in [i+1, i+2]:
        if j < n:
            dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]))
print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(input())
h = gil()


def rp(i, h, n, c, p):
    if i >= n:
        return c + abs(p - h[n-1])
    x = abs(p - h[i])
    return min(rp(i+1, h, n, c + x, h[i]),rp(i+2, h, n, c + x, h[i]))
    
ans = min(rp(1, h, len(h), 0, h[0]),rp(2, h, len(h), 0, h[0]))
print(ans)


Fixed submission:
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(input())
h = gil()
dp = [1e18]*(n+1)
dp[0] = 0
for i in range(n):
    for j in [i+1, i+2]:
        if j < n:
            dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]))
print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
from collections import defaultdict
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(input())
h = gil()

mem = [C() for _ in range(n+2)]
def rp(i, h, n, c, p):
    if c in mem[i]:
        return mem[i][c]
        
    if i >= n:
        ans = c + abs(p - h[n-1])
        mem[n][c] = ans
        return ans
        
    x = abs(p - h[i])
    ans = min(rp(i+1, h, n, c + x, h[i]),rp(i+2, h, n, c + x, h[i]))
    mem[i][c] = ans
    return mem[i][c]
    
ans = min(rp(1, h, len(h), 0, h[0]),rp(2, h, len(h), 0, h[0]))
print(ans)


Fixed submission:
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(input())
h = gil()
dp = [1e18]*(n+1)
dp[0] = 0
for i in range(n):
    for j in [i+1, i+2]:
        if j < n:
            dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]))
print(dp[n-1])