CodeEff/ECCO huggingface dataset:
# Original solution
import sys
def solve(stns, idx, mem):

    if idx >= len(stns) -1:
        return 0

    if idx in mem: 
        return mem[idx]

    if idx == len(stns) - 2: 
        # can take only one step
        # print(idx)  
        # final_step = solve(stns, idx + 1, mem) + abs(stns[idx] - stns[idx+1])
        final_step = abs(stns[idx] - stns[idx+1])
        mem[idx] = final_step
        return final_step
    else: 
        # step: i + 11
        step1 = solve(stns, idx + 1, mem) + abs(stns[idx] - stns[idx+1])
        # step: i + 2
        step2 = solve(stns, idx + 2, mem) + abs(stns[idx] - stns[idx+2])

        min_cost = min(step1, step2)
        mem[idx] = min_cost 

        return min_cost



def take_input():
    # n = input()
    # stns = [int(x) for x in input().split(' ')]



    reader = (s.rstrip() for s in sys.stdin)
    input = reader.__next__
    sys.setrecursionlimit(1000000)
    # do magic here
    n = int(eval(input()))
    stns = [int(x) for x in input().split()]
    mem = {}
    res = solve(stns, 0, mem)
    print(res)

take_input()

# Optimized solution
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
sys.setrecursionlimit(1000000)


def solve(stns, idx, mem):

    if idx >= len(stns) -1:
        return 0

    if idx in mem: 
        return mem[idx]

    if idx == len(stns) - 2: 
        #cant take more than one step
        final_step = abs(stns[idx] - stns[idx+1])
        mem[idx] = final_step
        return final_step
    else: 
        # step: i + 11
        step1 = solve(stns, idx + 1, mem) + abs(stns[idx] - stns[idx+1])
        # step: i + 2
        step2 = solve(stns, idx + 2, mem) + abs(stns[idx] - stns[idx+2])

        min_cost = min(step1, step2)
        mem[idx] = min_cost 

        return min_cost



def take_input():
    n = eval(input())
    stns = [int(x) for x in input().split()]
    mem = {}
    res = solve(stns, 0, mem)
    print(res)

take_input()
# Original solution
import math

N = int(eval(input()))
vals = list(map(int, input().split()))


def chmin_orig(i1, i2):
    if dp[i1] > (dp[i2] + abs(vals[i1]-vals[i2])):
        dp[i1] = dp[i2] + abs(vals[i1]-vals[i2])
        return True
    return False


dp = [float('inf')] * 100010
dp[0] = 0
for i in range(N):
    chmin_orig(i, i-1)
    if i > 1:
        chmin_orig(i, i-2)

print((dp[N-1]))


# Optimized solution
N = int(eval(input()))
costs = list(map(int, input().split())) + [0]*10000


def chmin(i, j, dp, costs):
    if dp[i+j] > dp[i] + abs(costs[i] - costs[i+j]):
        dp[i+j] = dp[i] + abs(costs[i] - costs[i+j])
        return True
    return False


dp = [float('inf')] * 100010
dp[0] = 0
for i in range(N):
    chmin(i, 1, dp, costs)
    chmin(i, 2, dp, costs)

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

# 足場 i にたどり着くまでのコストの総和の最小値
dp = [1e14] * n

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

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

print((dp[n - 1]))


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

# 足場 i にたどり着くまでに支払うコストの総和の最小値
# 初期値として足場 0 にいるので dp[0] = 0
dp = [0] * n
# 足場 1 に行くための最小値は 0 → 1 と行く場合に当たるので
dp[1] = abs(hs[1] - hs[0])

# DP する
for i in range(2, n):
    cost_sum_1 = dp[i - 1] + abs(hs[i] - hs[i - 1])
    cost_sum_2 = dp[i - 2] + abs(hs[i] - hs[i - 2])
    dp[i] = min(cost_sum_1, cost_sum_2)

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

print((ls_cos[-1]))



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

