CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
h = list(map(int,input().split()))
dp = [10001] * n 
dp[0] = 0
dp[1] = abs(h[1] - h[0])
a = [[-1] * n for i in range(n)]
def chmin(a, b):
    if a <= b:
        pass
    else:
        a = b
    return a

for i in range(2, n):
    if a[i - 2][i] == -1:
        a[i][i - 2] = a[i - 2][i] = abs(h[i - 2] - h[i])
    if a[i - 1][i] == -1:
        a[i][i - 1] = a[i - 1][i] = abs(h[i - 1] - h[i])
    
    dp[i] = chmin(dp[i],dp[i - 2] + a[i - 2][i])
    dp[i] = chmin(dp[i],dp[i - 1] + a[i - 1][i])
    
print((dp[n - 1]))




# Optimized solution
n = int(eval(input()))
h = list(map(int,input().split()))
INF = float('inf')
dp = [INF] * n 
dp[0] = 0
dp[1] = abs(h[1] - h[0])

def chmin(a, b):
    if a <= b:
        return a
    else:
        return b 
    

for i in range(2, n):

    dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]))
    dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i - 1] - h[i]))
    
print((dp[n - 1]))
# Original solution
# coding: utf-8
# Your code here!
N=int(eval(input()))
A=list(map(int,input().split()))
dp=[0]*N
dp[1]=abs(A[1]-A[0])

for i in range(2,N):
    dp[i]=min((dp[i-2]+abs(A[i]-A[i-2])),dp[i-1]+abs(A[i]-A[i-1]))

print((dp[-1]))


# Optimized solution
# coding: utf-8
# Your code here!
N=int(eval(input()))
H=list(map(int,input().split()))

dp=[0]*N
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[-1]))
# Original solution
N = int(eval(input()))
h = list(map(int, input().split()))
INF = 1000 * 1000 * 1000
dp = [INF] * N

def absoluteDiff(a, b):
	if a > b:
		return a - b
	else:
		return b - a

dp[0] = 0
dp[1] = absoluteDiff(h[0], h[1])
for i in range(0, N - 2):
	dp[i + 1] = min(dp[i + 1], dp[i] + absoluteDiff(h[i], h[i + 1]))
	dp[i + 2] = dp[i] + absoluteDiff(h[i], h[i + 2])
dp[N - 1] = min(dp[N - 1], dp[N - 2] + absoluteDiff(h[N - 2], h[N - 1]))
print((str(dp[N - 1])))


# Optimized solution
INF=int('fffFFFFffffFFFF',16)

n=int(eval(input()))
h=list(map(int,input().split()))
dp=[INF] * n

dp[0]=0
dp[1]=abs(h[1]-h[0])

for i in range(2,n):
    dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2])
print((dp[n-1]))
# Original solution
n = int(eval(input()))
h = list(map(int, input().split()))

dp = [0] * n
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
  dp[i] = min(dp[i - k] + abs(h[i]-h[i-k]) for k in [1, 2])

print((dp[-1]))

# Optimized solution
n = int(eval(input()))
H = list(map(int, input().split()))

dp = [10 ** 12] * (n)
dp[0] = 0
dp[1] = abs(H[1] - H[0])

for i in range(1, n-1):
  dp[i+1] = min(dp[i] + abs(H[i+1] - H[i]), dp[i-1] + abs(H[i+1] - H[i-1]))
  
ans = dp[n-1]

print(ans)
# Original solution
def retMin(a,b):
  if a >= b:
    return b
  else:
    return a  

n=int(eval(input()))
r=list(map(int,input().split()))
dpList = [99999999999] * (n)

dpList[0] = 0

for i in range(1,n):
  if i<2:
    dpList[i] = retMin(dpList[i],dpList[i-1]+(abs(r[i]-r[i-1])))
  else:
    dpList[i] = retMin(dpList[i-1]+(abs(r[i]-r[i-1])),dpList[i-2]+(abs(r[i]-r[i-2])))
  
print((dpList[n-1]))

# Optimized solution
def retMin(a,b):
  if a >= b:
    return b
  else:
    return a  
 
