CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [10 ** 9 + 7 for i in range(100010)]
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]))


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

dp = [INF] * (n+1) # 初期化
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
N = int(eval(input()))
h = list(map(int,input().split()))

dp = []

for i in range(N):
	dp.append(float("inf"))

for i in range(N):
	if i ==0:
		dp[i] = 0
	else:
		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 = []

for i in range(N):
	dp.append(float("inf"))
dp[0] = 0
for i in range(N):
	if not i+1 > N -1:
		dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]))
	if not i+2 > N -1:
		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()))
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-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()))

dp = [0] * N

for i in range(1,N):
    if i == 1:
        dp[i] = dp[i-1] + 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]))
# Original solution
import sys
sys.setrecursionlimit(10**6)
def rec(i):
    if i == 0:
        C[i] = 0
        return C[i]
    elif i == 1:
        C[i] = rec(i-1)+abs(H[i]-H[i-1])
        return C[i]
    # print(i, rec(i-1), rec(i-2))
    C[i] = min(rec(i-1)+abs(H[i]-H[i-1]), rec(i-2)+abs(H[i]-H[i-2]))
    return C[i]
INFTY = 10**13
N = int(eval(input()))
H = list(map(int, input().split()))
C = [INFTY for i in range(N)]
# C[0] = 0
# for i in range(N):
#     if i+1 < N:
#         C[i+1] = min(C[i] + abs(H[i+1]-H[i]), C[i+1])
#     if i+2 < N:
#         C[i+2] = min(C[i] + abs(H[i+2]-H[i]), C[i+2])
# print(C[-1])
print((rec(N-1)))


# Optimized solution
import sys
sys.setrecursionlimit(10**6)
def rec(i):
    if C[i] != INFTY:
        return C[i]
    if i == 0:
        C[i] = 0
        return C[i]
    elif i == 1:
        C[i] = rec(i-1)+abs(H[i]-H[i-1])
        return C[i]
    C[i] = min(rec(i-1)+abs(H[i]-H[i-1]), rec(i-2)+abs(H[i]-H[i-2]))
    return C[i]
    
INFTY = 10**13
N = int(eval(input()))
H = list(map(int, input().split()))
C = [INFTY for i in range(N)]
print((rec(N-1)))
# Original solution
n=int(eval(input()))
l=list(map(int, input().split()))
inf=10**12
dp=[inf]*n
dp[0]=0
dp[1]=abs(l[0]-l[1])
for i in range(n-2):
	dp[i+2]=min(dp[i]+abs(l[i+2]-l[i]),dp[i+1]+abs(l[i+2]-l[i+1]))
print((dp[-1]))

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

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

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

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

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

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

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

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




print((dp[N-1]))


# Optimized solution
N = int(eval(input()))
h = list(map(int, input().split()))
inf = 10**4 +1
dp = [inf]* 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-2] - h[i]))

print((dp[N-1]))
# Original solution
import sys
sys.setrecursionlimit(10**7)
N=int(sys.stdin.readline())
H=list(map(int,sys.stdin.readline().split()))

dp=[0]*N
def rec(i):
    if dp[i]:
        return dp[i]
    if i==N-1:
        return 0
    elif i==N-2:
        return abs(H[i]-H[i+1])

    o=min(rec(i+1)+abs(H[i]-H[i+1]),rec(i+2)+abs(H[i]-H[i+2]))
    dp[i]=o
    return o
print((rec(0)))


# Optimized solution
import sys
N=int(sys.stdin.readline())
H=list(map(int,sys.stdin.readline().split()))

dp=[0]*N

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

# Optimized solution
n = int(eval(input()))
l = list(map(int,input().split()))
cost = [float('inf')]*(n+1)
cost[0]= 0
cost[1]=abs(l[0]-l[1])
for i in range(n):
  if i==1:
  	cost[i]=abs(l[i-1]-l[i])
  if i>1:
  	cost[i]=min(cost[i],cost[i-2]+abs(l[i]-l[i-2]),cost[i-1]+abs(l[i]-l[i-1]))
print((cost[n-1]))
# Original solution
import sys
sys.setrecursionlimit(100000)
eval(input())
stones = tuple(map(int, input().split()))
 