# Optimized solution
N = int(eval(input()))
h = list(map(int, input().split()))
dp = [float("inf") 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 < N - 2:
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print((dp[N - 1]))
# Original solution
N = int(eval(input()))
h = list(map(int, input().split()))

ans = [100000000000] * N
ans[0] = 0
for i in range(N-1):
    ans[i+1] = min(ans[i+1], ans[i] + abs(h[i] - h[i+1]))
    if i + 2 > N - 1:
        continue
    ans[i+2] = min(ans[i+2], ans[i] + abs(h[i] - h[i+2]))
print((ans[-1]))  

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

ans = [float("inf")] * N
ans[0] = 0
for i in range(N-1):
    ans[i+1] = min(ans[i+1], ans[i] + abs(h[i] - h[i+1]))
    if i + 2 > N - 1:
        continue
    ans[i+2] = min(ans[i+2], ans[i] + abs(h[i] - h[i+2]))
print((ans[-1]))
# Original solution
import sys
sys.setrecursionlimit(10**6)

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

def rec(i: int, c: int) -> int:
    if i == 0:
        return c
    elif i <= 1:
        return rec(i-1, c+abs(h[i]-h[i-1]))

    return min(rec(i-1, c+abs(h[i]-h[i-1])), rec(i-2, c+abs(h[i]-h[i-2])))

print((rec(n-1, 0)))

"""
3,0
2,20 1,10
1,30 0,50 0,30
0,50
"""


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

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

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

print((dp[n-1]))
# Original solution
n = int(eval(input()))
h = [int(i) for i in input().split()]

# dpの最小値を変更する関数
def chmin(a, b):
    if a > b:
        return b
    else:
        return a
    
# 無限大の値
f_inf = float('inf')

# DP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * (10**5+10)

# 初期条件
dp[0] = 0

# 足場 i-1 から足場 i へ移動する。コストは|h[i]−h[i-1]|
# 足場 i-2 から足場 i へと移動する コストは |h[i]−h[i-2]|
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[n-1]))

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

# 無限大の値
f_inf = float('inf')

# DP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * n

# 初期条件
dp[0] = 0

# 足場 i-1 から足場 i へ移動する。コストは|h[i]−h[i-1]|
# 足場 i-2 から足場 i へと移動する コストは |h[i]−h[i-2]|
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
n = int(eval(input()))
h = [int(i) for i in input().split()]

# 無限大の値
f_inf = float('inf')

# DP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * n

# 初期条件
dp[0] = 0

# 足場 i-1 から足場 i へ移動する。コストは|h[i]−h[i-1]|
# 足場 i-2 から足場 i へと移動する コストは |h[i]−h[i-2]|
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]))


# Optimized solution

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

INF = float('inf')

#DPテーブル
dp = [INF] * N

#最初のコストは0
dp[0] = 0

#最小化問題
#i番目のコストの最小値は、i-1 or i -2 番目までのコストからiまでのコストを足したものの小さい方
for i in range(1,N):
    dp[i] = min(dp[i],dp[i-1] + abs(h[i]-h[i-1]))
    #i=1のときは、i-2番目が存在しない
    if (i > 1):
        dp[i] = min(dp[i],dp[i-2] + abs(h[i]-h[i-2]))

print((dp[N-1]))
# Original solution
import sys
sys.setrecursionlimit(10**8)

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

dp = [float("inf")] * n #dpテーブル
#dp[i]メモ化テーブル
#まずは使わない

def rec(i):#再帰による全探索
    if i == 0:
        return 0
    elif i == 1:
        return abs(h[0]-h[1])
    else:
        return min(rec(i-1)+abs(h[i]-h[i-1]),rec(i-2)+abs(h[i]-h[i-2]))

print((rec(n-1)))


# Optimized solution
import sys
sys.setrecursionlimit(10**8)

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

dp = [float("inf")] * n #dpテーブル
#dp[i]メモ化テーブル

def rec(i):#再帰による全探索
    if dp[i] != float("inf"):
        return dp[i]
    if i == 0:
        return 0
    elif i == 1:
        return abs(h[0]-h[1])
    else:
        dp[i] = min(rec(i-1)+abs(h[i]-h[i-1]),rec(i-2)+abs(h[i]-h[i-2]))
        return dp[i]

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

# Optimized solution
N=int(eval(input()))
h=list(map(int, input().split()))
dp=[10000000000000]*(N+2)
#初期状態
dp[0]=0
#配るDP
for i in range(N):
    try:
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
    except IndexError:
        pass
    try:
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
    except IndexError:
        pass
print((dp[N-1]))
# Original solution
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ls = [0] * n
    for i in range(1, n):
        if i == 1:
            ls[i] = abs(a[i] - a[i-1])
        else:
            ls[i] = min(ls[i-1] + abs(a[i] - a[i-1]), ls[i-2] + abs(a[i] - a[i-2]))
    print((ls[-1]))


if __name__ == '__main__':
    slove()


# Optimized solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    h = list(map(int, readline().split()))
    dp = [10 ** 10] * n
    dp[0] = 0
    for i in range(1, n):
        if i == 1:
            dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i])
        else:
            dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]), dp[i])
    print((dp[-1]))


if __name__ == '__main__':
    solve()
# Original solution
n = int(eval(input()))
hs = list(map(int, input().split()))

