Buggy python submission (verdict: Runtime Error):
import time
from memory_profiler import profile

N = int(input())
h = list(map(int, input().split()))

suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])
 
#@profile
def netMain():
    for e in range(2, N):
        suml[e] = min(
            abs(h[e]-h[e-1]) + suml[e-1],
            abs(h[e]-h[e-2]) + suml[e-2],
        )
 
netMain()
print(suml[N-1])


Fixed submission:
N = int(input())
h = list(map(int, input().split()))
 
suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])
 
for e in range(2, N):
    suml[e] = min(
        abs(h[e]-h[e-1]) + suml[e-1],
        abs(h[e]-h[e-2]) + suml[e-2],
    )
 
# print(suml)
print(suml[N-1])

Buggy python submission (verdict: Runtime Error):
import time
from memory_profiler import profile

N = int(input())
h = list(map(int, input().split()))

suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])
 
#@profile
def netMain():
    for e in range(2, N):
        suml[e] = min(
            abs(h[e]-h[e-1]) + suml[e-1],
            abs(h[e]-h[e-2]) + suml[e-2],
        )
 
netMain()
print(suml[N-1])


Fixed submission:
N = int(input())
h = list(map(int, input().split()))
 
suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])
 
for e in range(2, N):
    suml[e] = min(
        abs(h[e]-h[e-1]) + suml[e-1],
        abs(h[e]-h[e-2]) + suml[e-2],
    )
 
# print(suml)
print(suml[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
inputs = input().split(" ")
l = [int(s) for s in inputs]

def calc(rl, ns, skip):
    v = rl[len(rl)-1]
    # print(rl,v,ns)
    lrl = len(rl)
    
    if lrl == 1:
        return ns
    if lrl == 2:
        v1 = rl[len(rl)-2]
        return ns+abs(v-v1)
    if lrl == 3:
        v1 = rl[len(rl)-2]
        v2 = rl[len(rl)-3]
        ns1 = ns + abs(v-v2)
        ns2 = ns + abs(v-v1) + abs(v1-v2)
        return min(ns1,ns2)
    else:
        v1 = rl[len(rl)-2]
        v2 = rl[len(rl)-3]
        return min(calc(rl[:len(rl)-1],ns+abs(v-v1),True),calc(rl[:len(rl)-2],ns+abs(v-v2),False))

print(calc(l,0,False))

Fixed submission:
N = int(input())
h = list(map(int, input().split()))
 
suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])
 
for e in range(2, N):
    suml[e] = min(
        abs(h[e]-h[e-1]) + suml[e-1],
        abs(h[e]-h[e-2]) + suml[e-2],
    )
 
# print(suml)
print(suml[N-1])

Buggy python submission (verdict: Runtime Error):

n = int(input())
l = list(map(int, input().split()))

def calc(rl, ns):
    v = rl[len(rl)-1]
    # print(rl,v,ns)
    lrl = len(rl)
    
    if lrl == 1:
        return ns
    if lrl == 2:
        v1 = rl[len(rl)-2]
        return ns+abs(v-v1)
    if lrl == 3:
        v1 = rl[len(rl)-2]
        v2 = rl[len(rl)-3]
        ns1 = ns + abs(v-v2)
        ns2 = ns + abs(v-v1) + abs(v1-v2)
        return min(ns1,ns2)
    else:
        v1 = rl[len(rl)-2]
        v2 = rl[len(rl)-3]
        return min(calc(rl[:len(rl)-1],ns+abs(v-v1),True),calc(rl[:len(rl)-2],ns+abs(v-v2),False))

print(calc(l,0))

Fixed submission:
N = int(input())
h = list(map(int, input().split()))
 
suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])
 
for e in range(2, N):
    suml[e] = min(
        abs(h[e]-h[e-1]) + suml[e-1],
        abs(h[e]-h[e-2]) + suml[e-2],
    )
 
# print(suml)
print(suml[N-1])

Buggy python submission (verdict: Runtime Error):
import copy
n = int(input())
inputs = input().split(" ")
l = [int(s) for s in inputs]