n=int(eval(input()))
r=list(map(int,input().split()))
dpList = [99999999999] * (n)
 
dpList[0] = 0
dpList[1] = dpList[0]+(abs(r[1]-r[0]))
 
for i in range(2,n):
  dpList[i] = retMin(dpList[i-1]+(abs(r[i]-r[i-1])),dpList[i-2]+(abs(r[i]-r[i-2])))
  
print((dpList[n-1]))
# Original solution
def helper(h, n):
    res = [0]*n
    res[0] = 0
    res[1] = abs(h[1]-h[0])
    for i in range(2, n):
        res[i] = min(res[i-1]+abs(h[i]-h[i-1]), res[i-2]+abs(h[i]-h[i-2]))
    return res[-1]

def main():
    n = int(eval(input()))
    h = list(map(int, input().split(" ")))
    print((helper(h, n)))

if __name__ == "__main__":
    main()

# Optimized solution
def helper(h, n):
    prev = 0
    curr = abs(h[1]-h[0])
    for i in range(2, n):
        next = min(curr+abs(h[i]-h[i-1]), prev+abs(h[i]-h[i-2]))
        prev = curr
        curr = next
    return curr

def main():
    n = int(eval(input()))
    h = list(map(int, input().split(" ")))
    print((helper(h, n)))

if __name__ == "__main__":
    main()
# Original solution
n = int(eval(input()))
h = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
for i in range(n):
    if i==0:
        dp[i] = 0
    elif i==1:
        dp[i] = abs(h[i]-h[i-1])
    else:
        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]))

# Optimized solution
N = int(eval(input()))
H = list(map(int, input().split()))
H = [0] + H
dp = [0] * (N+1)
for i in range(2,N+1):
    if i-2>=1:
        dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]), dp[i-2]+abs(H[i]-H[i-2]))
    else:
        dp[i] = dp[i] + abs(H[i]-H[i-1])
res = dp[N]
print(res)
# Original solution
N = int(eval(input()))
H = list(map(int, input().split()))
for _ in range(10):
    H.append(10**9)
dp = [10**9] * (N+2)
dp[0] = 0
# 配る方式
for i in range(N):
    dp[i+1] = min(dp[i] + abs(H[i]-H[i+1]),dp[i+1])
    dp[i+2] = min(dp[i] + abs(H[i]-H[i+2]), dp[i+2])
print((dp[N-1]))



# Optimized solution
N = int(eval(input()))
H = list(map(int, input().split()))
for _ in range(10):
    H.append(10**9)
dp = [10**9] * (N+2)
dp[0] = 0
# 引っ張ってくる方式
for i in range(1, 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]))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

dp = [10**9+1]*n
dp[0] = 0
dp[1] = dp[0] + abs(a[1]-a[0])

for i in range(2, n):
    dp[i] = min([dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2])])

print((dp[n-1]))

# Optimized solution
n = int(eval(input()))
dp = [0]*(n+1)
a = list(map(int, input().split()))
  
dp[1] = abs(a[1]-a[0])
for i in range(2,n):
  dp[i] =  min(dp[i-2]+abs(a[i]-a[i-2]), dp[i-1]+abs(a[i]-a[i-1]))
print((dp[n-1]))
# Original solution
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(eval(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)


# Optimized solution
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(eval(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]))
# Original solution
a = int(eval(input()))


hs = [int(x) for x in input().split()]

if a == 1:
  print((0))
  exit()
dp = [0]* len(hs)


dp[0] = 0
dp[1] = abs(hs[1] - hs[0])

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

# Optimized solution
a = int(eval(input()))
hs = [int(x) for x in input().split()]

dp = [0]* len(hs)
dp[0] = 0
dp[1] = abs(hs[1] - hs[0])
     
for i in range(2, a):
	dp[i] = min(abs(hs[i-1]- hs[i]) + dp[i-1], abs(hs[i-2]- hs[i]) + dp[i-2] )
      
print((dp[-1]))
# Original solution
N = int(eval(input()))
C = list(map(int,input().split()))

dp = [-1 for _ in range(N)]

