CodeEff/ECCO huggingface dataset:
# 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 から足場 i+1 へ移動する。コストは|h[i]−h[i+1]|
# 足場 i から足場 i+2 へと移動する コストは |h[i]−h[i+2]|
for i in range(n-1):
    dp[i + 1] = chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))
    # n-2の時は2つ先はない
    if i < n-2:
        dp[i + 2] = chmin(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()]

# dpの最小値を変更する関数
def chmin(a, b):
    if a > b:
        return b
    else:
        return a
      
dp=[1000000000]*N
dp[0]=0
#dp[1]=abs(h[1]-h[0])
 
#配るDP
for i in range(N-1):
    #print(abs(h[i]-h[i+1])+dp[i],dp[i+1],abs(h[i]-h[i+2])+dp[i],dp[i+2])
    dp[i+1]=chmin(abs(h[i]-h[i+1])+dp[i],dp[i+1])
    if i < N-2:
        dp[i+2]=chmin(abs(h[i]-h[i+2])+dp[i],dp[i+2])
    
print((dp[-1]))
# Original solution
n = int(eval(input()))
lst = [int(i) for i in input().split()]

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

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

print((dp[-1]))

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

dp = [1e7]*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]))
# 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
def main():
    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-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]))
    print((dp[-1]))
    
if __name__  == '__main__':
    main()
# Original solution
def chmin(a, b):
    if a > b:
        return b
    else:
        return a

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

# dp table
dp = [float('inf')]*(10**5 + 10)

# 初期条件
dp[0] = 0

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

# ans
print((dp[N-1]))

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

dp = [float('inf')]*(10**5 + 10)
dp[0] = 0

for i in range(1,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
import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 7)

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

def f(n):
    if n == 0:
        return 0
    elif n == 1:
        return abs(h[1] - h[0])
    return min(f(n-2) + abs(h[n] - h[n-2]), f(n-1) + abs(h[n] - h[n-1]))

print((f(n-1)))

# Optimized solution
import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 7)

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

@lru_cache(maxsize=2)
def f(n):
    if n == 0:
        return 0
    elif n == 1:
        return abs(h[1] - h[0])
    return min(f(n-2) + abs(h[n] - h[n-2]), f(n-1) + abs(h[n] - h[n-1]))

print((f(n-1)))
# Original solution
n = int(eval(input()))
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * (1 + 10 ** 5)
dp[0] = 0
for i in range(n):
    dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
    if i < 2:
        continue
    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 = [INF] * N
dp[0] = 0
for i in range(1, N):
    if i == 1:
        dp[i] = min(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)
print((dp[N - 1]))
# Original solution
import sys
sys.setrecursionlimit(500*500)

N =int(eval(input()))
H = list(map(int, input().split()))
H.append(0)
#総数Nで、N番目の添字はN-1

#メモ化再帰
#今の場所からゴールまでの最小コストを出す
now = 0
memo = [-1]*N
def func(n,memo):
  if n >= N:
    return 99999999
  if n == N-1:
    memo[N-1] = 0
    return 0
  else:
    if memo[n] != -1:
      return memo[n]
    else:
      min_later = min(func(n+1,memo)+abs(H[n+1]-H[n]), func(n+2,memo)+abs(H[n+2]-H[n]))
      memo[n] = min_later
    return min_later

print((func(now,memo)))

# Optimized solution
import sys
sys.setrecursionlimit(500*500)

N =int(eval(input())) 
H = list(map(int, input().split())) 
  
memo = [-1]*N 
def func(n,memo): 
  if n == 0: 
    memo[0] = 0 
    return memo[n] 
  elif n == 1: 
    memo[1] = abs(H[1]-H[0]) 
    return memo[n] 
  else: 
    if memo[n] != -1: 
      return memo[n] 
    else: 
      min_c = min(func(n-1,memo)+abs(H[n]-H[n-1]), func(n-2,memo)+abs(H[n]-H[n-2])) 
      memo[n] = min_c 
    return min_c 
  
print((func(N-1,memo)))
# Original solution
import sys

sys.setrecursionlimit(10 ** 6)

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

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