a, b = 0, abs(hs[1] - hs[0])

for i in range(2, n):
  d1 = a + abs(hs[i] - hs[i-2])
  d2 = b + abs(hs[i] - hs[i-1])
  a, b = b, d1 if d1 <= d2 else d2

print(b)

# Optimized solution
def main():
  n = int(eval(input()))
  hs = tuple(map(int, input().split()))

  a, b = 0, abs(hs[1] - hs[0])

  for i in range(2, n):
    d1 = a + abs(hs[i] - hs[i-2])
    d2 = b + abs(hs[i] - hs[i-1])
    a, b = b, d1 if d1 <= d2 else d2

  print(b)

if __name__ == "__main__":
  main()
# Original solution
def main():
  n = int(eval(input()))
  hs = tuple(map(int, input().split()))

  a, b = 0, abs(hs[1] - hs[0])

  for i in range(2, n):
    d1 = a + abs(hs[i] - hs[i-2])
    d2 = b + abs(hs[i] - hs[i-1])
    a, b = b, d1 if d1 <= d2 else d2

  print(b)

if __name__ == "__main__":
  main()

# Optimized solution
def main():
  n = int(eval(input()))
  hs = tuple(map(int, input().split()))

  a, b = 0, abs(hs[1] - hs[0])

  for i in range(2, n):
    c = hs[i]
    d1 = a + abs(c - hs[i-2])
    d2 = b + abs(c - hs[i-1])
    a, b = b, d1 if d1 <= d2 else d2

  print(b)

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

INF = float('inf')
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[-1]))

# Optimized 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-2] + abs(H[i-2]-H[i]), dp[i-1] + abs(H[i-1]-H[i]))
print((dp[-1]))
# Original solution
def main():
    N = int(eval(input()))
    H = list(map(int, input().split()))
    dp = [float('inf')] * (N + 5)
    dp[0] = 0
    for i in range(N):
        if i + 1 <= N - 1:
            dp[i+1] = min(dp[i+1], dp[i] + abs(H[i+1] - H[i]))
        if i + 2 <= N - 1:
            dp[i+2] = min(dp[i+2], dp[i] + abs(H[i+2] - H[i]))
    
    print((dp[N-1]))

    

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    N = int(eval(input()))
    H = list(map(int, input().split()))
    dp = [float('inf')] * (N + 5)
    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 - 2 >= 0:
            dp[i] = min(dp[i], dp[i-2] + abs(H[i] - H[i-2]))

    print((dp[N-1]))

if __name__ == "__main__":
    main()
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))

# dp には 足場(i)へ至る最小コストが入る。
dp=[float("inf")]*(n)
dp[0]=0
for i in range(n-1):
  dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]))
  if i+2 < n:
    dp[i+2]=min(dp[i+2],dp[i]+abs(a[i]-a[i+2]))
    
print((dp[-1]))
    



# Optimized solution
# 参考：
# https://qiita.com/drken/items/dc53c683d6de8aeacf5a

# ver 2,振り返る DP

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

# dp には 足場(i)へ至る最小コストが入る。
dp=[float("inf")]*(n)

# 振り返り起点(i==2)までのdp値は埋めておく。
dp[0]=0
dp[1]=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[-1]))
# Original solution
n=int(eval(input()))
h=list(map(int,input().split()))
dp=[float('inf')]*(n+1)
dp[1]=0
dp[0]=0
dp[2]=dp[1]+abs(h[1]-h[0])
for i in range(1,n-1):
  dp[i+2]=min(dp[i+1]+abs(h[i+1]-h[i]),dp[i]+abs(h[i+1]-h[i-1]))
  

print((dp[n]))

# Optimized solution
n=int(eval(input()))
h=list(map(int,input().split()))
dp=[float('inf')]*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)
print((dp[n-1]))
# Original solution
import sys
sys.setrecursionlimit(10 ** 7)

def solve(index: int, dp: list, footing: list) -> int:
    if dp[index] != -1:
        return dp[index]

    if index == 0:
        return 0
    elif index == 1:
        return abs(footing[1]-footing[0])

    tmp = min(solve(index-1, dp, footing)+abs(footing[index]-footing[index-1]), solve(index-2, dp, footing)+abs(footing[index]-footing[index-2]))
    #print(f'{tmp=}')
    dp[index] = tmp
    return tmp

N = int(eval(input()))
footing = list(map(int, input().split()))

dp = [-1] * N

ans = solve(N-1, dp, footing)

print(ans)

# Optimized solution

N = int(eval(input()))
footing = list(map(int, input().split()))