def calc(rl, ns, skip):
    v = rl[len(rl)-1]
    # print(rl,v,ns)
    lrl = len(rl)
    
    if lrl == 1:
        return ns
    if lrl == 2:
        v1 = rl[len(rl)-2]
        return ns+abs(v-v1)
    if lrl == 3:
        v1 = rl[len(rl)-2]
        v2 = rl[len(rl)-3]
        ns1 = ns + abs(v-v2)
        ns2 = ns + abs(v-v1) + abs(v1-v2)
        return min(ns1,ns2)
    else:
        v1 = rl[len(rl)-2]
        v2 = rl[len(rl)-3]
        return min(calc(rl[:len(rl)-1],ns+abs(v-v1),True),calc(rl[:len(rl)-2],ns+abs(v-v2),False))

print(calc(l,0,False))


Fixed submission:
N = int(input())
h = list(map(int, input().split()))
 
suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])
 
for e in range(2, N):
    suml[e] = min(
        abs(h[e]-h[e-1]) + suml[e-1],
        abs(h[e]-h[e-2]) + suml[e-2],
    )
 
# print(suml)
print(suml[N-1])

Buggy python submission (verdict: Runtime Error):
import copy

n = int(input())
inputs = input().split(" ")
l = [int(s) for s in inputs]

def calc(rl, ns, skip):
    v = rl[len(rl)-1]
    # print(rl,v,ns)
    lrl = len(rl)
    
    if lrl == 0:
        return ns
    if lrl == 1:
        v1 = rl[len(rl)-2]
        return ns+abs(v-v1)
    if lrl == 2:
        v1 = rl[len(rl)-2]
        v2 = rl[len(rl)-3]
        ns1 = ns + abs(v-v2)
        ns2 = ns + abs(v-v1) + abs(v1-v2)
        return min(ns1,ns2)
    else:
        v1 = rl[len(rl)-2]
        v2 = rl[len(rl)-3]
        return min(calc(rl[:len(rl)-1],ns+abs(v-v1),True),calc(rl[:len(rl)-2],ns+abs(v-v2),False))

print(calc(l,0,False))


Fixed submission:
N = int(input())
h = list(map(int, input().split()))
 
suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])
 
for e in range(2, N):
    suml[e] = min(
        abs(h[e]-h[e-1]) + suml[e-1],
        abs(h[e]-h[e-2]) + suml[e-2],
    )
 
# print(suml)
print(suml[N-1])

Buggy python submission (verdict: Runtime Error):
import copy

n = int(input())
l = list(map(int, input().split()))
#n = int(input())
#inputs = input().split(" ")
#l = [int(s) for s in inputs]

def calc(rl, ns, skip):
    v = rl.pop(len(rl)-1)
    # print(rl,v,ns)
    lrl = len(rl)
    
    if lrl == 0:
        return ns
    if lrl == 1:
        v1 = rl[len(rl)-1]
        return ns+abs(v-v1)
    if lrl == 2:
        v1 = rl[len(rl)-1]
        v2 = rl[len(rl)-2]
        ns1 = ns + abs(v-v2)
        ns2 = ns + abs(v-v1) + abs(v1-v2)
        # print("lrl 2:",v1,v2,ns1,ns2,ns)
        return min(ns1,ns2)
    else:
        v1 = rl[len(rl)-1]
        c1 = -1
        if skip == False:
            crl = copy.copy(rl)
            c1 = calc(crl,ns+abs(v-v1),True)
        v2 = rl[len(rl)-2]
        rl.pop(len(rl)-1)
        c2 = calc(rl,ns+abs(v-v2),False)
        if (c1 == -1):
            return c2
        else:
            return min(c1,c2)

print(calc(l,0,False))


Fixed submission:
N = int(input())
h = list(map(int, input().split()))
 
suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])
 
for e in range(2, N):
    suml[e] = min(
        abs(h[e]-h[e-1]) + suml[e-1],
        abs(h[e]-h[e-2]) + suml[e-2],
    )
 
# print(suml)
print(suml[N-1])

Buggy python submission (verdict: Runtime Error):
import copy

n = int(input())
inputs = input().split(" ")
l = [int(s) for s in inputs]