def rec(i):
    if i == 0:
        return 0
    if dp[i] < 100000000000:
        return dp[i]
    else:
        res = min(dp[i], rec(i - 1) + abs(h[i] - h[i - 1]))
        if i > 1:
            res = min(res, rec(i - 2) + abs(h[i] - h[i - 2]))
        dp[i] = res
        return res


print((rec(n - 1)))

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

# dp[i]で今までの計算結果を保存してる
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 > 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**7)

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

dp = [-1] * N # dp[i] := i から N-1 までの移動にかかる最小コスト
dp[N-1] = 0

def rec_memo(i):
    if dp[i] >= 0:
        return dp[i]
    
    if i == N-2:
        dp[i] = rec_memo(i+1) + abs(h[i+1] - h[i])
        return dp[i]
    else:
        dp[i] = min(rec_memo(i+1) + abs(h[i+1] - h[i]), rec_memo(i+2) + abs(h[i+2] - h[i]))
        return dp[i]

print((rec_memo(0)))

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

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

dp = [-1] * N # dp[i] := i から N-1 までの移動にかかる最小コスト
dp[N-1] = 0

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

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

# print(n, h, dp)

def chmin(arr, index_a, val):
  if arr[index_a] > val:
    arr[index_a] = val
    return True
  return False

def chmax(arr, index_a, val):
  if arr[index_a] < val:
    arr[index_a] = val
    return True
  return False

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

print((dp[n-1]))

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

#dp = [float("inf")] * (10**4 + 1)
dp = [10**9] * n

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

for i in range(2,n):
    #dp[i]
    # 1
    tmp1 = dp[i-1] + abs(h_L[i-1] - h_L[i])
    #dp[i] = min(dp[i],tmp1)
    # 2
    tmp2 = dp[i-2] + abs(h_L[i-2] - h_L[i])
    dp[i] = min(dp[i],tmp1,tmp2)
#print(dp)
print((dp[n-1]))

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

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

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

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

# 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 = list(map(int, input().split()))
dp = [float('inf')]*N
dp[0] = 0
for i in range(1, N):
    if i == 1:
        dp[i] = min(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[N-1]))
# Original solution


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    # dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
    N = read_int()
    h = read_ints()
    dp = [0, abs(h[1]-h[0])]
    for i in range(2, N):
        dp.append(min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]))
    return dp[-1]


if __name__ == '__main__':
    print((solve()))


# Optimized solution


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    # dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
    N = read_int()
    h = read_ints()
    a, b = 0, abs(h[1]-h[0])
    for i in range(2, N):
        b, a = min(abs(h[i]-h[i-1])+b, abs(h[i]-h[i-2])+a), b
    return b


if __name__ == '__main__':
    print((solve()))
# Original solution
n = int(eval(input()))
h = list(map(int, input().split()))
c = [0 for i in range(n)]
c[0] = 0
c[1] = abs(h[1] - h[0])
# c[2] = c[0] + abs(h[2]-h[0])
# c[2] = c[1] + abs(h[2]-h[1])
# c[3] = c[1] + abs(h[3]-h[1])
# c[3] = c[2] + abs(h[3]-h[1])
for i in range(2, n):
    c[i] = min(c[i-1]+abs(h[i]-h[i-1]), c[i-2]+abs(h[i]-h[i-2]))
print((c[-1]))


# Optimized solution

# n,k = map(int, input().split())
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])
# dp[2] = min((h[2] - h[1])+dp[1], (h[2]-h[0])+dp[0])
# dp[3] = min((h[3] - h[2])+dp[2], (h[3]-h[1])+dp[1])
print((dp[-1]))
# Original solution
# coding: utf-8

n = int(eval(input()))    # 2 <= n <= 10^5
h = list(map(int, input().rstrip().split()))
cost = lambda f, t: abs(h[t] - h[f])
# dp[j][i]
#   j 回目のジャンプでiにいるために必要な最低コストを格納
dp = [[float('inf')] * n for _ in range(n)]
for i in dp:
    i[0] = 0
for j in range(1, n):
    for i in range(1, n):
        dp[j][i] = min( \
            dp[j - 1][i], \
            float('inf') if i < 1 else \
                dp[j - 1][i - 1] + abs(h[i - 1] - h[i]), \
            float('inf') if i < 2 else \
                dp[j - 1][i - 2] + abs(h[i - 2] - h[i]))
print((dp[n - 1][n - 1]))