dp = [10 ** 10] * N
dp[0] = 0

# give
for i in range(N-1):
    if dp[i+1] > dp[i] + abs(footing[i+1] - footing[i]):
        dp[i+1] = dp[i] + abs(footing[i+1] - footing[i])

    if i < N-2:
        if dp[i+2] > dp[i] + abs(footing[i+2] - footing[i]):
            dp[i+2] = dp[i] + abs(footing[i+2] - footing[i])

print((dp[N-1]))
# Original solution
N = int(eval(input()))
H = list(map(int,input().split()))
import sys
import functools
#indexi番目にいるときの最小コスト
sys.setrecursionlimit(pow(10,6))

@functools.lru_cache(None)
def func(i):
    if i==0:
        return 0
    if i==1:
        return abs(H[0]-H[1])
    return min(func(i-1)+abs(H[i]-H[i-1]),func(i-2)+abs(H[i-2]-H[i]))

print((func(N-1)))


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

dp = [0]*N
dp[1]= abs(H[1]-H[0])
#dp[i] インデックスiにいるときの最小値


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]))

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

c = [0] * n
c[0] = 0
c[1] = abs(h[0] - h[1])

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

print((c[-1]))


# Optimized solution
n = int(eval(input()))
hs = tuple(map(int, input().split()))

a, b = 0, abs(hs[1] - hs[0])

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

print(b)
# Original solution
def main():
    n = int(eval(input()))
    hs = tuple(map(int, input().split()))
    
    a, b = 0, abs(hs[1] - hs[0])
    
    for i in range(2, n):
        c = hs[i]
        a, b = b, min(a + abs(c - hs[i-2]), b + abs(c - hs[i-1]))
    
    print(b)

if __name__ == "__main__":
    main()

# Optimized solution
def main():
  n = int(eval(input()))
  hs = tuple(map(int, input().split()))

  a, b = 0, abs(hs[1] - hs[0])

  for i in range(2, n):
    d1 = a + abs(hs[i] - hs[i-2])
    d2 = b + abs(hs[i] - hs[i-1])
    a, b = b, min(d1, d2)

  print(b)

if __name__ == "__main__":
  main()
# Original solution
def main():
  n = int(eval(input()))
  hs = tuple(map(int, input().split()))

  a, b = 0, abs(hs[1] - hs[0])

  for i in range(2, n):
    d1 = a + abs(hs[i] - hs[i-2])
    d2 = b + abs(hs[i] - hs[i-1])
    a, b = b, min(d1, d2)

  print(b)

if __name__ == "__main__":
  main()


# Optimized solution
def main():
  n = int(eval(input()))
  hs = tuple(map(int, input().split()))

  a, b = 0, abs(hs[1] - hs[0])

  for i in range(2, n):
    d1 = a + abs(hs[i] - hs[i-2])
    d2 = b + abs(hs[i] - hs[i-1])
    a, b = b, d1 if d1 <= d2 else d2

  print(b)

if __name__ == "__main__":
  main()
# Original solution
a = int(eval(input()))
b = 2#int(input())
x = list(map(int, input().split()))
dp = [0]+[10**10]*(a-1)
dp[1] = abs(x[1]-x[0])
for i,h in enumerate(x):
    if i<a-b:
        for di in range(1,b+1):
            dp[i+di] = min(dp[i+di],dp[i]+abs(h-x[i+di]))
    elif i <=a-b:
        dp[i+1] =min(dp[i+1],dp[i]+abs(h-x[i+1]))
#print(dp)
print((dp[a-1]))

# Optimized solution
a = int(eval(input()))
b = 2+1#int(input())
x = list(map(int, input().split()))
dp = [0]+[10**10]*(a-1)
dp[1] = abs(x[1]-x[0])
for i,h in enumerate(x):
    for j in range(i+1,min(i+b,a)):
        dp[j] = min(dp[j],dp[i]+abs(h-x[j]))
#print(dp)
print((dp[a-1]))
# Original solution
N = int(eval(input()))
hlist = list(map(int, input().split()))
cost = [-1 for _ in range(N)]
cost[0] = 0
cost[1] = abs(hlist[1] - hlist[0])
#再帰
"""
def function(n)
if 終了条件 return 初項
return function(n-1)を処理したもの
"""
def dp(n):
  #print(n)
  if n==0: return cost[0]
  elif n==1: return cost[1]
  else: return min(dp(n-1)+abs(hlist[n]-hlist[n-1]), dp(n-2)+abs(hlist[n]-hlist[n-2]))

for i in range(N):
  cost[i] = dp(i)
print((cost[-1]))