def calc(rl, ns, skip):
    v = rl.pop(len(rl)-1)
    # print(rl,v,ns)
    lrl = len(rl)
    
    if lrl == 0:
        return ns
    if lrl == 1:
        v1 = rl[len(rl)-1]
        return ns+abs(v-v1)
    if lrl == 2:
        v1 = rl[len(rl)-1]
        v2 = rl[len(rl)-2]
        ns1 = ns + abs(v-v2)
        ns2 = ns + abs(v-v1) + abs(v1-v2)
        # print("lrl 2:",v1,v2,ns1,ns2,ns)
        return min(ns1,ns2)
    else:
        v1 = rl[len(rl)-1]
        c1 = -1
        if skip == False:
            crl = copy.copy(rl)
            c1 = calc(crl,ns+abs(v-v1),True)
        v2 = rl[len(rl)-2]
        rl.pop(len(rl)-1)
        c2 = calc(rl,ns+abs(v-v2),False)
        if (c1 == -1):
            return c2
        else:
            return min(c1,c2)

print(calc(l,0,False))


Fixed submission:
N = int(input())
h = list(map(int, input().split()))
 
suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])
 
for e in range(2, N):
    suml[e] = min(
        abs(h[e]-h[e-1]) + suml[e-1],
        abs(h[e]-h[e-2]) + suml[e-2],
    )
 
# print(suml)
print(suml[N-1])

Buggy python submission (verdict: Runtime Error):
import copy

n = int(input())
inputs = input().split(" ")
l = [int(s) for s in inputs]

def calc(rl, ns):
    v = rl.pop(len(rl)-1)
    # print(rl,v,ns)
    lrl = len(rl)
    
    if lrl == 0:
        return ns
    if lrl == 1:
        v1 = rl[len(rl)-1]
        return ns+abs(v-v1)
    if lrl == 2:
        v1 = rl[len(rl)-1]
        v2 = rl[len(rl)-2]
        ns1 = ns + abs(v-v2)
        ns2 = ns + abs(v-v1) + abs(v1-v2)
        # print("lrl 2:",v1,v2,ns1,ns2,ns)
        return min(ns1,ns2)
    else:
        v1 = rl[len(rl)-1]
        crl = copy.copy(rl)
        c1 = calc(crl,ns+abs(v-v1))
        v2 = rl[len(rl)-2]
        rl.pop(len(rl)-1)
        c2 = calc(rl,ns+abs(v-v2))
        return min(c1,c2)

print(calc(l,0))

Fixed submission:
N = int(input())
h = list(map(int, input().split()))
 
suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])
 
for e in range(2, N):
    suml[e] = min(
        abs(h[e]-h[e-1]) + suml[e-1],
        abs(h[e]-h[e-2]) + suml[e-2],
    )
 
# print(suml)
print(suml[N-1])

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))

d = [float("inf")] * n
d[0] = 0

for i in range(1, len(a)):
    s = max(i-k, 0)
    now=a[i] 
    d[i] = min(y + abs(now-x) for x, y in zip(a[s:i], d[s:i]))
print(d[-1])  

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

d = [0] * n
d[1] = abs(a[0]-a[1])

for i in range(2, len(a)):
    d[i] = min(d[i-1]+abs(a[i]-a[i-1]), d[i-2]+abs(a[i]-a[i-2]))
print(d[-1])

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))

d = [float("inf")] * n
d[0] = 0

for i in range(1, len(a)):
    s = max(i-k, 0)
    now = a[i]
    d[i] = min(y + abs(now-x) for x, y in zip(a[s:i], d[s:i]))
print(d[-1])  

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

d = [0] * n
d[1] = abs(a[0]-a[1])

for i in range(2, len(a)):
    d[i] = min(d[i-1]+abs(a[i]-a[i-1]), d[i-2]+abs(a[i]-a[i-2]))
print(d[-1])

Buggy python submission (verdict: Runtime Error):
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(input())
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

# Top down
def dp(i):
	if i < 0: return 0
	else:
		if ans[i] != None: return ans[i]
		
		t1 = t2 = int(1e9)
		if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
		if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
		ans[i] = min(t1, t2)

		return ans[i]

dp(n-1)

# Bottom up
# for i in range(1, n):
# 	t1 = t2 = int(1e9)
# 	if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
# 	if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
# 	ans[i] = min(t1, t2)

print(ans[n-1])


Fixed submission:
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(input())
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

# # Top down
# def dp(current):
# 	if ans[current] != None: return ans[current]