dp[0] = 0
dp[1] = abs(C[0] - C[1])

for i in range(0,N-2):
    dp[i+2] = min(dp[i] + abs(C[i+2]-C[i]) , dp[i+1] + abs(C[i+2] - C[i+1]))

print((dp[N-1])) 


# Optimized solution
N = int(eval(input()))
H = list(map(int,input().split()))

DP = [0 for _ in range(N)]

DP[1] = abs(H[1]-H[0])


if len(H) > 2:
    for i in range(2,N):
        DP[i] = min(DP[i-2]+abs(H[i]-H[i-2]),DP[i-1]+abs(H[i]-H[i-1]))

print((DP[N-1]))
# Original solution
def func():
    N = int(eval(input()))
    H = [int(i) for i in input().split()]
    
    dp = [0]*N
    for i in range(1, N):
        L = []
        for j in range(max(0, i-2), i):
            L.append(dp[j] + abs(H[i] - H[j]))
        dp[i] = min(L)

    print((dp[-1]))
    
if __name__=="__main__":
    func()

# Optimized solution
N = int(eval(input()))
H = [int(i) for i in input().split()]
dp = [0] * N

dp[1] = abs(H[1] - H[0])

for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(H[i] - H[i-2]), dp[i-1] + abs(H[i] - H[i-1]))
print((dp[-1]))
# Original solution
import math

N = int(eval(input()))
h = list(map(int, input().split()))
dp = [float('INF')] * (10**5 + 10)

def chmin(a, b):
    if a >= b:
        return b
    else:
        return a

dp[0] = 0 #初期値 = 0
for i in range(N-1):
    dp[i+1] = chmin(dp[i+1], dp[i] + abs(h[i+1] - h[i]))
    if i < N-2:
        dp[i+2] = chmin(dp[i+2], dp[i] + abs(h[i+2] - h[i]))
print((dp[N-1]))

# Optimized solution
import math
 
N = int(eval(input()))
h = list(map(int, input().split()))
dp = [float('INF')] * N
 
def chmin(a, b):
    if a >= b:
        return b
    else:
        return a
 
#初期値
dp[0] = 0
 
#Loop
for i in range(1, N):
    dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if i > 1:
        dp[i] = chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
print((dp[-1]))
# Original solution
n = int(eval(input()))
h = [int(i) for i in input().split()]
m = [0, abs(h[0]-h[1])]
for i in range(2, n):
    v = min(m[0]+abs(h[i-2]-h[i]), m[1]+abs(h[i-1]-h[i]))
    m = [m[1], v]
print((m[1]))

# Optimized solution
n = int(eval(input()))
h = tuple(int(i) for i in input().split())
x, y = 0, abs(h[0]-h[1])
for i in range(2, n):
    v = min(x+abs(h[i-2]-h[i]), y+abs(h[i-1]-h[i]))
    x, y = y, v
print(y)
# Original solution
n = int(eval(input()))
h = tuple(int(i) for i in input().split())
x, y = 0, abs(h[0]-h[1])
for i in range(2, n):
    v = min(x+abs(h[i-2]-h[i]), y+abs(h[i-1]-h[i]))
    x, y = y, v
print(y)

# Optimized solution
n = int(eval(input()))
h = tuple(map(int, input().split()))
x, y = 0, abs(h[0]-h[1])
for i in range(2, n):
    d1 = x+abs(h[i-2]-h[i])
    d2 = y+abs(h[i-1]-h[i])
    x, y = y, d1 if d1 < d2 else d2
print(y)
# Original solution
# -*- coding: utf-8 -*-


def main():
    n = int(eval(input()))
    h_list = list(map(int, input().split()))

    dp = [0]

    for i in range(n):
        dp.append(9999999999)
        if i > 0:
            dp[i] = min(dp[i], dp[i - 1] + abs(h_list[i] - h_list[i - 1]))
        if i > 1:
            dp[i] = min(dp[i], dp[i - 2] + abs(h_list[i] - h_list[i - 2]))

    print((dp[-2]))


if __name__ == '__main__':
    main()