# Optimized solution
N = int(eval(input()))
hlist = list(map(int, input().split()))
cost = [-1 for _ in range(N)]

def dp(n):
  if n==0: return 0
  if n==1: return abs(hlist[1] - hlist[0])
  else: return min(cost[n-1]+abs(hlist[n]-hlist[n-1]), cost[n-2]+abs(hlist[n]-hlist[n-2]))

for i in range(N):
  cost[i]=dp(i)
print((cost[-1]))
# Original solution
import math
import sys
sys.setrecursionlimit(100000000)

# N = 4
# HRR = [10, 30, 40, 20]
# # N = 2
# HRR = [10, 10]

N = int(eval(input()))
HRR = list(map(int,input().split()))
result = []


def calculate(pos, cost):
    if pos == N-1:
        result.append(int(cost))
        return

    if pos + 1 <= N - 1:
        calculate(pos + 1, cost + math.fabs(HRR[pos + 1] - HRR[pos]))

    if pos + 2 <= N - 1:
        calculate(pos + 2,cost + math.fabs(HRR[pos + 2] - HRR[pos]))


calculate(0, 0)
print((min(result)))

# Optimized solution
# N = 4
# HRR = [10, 30, 40, 20]
# N = 2
# HRR = [10, 10]

N = int(eval(input()))
HRR = list(map(int,input().split()))
result = []
for i in range(N):
    if i == 0:
        result.append(0)
    elif i == 1:
        s1 = result[i - 1] + abs(HRR[i] - HRR[i - 1])
        result.append(s1)
    else:
        s1 = result[i - 1] + abs(HRR[i] - HRR[i - 1])
        s2 = result[i - 2] + abs(HRR[i] - HRR[i - 2])
        result.append(min(s1, s2))

print((result[-1]))
# Original solution
# N = 4
# HRR = [10, 30, 40, 20]
# N = 2
# HRR = [10, 10]

N = int(eval(input()))
HRR = list(map(int,input().split()))
result = []
for i in range(N):
    if i == 0:
        result.append(0)
    elif i == 1:
        s1 = result[i - 1] + abs(HRR[i] - HRR[i - 1])
        result.append(s1)
    else:
        s1 = result[i - 1] + abs(HRR[i] - HRR[i - 1])
        s2 = result[i - 2] + abs(HRR[i] - HRR[i - 2])
        result.append(min(s1, s2))

print((result[-1]))


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


def calculate(n, hrr):

    result = []

    for index,value in enumerate(hrr):

        if index == 0:
            result.append(0)
        elif index == 1:
            result.append(abs(hrr[index]-hrr[index-1]) + result[index-1])
        else:
            s1 = abs(hrr[index] - hrr[index-1]) + result[index - 1]
            s2 = abs(hrr[index] - hrr[index-2]) + result[index - 2]
            result.append(min(s1,s2))

    print((result[-1]))

calculate(N,HRR)
# Original solution
import sys
sys.setrecursionlimit(10**6)
n = int(eval(input()))
h = list(map(int, input().split()))

memo = [-1] * n
def cost(i):
    if i == 0:
        return 0
    elif i == 1:
        return abs(h[i]-h[i-1])
    else:
        if memo[i-1] == -1:
            return min(cost(i-1)+abs(h[i-1]-h[i]), cost(i-2)+abs(h[i-2]-h[i]))
print((cost(n-1)))

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

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

dp = [INF] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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

print((dp[-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(N - 2): 
    dp1 = dp[i] + abs(h[i + 1] - h[i])
    dp[i + 1] = min(dp[i + 1], dp1)
    dp2 = dp[i] + abs(h[i + 2] - h[i])
    dp[i + 2] = min(dp[i + 2], dp2)
dp1 = dp[-2] + abs(h[-1] - h[-2])
dp[-1] = min(dp[-1], dp1)

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):
    if i == 1:
        dp[i] = abs(h[i] - h[i - 1])
    else:
        dp[i] = min(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[-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(N - 1):
    if i == N - 2:
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
    else:
        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[-1]))
# Original solution
import sys
sys.setrecursionlimit(1000000)
 
N = int(eval(input()))
h = list(map(int,input().split()))
 
N -= 1
 
def step(i):
  if i == 0:
    return 0
  elif i == 1:
    return abs(h[1]-h[0])
  elif step(i-1)+abs(h[i-1]-h[i]) <= step(i-2)+abs(h[i-2]-h[i]):
    return step(i-1) + abs(h[i-1]-h[i])
  else:
    return step(i-2) + abs(h[i-2]-h[i])
  
print((step(N)))



# Optimized 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-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))

print((dp[N-1]))