# 	if current < 0: return 0
# 	else:
# 		t1 = t2 = int(1e9)
# 		if current-1 >= 0: t1 = abs(q[current] - q[current-1]) + dp(current-1)
# 		if current-2 >= 0: t2 = abs(q[current] - q[current-2]) + dp(current-2)

# 		ans[current] = min(t1, t2)
# 		return ans[current]

# dp(n-1)

for i in range(1, n):
	t1 = t2 = int(1e9)
	if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
	if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
	ans[i] = min(t1, t2)
# print(ans)
print(ans[n-1])

Buggy python submission (verdict: Runtime Error):
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(input())
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

# Top down
def dp(i):
	if i < 0: return 0
	else:
		if ans[i] != None: return ans[i]

		if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
		if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
		ans[i] = min(t1, t2)
		
		return ans[i]

dp(n-1)

# Bottom up
# for i in range(1, n):
# 	t1 = t2 = int(1e9)
# 	if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
# 	if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
# 	ans[i] = min(t1, t2)

print(ans[n-1])


Fixed submission:
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(input())
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

# # Top down
# def dp(current):
# 	if ans[current] != None: return ans[current]

# 	if current < 0: return 0
# 	else:
# 		t1 = t2 = int(1e9)
# 		if current-1 >= 0: t1 = abs(q[current] - q[current-1]) + dp(current-1)
# 		if current-2 >= 0: t2 = abs(q[current] - q[current-2]) + dp(current-2)

# 		ans[current] = min(t1, t2)
# 		return ans[current]

# dp(n-1)

for i in range(1, n):
	t1 = t2 = int(1e9)
	if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
	if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
	ans[i] = min(t1, t2)
# print(ans)
print(ans[n-1])

Buggy python submission (verdict: Runtime Error):
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(input())
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

# Top down
def dp(current):
	if current < 0: return 0
	else:
		if ans[current] != None: return ans[current]
		
		t1 = t2 = int(1e9)
		if current-1 >= 0: t1 = abs(q[current] - q[current-1]) + dp(current-1)
		if current-2 >= 0: t2 = abs(q[current] - q[current-2]) + dp(current-2)

		ans[current] = min(t1, t2)
		return ans[current]

dp(n-1)

# Bottom up
# for i in range(1, n):
# 	t1 = t2 = int(1e9)
# 	if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
# 	if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
# 	ans[i] = min(t1, t2)

print(ans[n-1])


Fixed submission:
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(input())
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

# # Top down
# def dp(current):
# 	if ans[current] != None: return ans[current]

# 	if current < 0: return 0
# 	else:
# 		t1 = t2 = int(1e9)
# 		if current-1 >= 0: t1 = abs(q[current] - q[current-1]) + dp(current-1)
# 		if current-2 >= 0: t2 = abs(q[current] - q[current-2]) + dp(current-2)

# 		ans[current] = min(t1, t2)
# 		return ans[current]

# dp(n-1)

for i in range(1, n):
	t1 = t2 = int(1e9)
	if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
	if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
	ans[i] = min(t1, t2)
# print(ans)
print(ans[n-1])

Buggy python submission (verdict: Runtime Error):
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(input())
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

# Top down
def dp(current):
	if ans[current] != None: return ans[current]

	if current < 0: return 0
	else:
		t1 = t2 = int(1e9)
		if current-1 >= 0: t1 = abs(q[current] - q[current-1]) + dp(current-1)
		if current-2 >= 0: t2 = abs(q[current] - q[current-2]) + dp(current-2)

		ans[current] = min(t1, t2)
		return ans[current]

dp(n-1)
print(ans[n-1])


Fixed submission:
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(input())
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

# # Top down
# def dp(current):
# 	if ans[current] != None: return ans[current]

# 	if current < 0: return 0
# 	else:
# 		t1 = t2 = int(1e9)
# 		if current-1 >= 0: t1 = abs(q[current] - q[current-1]) + dp(current-1)
# 		if current-2 >= 0: t2 = abs(q[current] - q[current-2]) + dp(current-2)

# 		ans[current] = min(t1, t2)
# 		return ans[current]

# dp(n-1)

for i in range(1, n):
	t1 = t2 = int(1e9)
	if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
	if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
	ans[i] = min(t1, t2)
# print(ans)
print(ans[n-1])