# Optimized solution
# -*- coding: utf-8 -*-


def main():
    n = int(eval(input()))
    h_list = list(map(int, input().split()))

    dp = [0] + [9999999999] * (n - 1)

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

    print((dp[-1]))


if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
H = list(map(int, input().split()))
H.append(0)
H.append(0)

#dp[足場i]=足場iにたどり着く最小コスト
dp = [10**10 for _ in range(N+10)]

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

print((dp[N-1]))


# Optimized solution
N = int(eval(input()))
h = list(map(int, input().split()))

dp = [0] * (N)
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
    dp[i] = dp[i-1] + abs(h[i] - h[i-1])
    dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print((dp[N-1]))
# Original solution
import itertools

n = int(eval(input()))
h = list(map(int, input().split()))


combi = []
perm = []

# 1からn桁の[1, 2]の数字の組み合わせのうち合計値がnになるものをcombiに代入
for i in range(int(n / 2), n + 1):
    tmp_combi = list(itertools.combinations_with_replacement([1, 2], i))
    for c in (tmp_combi):
        if sum(c) == n:
            combi.append(c)

# combiの順列を作成しpermに入れる
# setを使いユニークにしている
# 1, 1, 2 -> 1 1 2, 1 2 1, 2 1 1
for c in combi:
    for p in list(set(list(itertools.permutations(c)))):
        perm.append(p)

# 順列1つずつに対しコストを計算して最小値をmin_costに代入
min_cost = 10 ** 10
for p in perm:
    cost = 0
    p = list(p)
    pos = p.pop(0)
    if pos != 1:
        continue
    for j in p:
        cost += abs(h[pos - 1] - h[pos + j - 1])
        pos += j
    if cost < min_cost:
        min_cost = cost

print(min_cost)

# Optimized solution
N = int(eval(input()))
blank = 2
h = list(map(int,input().split())) + [0] * blank
INF = 10 ** 9 + 1
dp = [INF] * (N + blank)
dp[0] = 0
for i in range(N):
  dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i + 1])
  dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 2])
  
print((dp[N - 1]))
# Original solution
n = int(eval(input()))
hlis = list(map(int, input().split()))
hlis.append(float('inf'))
dp = [0] + [abs(hlis[0] - hlis[1])] + [float('inf')]*(n-1)
for i in range(n-1):
    one = abs(hlis[i]-hlis[i+1])
    two = abs(hlis[i]-hlis[i+2])
    dp[i+1] = min(dp[i]+one, dp[i+1])
    dp[i+2] = min(dp[i]+two, dp[i+2])
print((dp[n-1]))

# Optimized solution
N = int(eval(input()))
hlis = list(map(int, input().split()))
dp = [-1]*N
dp[0] = 0
dp[1] = abs(hlis[0] - hlis[1])
for i in range(2, N):
    dp[i] = min(dp[i-1]+abs(hlis[i]-hlis[i-1]), dp[i-2]+abs(hlis[i]-hlis[i-2]))
print((dp[-1]))
# Original solution
n=int(eval(input()))
numbers = [int(n) for n in input().split()]
cost = []
for i in range(0,n):
    cost.append(0)
#cost[0]=0
cost[1]=abs(numbers[1]-numbers[0])
for i in range(2,n):
    cost[i]=min((cost[i-2]+abs(numbers[i]-numbers[i-2])),(cost[i-1]+abs(numbers[i]-numbers[i-1])))
    
#print(cost)
print((cost[n-1]))

# Optimized solution
n=int(eval(input()))
h=list(map(int,input().split()))
dp=[0]*(n+1)
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
  # print(dp)
print((dp[-2]))
# Original solution
n = int(eval(input()))
h = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(1,n-1):
    dp[i+1] = min(dp[i-1]+abs(h[i+1]-h[i-1]),dp[i]+abs(h[i+1]-h[i]))
print((dp[-1]))

# Optimized solution
n = int(eval(input()))
h = list(map(int,input().split()))
dp = [0]*(n)
for i in range(1,n):
    if i>1:
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))
    else:
        dp[i] = dp[i-1] + abs(h[i]-h[i-1])