tracker = {}
def min_cost(remaining_stones):
    if len(remaining_stones) == 1:
        return 0
    if len(remaining_stones) == 2:
        return abs(remaining_stones[0] - remaining_stones[1])
    
    jump_1 = remaining_stones[1:]
    if jump_1 not in tracker:
        tracker[jump_1] = min_cost(jump_1)
    jump_2 = remaining_stones[2:]
    if jump_2 not in tracker:
        tracker[jump_2] = min_cost(jump_2)
 
    score_1 = abs(remaining_stones[0] - remaining_stones[1]) + tracker[jump_1]
    score_2 = abs(remaining_stones[0] - remaining_stones[2]) + tracker[jump_2]
    return min(score_1, score_2)
 
 
print((min_cost(stones)))

# Optimized solution
import sys
sys.setrecursionlimit(100000)
n = int(eval(input()))
stones = list(map(int, input().split()))
stones.reverse()

bottum_up = [-1 for i in range(n)]
bottum_up[0] = 0
bottum_up[1] = abs(stones[0] - stones[1])

for i in range(2,len(stones)):
    score_1 = abs(stones[i] - stones[i-1]) + bottum_up[i-1]
    score_2 = abs(stones[i] - stones[i-2]) + bottum_up[i-2] 
    bottum_up[i] = min(score_1, score_2)

print((bottum_up[-1]))
# Original solution
N=int(eval(input()))
H=list(map(int,input().split()))
cost=0
t1,t2=0,0
A=[0]*(N)
i=1
while i<N:
  if i==1:
    A[i]=abs(H[i]-H[i-1])
    #print(i,A[i])
  elif i==2:
    t1=abs(H[i]-H[i-2])
    t2=abs(H[i]-H[i-1])+abs(H[i-2]-H[i-1])
    A[i]=min(t1,t2)
    #print(i,A[i],t1,t2)
  else:
    t1=abs(H[i]-H[i-1])+A[i-1]
    t2=abs(H[i]-H[i-2])+A[i-2]
    A[i]=min(t1,t2)
    #print(i,A[i],t1,t2)
  i=i+1
#print(A)
print((A[N-1]))

# 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((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=[int(i) for i in input().split()]
h.append(10000)
dp=[float('inf') for i in range(n+1)]
dp[0]=0
for i in range(n-1):
    dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]))
    if(i<n-2):
        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=[int(i) for i in input().split()]
h.append(10000)
dp=[float('inf') for i in range(n+1)]
dp[0]=0
for i in range(n-1):
    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]))
# Original solution
##https://atcoder.jp/contests/dp/tasks/dp_a

N = int(eval(input()))
##N, M = map(int, input().split())

H = list(map(int, input().split()))
F = [0]*N#それぞれに対する回答を格納する箇所
C = [0]*N#Nに飛ぶ時の最小コストの格納

F[0] = 1
F[1] = 1
C[0] = 0
C[1] = abs(H[0] - H[1])

for i in range(2, N):
    if C[i-2] + abs(H[i] - H[i-2]) > C[i-1] + abs(H[i] - H[i-1]):
        F[i] = F[i-1]
        C[i] = C[i-1] + abs(H[i] - H[i-1])
    elif C[i-2] + abs(H[i] - H[i-2]) < C[i-1] + abs(H[i] - H[i-1]):
        F[i] = F[i-2]
        C[i] = C[i-2] + abs(H[i] - H[i-2])
    else:
        F[i] = F[i-2] + F[i-1]
        C[i] = C[i-2] + abs(H[i] - H[i-2])        
print((C[N-1]))


# Optimized solution
##https://atcoder.jp/contests/dp/tasks/dp_a

N = int(eval(input()))
##N, M = map(int, input().split())

H = list(map(int, input().split()))
C = [0]*N#Nに飛ぶ時の最小コストの格納


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

for i in range(2, N):
    if C[i-2] + abs(H[i] - H[i-2]) > C[i-1] + abs(H[i] - H[i-1]):
        C[i] = C[i-1] + abs(H[i] - H[i-1])
    elif C[i-2] + abs(H[i] - H[i-2]) < C[i-1] + abs(H[i] - H[i-1]):
        C[i] = C[i-2] + abs(H[i] - H[i-2])
    else:
        C[i] = C[i-2] + abs(H[i] - H[i-2])        
print((C[N-1]))
# Original 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]))