# Optimized solution
# coding: utf-8

n = int(eval(input()))    # 2 <= n <= 10^5
h = list(map(int, input().rstrip().split()))
dp = [0]
for i in range(1, n):
    dp.append(min( \
        dp[i - 1] + abs(h[i - 1] - h[i]), \
        float('inf') if i < 2 else dp[i - 2] + abs(h[i - 2] - h[i])))
print((dp[- 1]))
# Original solution

def main():
    n=int(eval(input()))
    h=list(map(int,input().split()))
    dp=[None]*n

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

if __name__=='__main__':
    main()


# Optimized solution

def main():
    n = int(eval(input()))
    h = list(map(int,input().split()))
    dp = [0] * (n + 1)
    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]))

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

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

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

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

print((dp[-1]))
# Original solution
n = int(eval(input()))
dp = [10 ** 9 for _ in range(n + 2)] # ちょっと大きめに
dp[0] = 0

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

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

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

dp = [10 ** 9 for _ in range(n+1)]
# スタート位置
dp[0] = 0

for i in range(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 = [10 ** 9 for _ in range(n+1)]
# スタート位置
dp[0] = 0

for i in range(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()))
h = [0] + h

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

for i in range(1, n+1):
  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]))
# Original solution
n = int(eval(input()))
H = [0] + list(map(int, input().split()))

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

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

#dp[i] = そこに辿り着くまでのコスト
#初期条件 dp[0] = 0, dp[1] = |h[1] - h[0]|, dp[2以上] = 10 ** 9 + 7
dp = [10**9+7] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
if n == 2:
    print((dp[1]))
else:
    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 = [int(i) for i in input().split()]

dp = [0,abs(h[1]-h[0])]
for i in range(2,n):
    dp.append(min(dp[-2] + abs(h[i] - h[i-2]),dp[-1] + abs(h[i] - h[i-1])))
print((dp[n-1]))
# Original solution

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

# memo = [0] + [abs(H[i] - H[i-1]) for i in range(1, N)]
# memo = [H[i] - H[i-1] for i in range(1, N)]
memo = [sum(H)] * (N+2)
memo[0] = 0
for i in range(N):
    memo[i+1] = min(memo[i+1], memo[i] + abs(H[i+1] - H[i]))
    if i > N-3:
        break
    memo[i+2] = min(memo[i+2], memo[i] + abs(H[i+2] - H[i]))

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


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

dp = [float('inf')] * N
dp[0] = 0
for i in range(N - 2):
    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]))
i = N - 2
dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
print((dp[N - 1]))


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

dp = [float('inf')] * N
dp[0] = 0
for i in range(N - 2):
    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]))
dp[N - 1] = min(dp[N - 1], dp[N - 2] + abs(h[N - 1] - h[N - 2]))
print((dp[N - 1]))
# 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[0]-h[1])
for i in range(2,N):
    dp1 = abs(h[i]-h[i-1])+dp[i-1]
    dp2 = abs(h[i]-h[i-2])+dp[i-2]
    dp[i] = min([dp1,dp2])
print((dp[N-1]))

# Optimized solution
def main():
    INF = 10**9
    N = int(eval(input()))
    h = list(map(int,input().split()))
    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]-h[i-2]))
    print((dp[N-1]))

if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
h = [0] + list(map(int, input().split()))
cost = {1:0,2: abs(h[2] - h[1])}
for i in range(1, n):
    cost[i + 1] = min(cost[i + 1], cost[i] + abs(h[i + 1] - h[i]))
    if i==n-1:break
    cost[i + 2] = cost[i] + abs(h[i + 2] - h[i])

print((cost[n]))


# Optimized solution
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [0] * n
dp[1] = abs(h[1] - h[0])
for i, (h, h1, h2) in enumerate(zip(h[2:], h[1:], h)):
    dp[i + 2] = min(dp[i + 1] + abs(h - h1), dp[i] + abs(h - h2))