print((dp[-1]))
# Original solution
n=int(eval(input()))
h=list(map(int,input().split()))

dp=[float('inf')]*n
dp[0]=0#初期条件を設定

for i in range(1,n):
    dp[i]=min(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
    #i=1の時i-2<0となるので先にここを計算する
    if i>=2:
        dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]))
        
print((dp[-1]))

# Optimized solution
#DP-A
n=int(eval(input()))
h=list(map(int,input().split()))

dp=[float('inf')]*n
dp[0]=0
for i in range(1,n):

    #2パターンの遷移を考え小さいほうを保存する
    dp[i]=dp[i-1]+abs(h[i]-h[i-1])
    if i>1:
        dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]))

print((dp[-1]))
# Original solution
N = int(eval(input()))
H = [int(c) for c in input().split()]

prv1 = prv2 = cur = 0
for i in range(1, N):
    j1 = abs(H[i] - H[i-1])
    cur = min(j1 + prv1, abs(H[i] - H[i-2]) + prv2) if i > 1 else j1
    prv2 = prv1
    prv1 = cur

print(cur)


# Optimized solution
N = int(eval(input()))
H = [int(c) for c in input().split()]

cur = abs(H[1] - H[0])
prv1 = cur
prv2 = 0
for i in range(2, N):
    cur = min(abs(H[i] - H[i-1]) + prv1, abs(H[i] - H[i-2]) + prv2)
    prv2 = prv1
    prv1 = cur

print(cur)
# Original solution
N = int(eval(input()))
h_list = input().split()
h_list = [int(i) for i in h_list]
current_V = [0]
current_value = [0] * N
current_cost = 0
while (current_V != []):

    V = current_V.pop(0)
    if N - 1 >= V + 1 :
        if V + 1 not in current_V :
            current_V.append(V + 1)
            current_value[V + 1] = current_value[V] + abs(h_list[V] - h_list[V + 1])
        else:
            value = current_value[V] + abs(h_list[V] - h_list[V + 1])
            if value < current_value[V + 1]:
                current_value[V + 1] = value
    if N - 1 >= V + 2 :
        if V + 2 not in current_V :
            current_V.append(V + 2)
            current_value[V + 2] = current_value[V] + abs(h_list[V] - h_list[V + 2])
        else:
            value = current_value[V] + abs(h_list[V] - h_list[V + 2])
            if value < current_value[V + 2]:
                current_value[V + 2] = value
print((current_value[N - 1]))


# Optimized solution
N = int(eval(input()))
h_list = input().split()
h_list = [int(i) for i in h_list]
current_V = [0]
current_value = [0] * N
current_value[1]=abs(h_list[0]-h_list[1])
for i in range(2,N) :
    current_value[i]=min(current_value[i-1]+abs(h_list[i-1]-h_list[i]),current_value[i-2]+abs(h_list[i-2]-h_list[i]))

print((current_value[-1]))
# Original solution
n=int(eval(input()))
h=list(map(int, input().split()))

dp=[0]*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[-1]))

# Optimized solution
n=int(eval(input()))
h=list(map(int,input().split()))

dp=[0]*n

dp[0]=0
dp[1]=abs(h[0]-h[1])

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[-1]))
# Original solution
def 解():
    N = int(eval(input()))
    aH = [int(_) for _ in input().split()]

    #dp = [0]*3
    #dp[1] = abs(aH[0] - aH[1])
    dp={0:0,1:abs(aH[0]-aH[1]),2:0}
    for i in range(2,N):
        dp[i%3] = min(abs(aH[i]-aH[i-1])+dp[(i-1)%3],abs(aH[i]-aH[i-2]) + dp[(i-2)%3])
    print((dp[(N-1)%3]))
解()


# Optimized solution
def 解():
    N = int(eval(input()))
    aH = [int(_) for _ in input().split()]

    dp = [0]*3
    dp[1] = abs(aH[0] - aH[1])
    #dp={0:0,1:abs(aH[0]-aH[1]),2:0}
    for i in range(2,N):
        dp[i%3] = min(abs(aH[i]-aH[i-1])+dp[(i-1)%3],abs(aH[i]-aH[i-2]) + dp[(i-2)%3])
    print((dp[(N-1)%3]))