# 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-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]))
print((dp[-1]))
# Original solution
N = int(eval(input()))
h = list(map(int , input().split()))
dp = [[-1]*10000 for i in range(N)]
import sys
sys.setrecursionlimit(10000000)
def dfs(i,c):
    if i == N:
        return 10000
    if dp[i][c] != -1:
        return dp[i][c]
    else:
        if i == N-1:
            return abs(h[i] - c)
        dp[i][c] = min(dfs(i+1, h[i])+abs(h[i]-c),dfs(i+2, h[i])+abs(h[i]-c))
        return dp[i][c]
print((dfs(0,h[0])))

# Optimized solution
N = int(eval(input()))
h = list(map(int , input().split()))
dp = [10**9+1]*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[N-1]))
# Original solution
n = int(eval(input()))
h = list(map(int, input().split()))
INF = 10**8
dp = [INF]*n
dp[0] = 0
for i in range(n-1):
    if i == 0:
        dp[i+1] = abs(h[i+1]-h[i])
    else:
        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]))


# Optimized solution
n = int(eval(input()))
h = list(map(int, input().split()))
INF = 10**8
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-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()))

dp = [[] for i in range(N)]
dp[0] = 0
dp[1] = abs(h[0]-h[1])

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

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

dp = [0]*n
dp[1] = abs(cost[1] - cost[0])

for i in range(2, n):
  be1 = abs(cost[i]-cost[i-1])
  be2 = abs(cost[i]-cost[i-2])
  dp[i] = min(dp[i-1]+be1, dp[i-2]+be2)
  
print((dp[-1]))
# Original solution
import sys
sys.setrecursionlimit(100000) 

n = int(eval(input()))
h = list(map(int,input().split()))
dp_ = [-1]*n

def dp(i):
    if dp_[i]!=-1:
        return dp_[i]
    if i == 0:
        dp_[i] = 0
    elif i == 1:
        dp_[i] = abs(h[1]-h[0])
    else:
        dp_[i] = min(dp(i-2)+abs(h[i]-h[i-2]),dp(i-1)+abs(h[i]-h[i-1]))
    return dp_[i]

print((dp(n-1)))

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

cost = [0]*n
for i in range(n):
    if i == 0:
        continue
    if i == 1:
        cost[i] = abs(h[i]-h[i-1])
        continue
    cost[i] = min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2]))
print((cost[n-1]))
# Original solution
import sys
sys.setrecursionlimit(10**6)
#import numpy as np
#N = map(int, input().split())
N = int(eval(input()))
h = list(map(int,input().split()))

# メモ化再帰
#memo = np.full(N, -1)
memo = [-1]*N
def func(i):
    if memo[i] != -1:
        return memo[i]
    if i == 0:
        return 0
    elif i == 1:
        return abs(h[1]-h[0])
    a = func(i-1) + abs(h[i]-h[i-1])
    b = func(i-2) + abs(h[i]-h[i-2])
    memo[i] = min(a,b)
    return min(a,b)
print((func(N-1)))

# pythonの問題はfuncの呼び出し回数
# 10^50に耐えられない
# sys.setrecursionlimit(10**6)で回避可能

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

memo = [-1]*N

memo[0] = 0
memo[1] = abs(h[1]-h[0])
for i in range(2,N):
    a = memo[i-1] + abs(h[i]-h[i-1])
    b = memo[i-2] + abs(h[i]-h[i-2])
    memo[i] = min(a,b)
print((memo[N-1]))
# Original solution
import sys
from functools import lru_cache

sys.setrecursionlimit(10**6)

INF = sys.maxsize

N = int(input().strip())
h = [int(x) for x in input().split()]

@lru_cache()
def solve(i):
  if i >= N - 1:
    return 0
  return min(    
    solve(i + 1) + abs(h[i] - h[i + 1]) if i + 1 < N else INF,
    solve(i + 2) + abs(h[i] - h[i + 2]) if i + 2 < N else INF
  )
  
print((solve(0)))

# Optimized solution
import sys

INF = sys.maxsize

N = int(input().strip())
h = [int(x) for x in input().split()]

memo = [INF] * N

for i in range(N - 1, -1, -1):
  if i == N -1:
    memo[i] = 0
  else:
    memo[i] = min(
      memo[i + 1] + abs(h[i] - h[i + 1]) if i + 1 < N else INF,
      memo[i + 2] + abs(h[i] - h[i + 2]) if i + 2 < N else INF                        
    )
  