print((dp[-1]))
# Original solution
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [float("inf") for i in range(n)]
dp[0] = 0
dp[1] = dp[0] + (h[1] - h[0])
for i in range(1, 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
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
sys.setrecursionlimit(1000000)
# do magic here
n = int(eval(input()))
heights = [int(x) for x in input().split()]

dp = [0 for x in range(n+1)]

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

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

print((dp[n-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=[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(1000000)
def solve(n,l,pos):
    ans=0
    if(pos==n):
        return 0
    if(pos==n-1):
        return abs(l[-1]-l[-2])
    ans+=min(abs(l[pos-1]-l[pos])+solve(n,l,pos+1),abs(l[pos-1]-l[pos+1])+solve(n,l,pos+2))
    return ans
n=int(eval(input()))
l=list(map(int,input().split()))
print((solve(n,l,1)))

# Optimized solution
import sys
sys.setrecursionlimit(1000000)
def solve(n,l,pos):
    if(pos==n):
        return 0
    if(pos==n-1):
        return abs(l[-1]-l[-2])
    if(t[pos]!=-1):
        return t[pos]
    t[pos]=min(abs(l[pos-1]-l[pos])+solve(n,l,pos+1),abs(l[pos-1]-l[pos+1])+solve(n,l,pos+2))
    return t[pos]
n=int(eval(input()))
l=list(map(int,input().split()))
global t
t=[-1]*(n+1)
print((solve(n,l,1)))
# Original solution
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import itertools
# import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *H = list(map(int, read().split()))
dp = [0] * N
dp[1] = abs(H[1] - H[0])

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

ans = dp[-1]
print(ans)


# Optimized solution
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import itertools
# import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *H = list(map(int, read().split()))
dp = [0] * N

for i in range(1, N):
    x = dp[i - 1] + abs(H[i] - H[i - 1])
    if i > 1:
        y = dp[i - 2] + abs(H[i] - H[i - 2])
        if x > y: 
            x = y
    dp[i] = x

ans = dp[-1]
print(ans)
# Original solution
def minjump(li , lir):
    #print(li,lir)
    if tuple(li) in list(lir.keys()):
        return lir[tuple(li)]
    else:
        if(len(li)<2):
            return 0 
        elif(len(li) == 2):
            lir[tuple(li)] = abs(li[0]-li[1])
            return lir[tuple(li)]   
        else:
            val1 = abs(li[0]-li[1])+minjump(li[1:],lir)
            val2 = abs(li[0]-li[2])+minjump(li[2:],lir)
            lir[tuple(li)] = min(val1,val2)
            #print(li,lir[tuple(li)])
            return lir[tuple(li)] 

t= int(eval(input()))
num = list(map(int,input().split()))
listi = dict()
print((minjump(num,listi)))


# Optimized solution
n  = int(eval(input()))
k = 2
num = list(map(int,input().split()))
numval = list()
for data in range(n):
    numval.append(1000000000)
numval[0] = 0
i = 0
if(n<k):
    k = n-1
for i in range(0,n):
    for data in range(1,k+1):
        if(i+data)>=n:
            break
        numval[i+data] = min(numval[i+data],numval[i]+abs(num[i]-num[i+data]))
    i += 1
print((numval[n-1]))
# Original solution
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(eval(input()))
H = list(map(int, input().split()))
d = [float('inf')]*N

if N <= 3:
    print((abs(H[0]-H[-1])))
else:
    d[0] = 0
    d[1] = abs(H[1]-H[0])
    d[2] = abs(H[2]-H[0])
    for i in range(3, N):
        d[i] = min(d[i-1]+abs(H[i]-H[i-1]), d[i-2]+abs(H[i]-H[i-2]))
    print((d[-1]))


# Optimized solution
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(eval(input()))
H = list(map(int, input().split()))
d = [float('inf')]*N


def solve():
    if N <= 3:
        print((abs(H[0]-H[-1])))
    else:
        d[0] = 0
        d[1] = abs(H[1]-H[0])
        d[2] = abs(H[2]-H[0])
        for i in range(3, N):
            d[i] = min(d[i-1]+abs(H[i]-H[i-1]), d[i-2]+abs(H[i]-H[i-2]))
        print((d[-1]))


def solve2():
    a = 0
    b = abs(H[1]-H[0])
    for i in range(2, N):
        a, b = b, min(abs(H[i]-H[i-1])+b, abs(H[i]-H[i-2])+a)
    print(b)


solve2()
# Original solution
N = int(eval(input()))
h = list(map(int, input().split()))
INF = 10 ** 9

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

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

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