解()
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

INF = 10 ** 10

n = int(eval(input()))
# 貰うDPだと0へのアクセスが、配るDPだとn+1へのアクセスが必要になる
h = [INF] + list(map(int, input().split())) + [INF]
dp = [INF] + [INF] * n + [INF]
dp[1] = 0

def chmin(dp_table, index, value):
    if dp_table[index] > value:
        dp_table[index] = value

# 貰うDP(dp[i-1], dp[i-2]が計算済み)
#for i in range(2, n+1):
#    chmin(dp, i, dp[i-1] + abs(h[i] - h[i-1]))
#    chmin(dp, i, dp[i-2] + abs(h[i] - h[i-2]))

# 配るDB(dp[i]が計算済み)
#for i in range(1, (n-1)+1):
#    chmin(dp, i+1, dp[i] + abs(h[i] - h[i+1]))
#    chmin(dp, i+2, dp[i] + abs(h[i] - h[i+2]))
#
#print(dp[n])

# 再帰(DFS) (メモ化なし)
def dfs(i):
    if i == 0:
        return INF
    if i == 1:
        return 0

    ans = INF
    prev_cost = dfs(i-1)
    if ans > prev_cost + abs(h[i] - h[i-1]):
        ans = prev_cost + abs(h[i] - h[i-1])
    prev_cost = dfs(i-2)
    if ans > prev_cost + abs(h[i] - h[i-2]):
        ans = prev_cost + abs(h[i] - h[i-2])

    return ans

# 再帰(DFS) (メモ化ありfunctools.lru_cache使用)
import functools
dfs = functools.lru_cache(maxsize=None)(dfs)

print((dfs(n)))  


# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

INF = 10 ** 10

n = int(eval(input()))
# 貰うDPだと0へのアクセスが、配るDPだとn+1へのアクセスが必要になる
h = [INF] + list(map(int, input().split())) + [INF]
dp = [INF] + [INF] * n + [INF]
dp[1] = 0

def chmin(dp_table, index, value):
    if dp_table[index] > value:
        dp_table[index] = value

# 再帰(DFS) (メモ化あり: テーブル使用)
def dfs(i):
    if i == 0:
        return INF
    if i == 1:
        return 0
    if dp[i] != INF:
        return dp[i]

    ans = INF
    prev_cost = dfs(i-1)
    if ans > prev_cost + abs(h[i] - h[i-1]):
        ans = prev_cost + abs(h[i] - h[i-1])
    prev_cost = dfs(i-2)
    if ans > prev_cost + abs(h[i] - h[i-2]):
        ans = prev_cost + abs(h[i] - h[i-2])

    dp[i] = ans
    return dp[i]

print((dfs(n)))
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

INF = 10 ** 10

n = int(eval(input()))
# 貰うDPだと0へのアクセスが、配るDPだとn+1へのアクセスが必要になる
h = [INF] + list(map(int, input().split())) + [INF]
dp = [INF] + [INF] * n + [INF]
dp[1] = 0

def chmin(dp_table, index, value):
    if dp_table[index] > value:
        dp_table[index] = value

# 再帰(DFS) (メモ化あり: テーブル使用)
def dfs(i):
    if i == 0:
        return INF
    if i == 1:
        return 0
    if dp[i] != INF:
        return dp[i]

    ans = INF
    prev_cost = dfs(i-1)
    if ans > prev_cost + abs(h[i] - h[i-1]):
        ans = prev_cost + abs(h[i] - h[i-1])
    prev_cost = dfs(i-2)
    if ans > prev_cost + abs(h[i] - h[i-2]):
        ans = prev_cost + abs(h[i] - h[i-2])

    dp[i] = ans
    return dp[i]

print((dfs(n)))


# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

INF = 10 ** 20
n = int(eval(input()))
h = [INF] + list(map(int, input().split())) + [INF]

dp = [INF] + [INF] * n + [INF]
dp[1] = 0