print((memo[0]))
# Original solution

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

dp = [1e9] * 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 = [int(i) for i in 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]))
    if i > 0:
        dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print((dp[-1]))
# Original solution
# _*_ coding:utf-8 _*_
#  Atcoder_EducationDP_ContestX-1
#  TODO https://atcoder.jp/contests/dp/tasks/dp_a
#  参考文献 https://qiita.com/drken/items/dc53c683d6de8aeacf5a#%E8%A7%A3%E6%B3%95
#  C++ バージョンを上から書き下す
#  貰う型DP
import sys

# 初期化
# 足場の数となる要素数は足場の値の最大値であるMAX
blockMAXElement = 100010
blockElementRange = list(range(0,blockMAXElement,+1))
# DPテーブルの中身は今回は最小値を求めるため最大値を利用
dp = list()
for _ in blockElementRange:
	dp.append(sys.maxsize)

N = int(input().strip())
blockRange = list(range(0,N,+1))
h = list(map(int,input().strip().split(' ')))

# 初期の条件 0歩の時は値が与えられていないのでDPは0にセット
dp[0] = 0
for position in range(1,N,+1):
#   一つ手前の足場までで最適な値のはず、のコスト
	previousMinCost = dp[position-1]
#   一つ手前から来た場合の足場positionでのコスト計
#   pM = previousMin
	pMNowCost = dp[position-1]+abs(h[position]-h[position-1])
#   今の足場で設定されている足場へのコストより小さくなるならそれを改めて入れる
	if pMNowCost <= dp[position]:
		dp[position] = pMNowCost
#   これは二つ手前から来たケースを考えるのでpositon = 1の場合を除いて考える
#   それ以降は一個手前からと同じ
	if 1 < position:
		previous2MinCost = dp[position-2]
		pM2NowCost = dp[position-2]+abs(h[position]-h[position-2])
		if pM2NowCost <= dp[position]:
			dp[position] = pM2NowCost

print(("{}".format(dp[N-1])))


# Optimized solution
# _*_ coding:utf-8 _*_
#  Atcoder_EducationDP_ContestX-1_other1
#  TODO https://atcoder.jp/contests/dp/tasks/dp_a
#  参考文献 https://qiita.com/drken/items/dc53c683d6de8aeacf5a#%E8%A7%A3%E6%B3%95
#  C++ バージョンを上から書き下す
#  TODO　配る型DP https://qiita.com/drken/items/dc53c683d6de8aeacf5a#%E5%88%A5%E8%A7%A3-1-%E9%85%8D%E3%82%8B-dp
import sys

# 初期化
# 足場の数となる要素数は足場の値の最大値であるMAX
blockMAXElement = 100010
blockElementRange = list(range(0,blockMAXElement,+1))
# DPテーブルの中身は今回は最小値を求めるため最大値を利用

dp = [sys.maxsize] * blockMAXElement
# コスト
# 参考文献のC++では配列は宣言時に初期化されるがpythonはそれがないのでまずはあえて0で初期化
h = [0] * blockMAXElement

N = int(input().strip())
inputh = list(map(int,input().strip().split(' ')))
# h配列を入力データから取り出した物に置き換える
for i  in range(0,len(inputh),+1):
	h[i] = inputh[i]

# 初期の条件 0歩の時だけはコストがないので、0にセット
dp[0] = 0
# 現在の位置から最後の一歩手前(N-2歩き目)まで(仮にそこで2歩進んだ場合もDPテーブルはあるのでエラーにはならず)
for position in range(0,N-1,+1):
#   現在の岩場で最適な値のコスト
	nowMinCost = dp[position]
#   1歩進んだときのコスト計
	nextOneCost = nowMinCost+abs(h[position+1]-h[position])
#   一歩次の足場で設定されている足場へのコストより小さくなるならそれを改めて入れる
	if nextOneCost < dp[position+1]:
		dp[position+1]=nextOneCost
#   2歩足場をまたいだケースを考える。貰う場合と異なるのはpositionは0から始めて良いし
#   逆にN-2の石の足場から2歩飛んでもプログラム上ではエラーにならない
#   それ以降は1個手前からと同じ
	nextTwoCost = dp[position]+abs(h[position+2]-h[position])
	if nextTwoCost < dp[position+2]:
		dp[position+2] = nextTwoCost