for i in range(1, n):
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]))
    dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]))

print((dp[n]))
# Original solution
import sys
sys.setrecursionlimit(1000000)

# 入力
N = int(eval(input()))
H = [int(i) for i in input().split()]

# メモ用のDPテーブルを生成
dp = [float("inf") for i in range(N)]

# 足場iにたどり着く最初コストを返す
def rec(i):
    # ベースケースをセット
    if i == 0:
        return 0
    
    # メモをチェック
    if dp[i] < float("inf"):
        return dp[i]
    
    # i-1から遷移する場合
    cost = rec(i-1) + abs(H[i] - H[i-1])
    # i-2から遷移する場合
    if i > 1:
        cost = min(cost, rec(i-2) + abs(H[i] - H[i-2]))
    
    # 結果をメモしてから返す
    dp[i] = cost
    return cost

print((rec(N-1)))

# Optimized solution
N = int(eval(input()))
H = [int(i) for i in input().split()]

dp = [float("inf")] * N
dp[0], dp[1] = 0, abs(H[1]-H[0])
for i in range(2, N):
    dp[i] = min(dp[i], dp[i-1]+abs(H[i]-H[i-1]), dp[i-2]+abs(H[i]-H[i-2]))
    
print((dp[N-1]))
# Original solution
n = int(eval(input()))
h = list(map(int,input().split()))
inf = 10 ** 10
dp = [inf] * n
dp[0] = 0
for i in range(n - 1):
    temp = abs(h[i + 1] - h[i])
    dp[i + 1] = min(dp[i + 1], temp + dp[i])
    if i + 2 < n:
        temp = abs(h[i + 2] - h[i])
        dp[i + 2] = min(dp[i + 2], temp + dp[i])
print((dp[-1]))

# Optimized solution
N = int(eval(input()))
h = [int(i) for i in input().split()]
dp = [10**10 for _ in range(N)]
dp[0] = 0
for i in range(N-1):
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1]-h[i]))
    if i+2 < N:
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2]-h[i]))
print((dp[-1]))
# Original solution
N = int(eval(input()))
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(1, N):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i])
    if i + 1 < N:
        dp[i+1] = min(dp[i-1] + abs(h[i+1] - h[i-1]) , dp[i+1])
print((dp[N-1]))

# Optimized solution
N = int(eval(input()))
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(1, N):
    dp[i] = min(dp[i], dp[i-1]+abs(h[i] - h[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i-2]+abs(h[i] - h[i-2]))
print((dp[N-1]))
# Original solution
from sys import stdin as I
from sys import stdout as O
N = int(I.readline())
H = [None] + list(map(int,I.readline().split()))
DP = [None for i in range(N+1)]
DP[1] = 0
DP[2] = abs(H[2]-H[1])
for i in range(3,N+1):DP[i] = min(DP[i-2]+abs(H[i]-H[i-2]),DP[i-1]+abs(H[i]-H[i-1]))
print((DP[N]))

# Optimized solution
N = int(eval(input()))
h = [*list(map(int, input().split()))]
dp = [0, abs(h[1] - h[0])] + [0] * (N - 2)
for i in range(2, N):
	dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1],abs(h[i] - h[i-2]) + dp[i-2])
print((dp[N-1]))
# Original solution
n = int(eval(input()))
H = list(map(int, input().split()))
cost = [None]*n
h1 = [None]*(n-1)
h2 = [None]*(n-2) 
one_ago = H[1]
two_ago = H[0]
h1[0] = abs(two_ago-one_ago)
for i in range(2, n):
    new = H[i]
    h1[i-1] = abs(one_ago-new)
    h2[i-2] = abs(two_ago-new)
    two_ago, one_ago = one_ago, new
cost[0], cost[1] = 0, h1[0]
for i in range(2, n):
    cost[i] = min(cost[i-2]+h2[i-2], cost[i-1]+h1[i-1])
print((cost[n-1]))

# Optimized solution
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [None]*n
dp[0], dp[1] = 0, abs(h[0]-h[1])
for i in range(2, n):
    dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i]))
print((dp[-1]))