print(("{}".format(dp[N-1])))
# Original 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] = abs(h[i]-h[0])
        continue
    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 = [float('inf')] * n
dp[0] = 0

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

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

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

dp = [float("inf")]*n #最小値求めるのでinfで初期化
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[-1]))

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

dp = [float("inf")]*n #最小値求めるのでinfで初期化
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]))
# Original solution
N = int(eval(input()))
H = list(map(int, input().split()))

dp = [0 for _ in range(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[N - 1]))


# Optimized 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[0] - H[i])
    else:
        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
inf = 10**9 + 7
n = int(eval(input()))
nodes = list(map(int, input().split()))
dp = [inf] * n

dp[0] = 0


for i in range(1, n):
    dp[i] = min(dp[i], dp[i-1]+abs(nodes[i]-nodes[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i-2]+abs(nodes[i]-nodes[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] = 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
import sys
sys.setrecursionlimit(100001)

N = int(eval(input()))
memo = [[-1]*(N-1) for i in range(N)]

def frog(h,h2,h1):
    if memo[h2][h1]  != -1:
        return memo[h2][h1]
    elif h1 <= 0:
        if memo[h2][0]  == -1:
            memo[h2][0] = abs(h[h2] - h[0])
        return memo[h2][0]
    else:
        memo[h2][h1] = min(frog(h,h1,h1-1)  + abs(h[h2]-h[h1]),frog(h,h1,h1-2)+abs(h[h2] - h[h1]))
        return memo[h2][h1]
    
   

s = input().split()

h = []
for i in range(N):
    h.append(int(s[i]))
print((min(frog(h,N-1,N-2),frog(h,N-1,N-3))))
#print(memo)

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

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

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

if n == 2:
    print((abs(costs[-1] - costs[-2])))
else:
    best = [float("inf") for i in range(n)]
    best[n - 1] = 0
    best[n - 2] =  abs(costs[n - 2] - costs[n - 1])

    for i in range(n - 3, -1, -1):
        best[i] = min(abs(costs[i] - costs[i + 1]) + best[i + 1], abs(costs[i] - costs[i + 2]) + best[i + 2]) 

    print((best[0]))



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

if n == 2:
    print((abs(costs[-1] - costs[-2])))
else:
    best = [abs(costs[n - 2] - costs[n - 1]), 0]

    for i in range(n - 3, -1, -1):
        current = min(abs(costs[i] - costs[i + 1]) + best[0], abs(costs[i] - costs[i + 2]) + best[1])
        best[0], best[1] = current, best[0] 

    print((best[0]))
# Original solution
import sys
sys.setrecursionlimit(1000000)
N = int(eval(input()))
h_list = list(map(int,input().split()))

costs = [None for _ in range(N)]

def func(stone_num):
    if stone_num == 0:
        return 0
    if stone_num == 1:
        return func(stone_num-1) + abs(h_list[stone_num-1] - h_list[stone_num])
    return min(
        func(stone_num-1) + abs(h_list[stone_num-1] - h_list[stone_num]),
        func(stone_num-2) + abs(h_list[stone_num-2] - h_list[stone_num])
    )

print((func(N-1)))

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

costs = [None for _ in range(N)]

for i in range(N):
    if i == 0:
        cost = 0
    elif i == 1:
        cost = costs[i-1] + abs(h_list[i-1] - h_list[i])
    else:
        cost = min(
            costs[i-1] + abs(h_list[i-1] - h_list[i]),
            costs[i-2] + abs(h_list[i-2] - h_list[i])
        )
    costs[i] = cost

print((costs[-1]))
# Original solution
def main():
    import sys
    input = sys.stdin.readline

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

    inf = float("inf")
    dp = [inf]*N

    dp[0] = 0
    step1, step2 = inf, inf

    for i in range(1, N):
        step1 = abs(H[i-1]-H[i]) + dp[i-1]
        if i >= 2:
            step2 = abs(H[i-2]-H[i]) + dp[i-2]
        step = min(step1, step2)

        dp[i] = min(dp[i], step)
    print((dp[-1]))


if __name__ == "__main__":
    main()


# Optimized solution
def main():
    import sys
    input = sys.stdin.readline

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

    inf = float("inf")
    dp = [inf]*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[-1]))


if __name__ == "__main__":
    main()