peterverebics/CodeNet_Python_118 huggingface dataset:
n = int(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-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))
print(dp[-1])
N = int(input())
H = list(map(int, input().split()))

dp = [0]*N

for i, x in enumerate(H):
  if i == 0:
    continue
  elif i == 1:
    dp[i] = abs(H[i]-H[i-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[-1])
n = int(input())
h = list(map(int, input().split()))
dp = [10 ** 18 for _ in range(n)]

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

n = int(sys.stdin.readline())
inp = list(map(lambda x: int(x), sys.stdin.readline().split(" ")))


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

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

print(dp[-1])
import sys
n = int(input())
a = list(map(int, input().split()))

dp = [sys.maxsize]*n
dp[0] = 0
for i in range(n):
  for j in range(i+1, i+2+1):
    if(j<n):
      dp[j] = min(dp[j], dp[i]+abs(a[i]-a[j]))
print(dp[n-1])
n=int(input())
l=list(map(int,input().split()))
ans=[0,abs(l[1]-l[0])]
for i in range(2,n):
    ans.append(min(abs(l[i]-l[i-2])+ans[-2],abs(l[i]-l[i-1])+ans[-1]))
print(ans[-1])
N = int(input())
h = list(map(int, input().split()))

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

print(dp[N-1])
n = int(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, min(d1, d2)

print(b)
# -*- coding: utf-8 -*-
def main():
    n = int(input())
    h = list(map(int, input().split()))

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


if __name__ == "__main__":
    main()
import sys
import numpy as np
 
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
 
 
n=int(input())
h=list(map(int,input().split()))

dp=[0]*(n+1)

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


print(dp[n])
n=int(input())
h=list(map(int,input().split()))
cost=[0,abs(h[1]-h[0])]
for i in range(2,n):
  cost.append(min(cost[i-2]+abs(h[i]-h[i-2]),cost[i-1]+abs(h[i]-h[i-1])))
print(cost[n-1])
n = int(input())
arr = list(map(int,input().split()))
if n==2:
	print(abs(arr[0]-arr[1]))
elif n==3:
	x = abs(arr[0]-arr[2])
	y = abs(arr[0]-arr[1]+arr[1]-arr[2])
	print(min(x,y))
else:
	x = abs(arr[0]-arr[1])
	y = abs(arr[0]-arr[2])
	dp = [x,y]
	for i in range(3,n):
		x = dp[-1]+abs(arr[i]-arr[i-1])
		y = dp[-2]+abs(arr[i]-arr[i-2])
		dp.append(min(x,y))
	print(dp[-1])
n = int(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])
n=int(input())
h=list(map(int,input().split()))
dp=[1000000000]*(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[n-1])
import sys
input = sys.stdin.readline
n = int(input())
H = list(map(int,input().split()))

D = [float("inf") for i in range(n)]
D[0] = 0
for i in range(1, n):
    for j in range(1, 3):
        if i-j >= 0:
            D[i] = min(D[i], D[i-j]+abs(H[i]-H[i-j]))
    
print(D[-1])
def sol(lis):
    if len(lis)<=2:
        return abs(lis[0]-lis[1])
    costs = [0,abs(lis[0]-lis[1])]
    for i in range(2,len(lis)):
        x = abs(lis[i]-lis[i-1])
        y = abs(lis[i]-lis[i-2])
        costs.append(min(x+costs[-1],y+costs[-2]))
    return costs[-1]
input()
lis = list(map(int,input().split(' ')))
print(sol(lis))
N = int(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]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])
n=int(input())
l=list(map(int,input().split()))
sumlmin=[0]*n
sumlmin[1]=abs(l[1]-l[0])
for i in range(n-2):
    sumlmin[i+2]=min((sumlmin[i]+abs(l[i+2]-l[i])),(sumlmin[i+1]+abs(l[i+2]-l[i+1])))


print(sumlmin[n-1])
N = int(input())
A = list(map(int, input().split()))
dp = [0 for i in range(N)]
dp[0] = 0
dp[1] = abs(A[1]-A[0])
for i in range(2,N):
    dp[i] = min( abs(A[i]-A[i-2]) + dp[i-2] , abs(A[i]-A[i-1]) + dp[i-1])
print(dp[N-1])
import sys
sys.setrecursionlimit(200000)


N = int(input())
h = list(map(int, input().split()))
dp = [float('inf')] * N
dp[0] = 0


def rec(i):

    if dp[i] < float('inf'):
        return dp[i]

    a = rec(i-1) + abs(h[i] - h[i-1])
    if i > 1:
        a = min(a, rec(i-2) + abs(h[i] - h[i-2]))

    dp[i] = a
    return a


print(rec(N-1))
import numpy as np

n = int(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])
N = int(input())
h = list(map(int, input().split()))

"""
    dp[i]: カエルが足場 i にたどり着くまでの最小コスト
    i の一つ前は、 i-1 or i-2 にいる. dp[0] = 0.
"""

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])
n = int(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])
n = int(input())
k = list(map(int, input().split()))
dp = [0] * n
dp[1] = abs(k[1] - k[0])

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
h = na()

A = [0 for _ in range(n)]

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

print(A[-1])
n = int(input())
H = list(map(int, input().split()))
dp = [-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])
#!/usr/bin/env python3
import sys

def chmin(val: int, new: int):
    if new < val:
        return new
    else:
        return val

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

dp = [sys.maxsize] * N
dp[0] = 0
dp[1] = abs(H[1] - H[0])

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

print(dp[N-1])
n=int(input())
routes=list(map(int,input().split()))
dp=[float("inf") for i in range(n)]
dp[0]=0
for i in range(n):
    for j in range(i+1,i+3):
        if j<n:
            dp[j]=min(dp[j],dp[i]+abs(routes[i]-routes[j]))
print(dp[-1])
n=int(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])
N = int(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])
N = int(input())
h = [0] + list(map(int,input().split()))

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

for i in range(3,N+1):
    jump1 = dp[i-1] + abs(h[i]-h[i-1])
    jump2 = dp[i-2] + abs(h[i]-h[i-2])
    dp[i] = min(jump1,jump2)
    
print(dp[N])
N = int(input())
h_array = list(map(int, input().split()))

dp = [10 ** 5 for i in range(N)]

for i in range(N):
    if i == 0:
        dp[0] = 0
    elif i == 1:
        dp[1] = dp[0] + abs(h_array[1] - h_array[0])
    else:
        dp[i] = min(dp[i - 1] + abs(h_array[i] - h_array[i - 1]), dp[i - 2] + abs(h_array[i] - h_array[i - 2]))
print(dp[N - 1])
N = int(input())
H = list(map(int, input().split()))

inf = float('inf')
dp = [inf] * (N + 1)
dp[1] = 0

for i in range(1, N):
    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 + 1] - H[i - 1]))

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

print(dp[-1])
n=int(input())
l=list(map(int,input().split()))
final=[0]*n
for i in range(1,n):
  if i==1:
    final[i]=abs(l[i]-l[i-1])
  else:
    final[i]=min(final[i-1]+abs(l[i]-l[i-1]),final[i-2]+abs(l[i]-l[i-2]))
print(final[-1])
import numpy as np

n = map(int, input())
h_list = [int(i) for i in input().split()]
h_list = np.array(h_list)

dp = np.zeros((len(h_list)))
dp[1] = np.abs(h_list[1]-h_list[0])

for i in range(2,len(h_list)):
    temp1 = dp[i-1] + np.abs(h_list[i] - h_list[i-1])
    temp2 = dp[i-2] + np.abs(h_list[i] - h_list[i-2])
    dp[i] = min(temp1, temp2)
    
    
print(int(dp[-1]))
"""dpまじでわからん"""
'''
Created on 2020/08/29

@author: harurun
'''
import sys
N=int(sys.stdin.readline())
h=list(map(int,sys.stdin.readline().split()))
dp=[0]*N

for i in range(1,N):
  if i>=2:
    dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]))
  else:
    dp[i]=dp[i-1]+abs(h[i-1]-h[i])
print(dp[N-1])
# print(dp)
n = int(input())
l = list(map(int, input().split()))
l1 = [0]*n
l1[1] = abs(l[0] - l[1])
for i in range(2, n):
    l1[i] = min(l1[i - 2] + abs(l[i] - l[i - 2]), l1[i - 1] + abs(l[i] - l[i - 1]))
print(l1[n - 1])
n=int(input())
if n==1:
  print(0)
  exit()
h=list(map(int,input().split()))
c=[-1]*n
c[0]=0
c[1]=abs(h[1]-h[0])
for i in range(2,n):
  c[i]=min(c[i-2]+abs(h[i]-h[i-2]),c[i-1]+abs(h[i]-h[i-1]))
print(c[n-1])
N = int(input())
h = list(map(int,input().split()))
A = [float('inf')] * (N)
A[0] = 0
A[1] = abs(h[1]-h[0])

if N > 2:
    for i in range(2,N):
        p = A[i-1] + abs(h[i-1] - h[i])
        q = A[i-2] + abs(h[i-2] - h[i])
        if  p < A[i]:
            A[i] = p
        if q < A[i]:
            A[i] = q
    print(A[N-1])

else:
    print(abs(h[1]-h[0]))
n=int(input())
h=list(map(int,input().split()))
c=[0]*n
c[1]=abs(h[1]-h[0])
i=2
while i<n:
	c[i]=min(c[i-2]+abs(h[i-2]-h[i]),c[i-1]+abs(h[i-1]-h[i]))
	i+=1
print(c[n-1])
N = int(input())
h = list(map(int,input().split()))
dp = [0] * 110000
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])
N=int(input())
h=list(map(int, input().split()))

min_cost = [0]*N
min_cost[0] = 0
min_cost[1] = abs(h[1]-h[0])
for idx in range(2, N):
    min_cost[idx] = min(min_cost[idx-1]+abs(h[idx]-h[idx-1]), \
                        min_cost[idx-2]+abs(h[idx]-h[idx-2]))
print(min_cost[-1])
n=int(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[n-1])
from sys  import stdin,stdout

st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")

mod=1000000007
INF=float('inf')

n=inp()
l=li()
dp=[0 for i in range(n)]
dp[1]=abs(l[1]-l[0])

for i in range(2,n):
    dp[i]=min(dp[i-2]+abs(l[i]-l[i-2]),abs(l[i]-l[i-1])+dp[i-1])
print(dp[-1])
n = int(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-1]+abs(h[i] - h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])
N = int(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])
n = int(input())
a = list(map(int,input().split()))
dp = [0 for i in range(n)]
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-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]))

print(dp[-1])
N = int(input())
A = list(map(int, input().split()))

INF = 10**9
dp = [INF]*N

def chmin(val1, val2):
    if val1 < val2:
        return val1
    else:
        return val2
        
for i in range(len(A)):
    if i == 0:
        dp[0] = 0
    elif i == 1:
        dp[1] = abs(A[1]-A[0])
    else:
        dp[i] = chmin(dp[i-1]+abs(A[i]-A[i-1]), dp[i-2]+abs(A[i]-A[i-2]))

print(dp[N-1])
n = int(input())
H = list(map(int, input().split()))
DP = [0 for i in range(n)]

DP[0] = 0
DP[1] = abs(H[1] - H[0])
for i in range(2, n):
    a = DP[i - 2] + abs(H[i] - H[i - 2])
    b = DP[i - 1] + abs(H[i] - H[i - 1])
    if a <= b:
        DP[i] = a
    else:
        DP[i] = b
print(DP[n - 1])
n = int(input())
h = list(map(int, input().split()))

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

for i in range(2,n):
    memo[i] += min(abs(h[i]-h[i-1])+memo[i-1],\
                    abs(h[i]-h[i-2])+memo[i-2])
print(memo[-1])
n = int(input())
h = list(map(int,input().split()))

INF = 10 ** 20

dp = [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[n-1])
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np

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

dp = np.zeros(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(int(dp[N-1]))
n = int(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)
n = int(input())
l = list(map(int,input().split()))
dp = [0]*n
dp[1] = abs(l[1]-l[0])
for i in range(2,n):
    dp[i] = min(dp[i-2]+abs(l[i-2]-l[i]),dp[i-1]+abs(l[i-1]-l[i]))
print(dp[n-1])
N = int(input())
step = list(map(int, input().split()))
dp = [float('inf')] * N
dp[0] = 0
dp[1] = abs(step[0] - step[1])
for i, s in enumerate(step):
  if i < 2:
    continue
  dp[i] = min(dp[i - 2] + abs(step[i - 2] - step[i]), dp[i - 1] + abs(step[i - 1] - step[i]))
print(dp[N - 1])
import numpy as np
N = int(input())
h = list(map(int, input().split()))

dp = np.full(N, np.inf)
dp[0] = 0
for i in range(1,N):
  dp[i] = min(dp[i],dp[i-1]+np.abs(h[i] - h[i-1]))
  if i > 1: dp[i] = min(dp[i],dp[i-2]+np.abs(h[i] - h[i-2]))
print(int(dp[-1]))
n = int(input())
h = list(map(int, input().split()))

dp = [0] * len(h)
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])
N = int(input())
h = [int(x) for x in input().split()]

dp = [1000000 for _ in range(N)]
dp[0] = 0
dp[1] = 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] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))
print(dp[-1])
n = int(input())
cost = list(map(int, input().split(" ")))

dp = [None for i in range(n)]
dp[0] = 0
dp[1] = abs(cost[1] - cost[0])


for i in range(2, n):
     one_step_cost = abs(cost[i] - cost[i-1]) + dp[i-1]
     two_step_cost = abs(cost[i] - cost[i-2]) + dp[i-2]
     best_cost = min([one_step_cost, two_step_cost])
     dp[i] = best_cost


print(dp[n-1])
N = int(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])
N = int(input())
X = list(map(int,input().split()))

dp = [0,abs(X[1] - X[0])]
for x in range(2,N):
  dp.append(min(dp[x-1] + abs(X[x-1]-X[x]),
                dp[x-2] + abs(X[x-2]-X[x])
               )
           )
print(dp[N-1])
N = int(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])
n = int(input())
h = list(map(int, input().split()))

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

for i in range(2, n):
    dp.append(min(abs(h[i]-h[i-1])+dp[-1], abs(h[i]-h[i-2])+dp[-2]))
print(dp[-1])
k=int(input())
a=list(map(int,input().split()))
if k==1:
    print(0)
else:
    dp = [0] * k
    dp[1] = abs(a[0]-a[1])
    for i in range(2,k):
        dp[i]=min(
            dp[i-1]+abs(a[i]-a[i-1]),
            dp[i-2]+abs(a[i]-a[i-2])
        )
    print(dp[-1])
def cost(a, b):
    tmp = a - b
    if tmp < 0:
        tmp = -1*tmp
    return tmp

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

min_cost = [0]*N
min_cost[0] = 0
min_cost[1] = cost(h[0], h[1])


for i in range(2, N):
    min_cost[i] = min(min_cost[i - 2]+cost(h[i-2], h[i]), min_cost[i-1]+cost(h[i-1], h[i]))

print(min_cost[-1])
#DP-A
n=int(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])
n=int(input())
z=list(map(int,input().split()))
ans=[0,abs(z[1]-z[0])]

for i in range(2,len(z)):
    ans.append(min(abs(z[i]-z[i-1])+ans[-1],abs(z[i]-z[i-2])+ans[-2]))
print(ans[-1])
def main():
    n = int(input())
    hs = list(map(int, input().split()))

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

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

    print(dp[-1])


if __name__ == "__main__":
    main()
n=int(input())
h=list(map(int, input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])

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

print(dp[n-1])
n = int(input())
h = list(map(int, 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[-1])
n = int(input())
h = [int(i) for i in input().split()]

dp = [0, abs(h[1] - h[0])] + [-1 for i in range(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[-1])
# -*- coding: utf-8 -*-

N = int(input().strip())
h_list = list(map(int, input().rstrip().split()))
#-----

cost = [0]*N
cost[1] = abs(h_list[1] - h_list[0])

for i in range(2,N):
  cost1 = cost[i-1] + abs(h_list[i] - h_list[i-1])
  cost2 = cost[i-2] + abs(h_list[i] - h_list[i-2])
  cost[i] = min( cost1, cost2 )

print(cost[-1])
N = int(input())
h_list = list(map(int, input().split()))

dp = [0] * (N)
for i in range(1, N):
    h1 = abs(h_list[i] - h_list[i-1])
    h2 = abs(h_list[i] - h_list[i-2]) if i >= 2 else 10**9
    dp[i] = min(dp[i-1] + h1, dp[i-2] + h2)

print(dp[-1])
n = int(input())
h = list(map(int,input().split()))
cost = [1000000 for i in range(n)]
cost[0] = 0
for i in range(1,n):
    if i-1>=0 and i-2>=0:
        cost[i] = min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2]))
    elif i-2<=0 and i-1>=0:
        cost[i] = cost[i-1]+abs(h[i]-h[i-1])
    else:
        print("Error")
print(cost[n-1])
import sys
def mincost(n,h):
    dp=[-1 for i in range(n)]
    dp[n-1]=0
    dp[n-2]=abs(h[n-2]-h[n-1])
    for i in range(n-3,-1,-1):
        dp[i]=min(dp[i+1]+abs(h[i+1]-h[i]),dp[i+2]+abs(h[i+2]-h[i]))
    return dp[0]    

n=int(input())
h=[int(x) for x in input().split()]
print(mincost(n,h))
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
h = LI()
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-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])
N=int(input())
h_array=input().split()
dp=[0]*N


dp[0]=0
dp[1]=abs(int(h_array[0])-int(h_array[1]))
for  n in range(2,N):
    dp[n] =min(abs(int(h_array[n])-int(h_array[n-1]))+dp[n-1],abs(int(h_array[n])-int(h_array[n-2]))+dp[n-2])
print(dp[-1])
n=int(input())
h=list(map(int,input().split()))
#dp[i]はiに来たときのコストの総和の最小値

dp=[float('inf')]*n
dp[0]=0
dp[1]=abs(h[0]-h[1])+dp[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])
n = int(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])
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
def dis(a,b):
    return abs(h[a]-h[b])
dp[1]=dis(1,0)
for i in range(2,n):
    dp[i]=min(dp[i-1]+dis(i,i-1),dp[i-2]+dis(i,i-2))
print(dp[-1])
N = int(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])
n=int(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[-1])
N = int(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])
def min_cost():
    # Translation of Errichto's solution
    len_costs = input()
    costs = input().split(' ')
    costs = list(map(int, costs))
    dp = [float('inf') for i in range(len(costs))]
    dp[0] = 0
    for i in range(len(costs)):
        for j in [i + 1, i + 2]:
            if j < len(costs):
                dp[j] = min(dp[j], dp[i] + abs(costs[i] - costs[j]))
    print(dp[-1])

min_cost()
# min_cost([10, 30, 40, 20])
# min_cost([10, 10])
# min_cost([30, 10, 60, 10, 60, 50])
n=int(input())
arr=list(map(int, input().split()))
cost=[0 for _ in range(n+1)]
cost[2]=abs(arr[1]-arr[0])
for stone in range(3, n+1):
    cost[stone]=min(cost[stone-1]+abs(arr[stone-1]-arr[stone-2]), cost[stone-2]+abs(arr[stone-1]-arr[stone-3]))
print(cost[n])
a=int(input())
b=list(map(int,input().split()))

c=[0,abs(b[0]-b[1])]
for i in range(2,a):
  d=min(c[i-2]+abs(b[i-2]-b[i]),c[i-1]+abs(b[i-1]-b[i]))
  c.append(d)
print(c[a-1])
"""
dp[i] : 足場iに到達するにあたって、たどり着く最小回数
"""
INF = 10**10
dp = [INF]*110000
N = int(input())
hs  = list(map(int, input().split())) + [INF,INF]
dp[0] = 0
for i in range(N):
    dp[i+1] = min(dp[i+1], dp[i]+abs(hs[i+1]-hs[i]))
    dp[i+2] = min(dp[i+2], dp[i]+abs(hs[i+2]-hs[i]))
print(dp[N-1])
N = int(input())
H = list(map(int,input().split()))
DP = [0]
for i in range(1,N):
    a = DP[i-1] + abs(H[i]-H[i-1])
    b = DP[i-2] + abs(H[i]-H[i-2]) if i>1 else float("inf")
    DP.append(min(a,b))
print(DP[N-1])
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
rage=range #lol
for i in rage(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])
def main():
  n = int(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()
N = int(input())
h = [0] * (2*N)
h[:N] = list(map(int, input().split()))
INF = 10**9
dp = [INF] * (2*N)
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])
n = int(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])
N = int(input())
h = list(map(int, input().split()))

dp = [float('inf') for _ in range(N)]
dp[0] = 0

for i in range(N):
    if i - 1 >= 0:
        if dp[i - 1] + abs(h[i] - h[i - 1]) < dp[i]:
            dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])
    if i - 2 >= 0:
        if dp[i - 2] + abs(h[i] - h[i - 2]) < dp[i]:
            dp[i] = dp[i - 2] + abs(h[i] - h[i - 2])
print(dp[N-1])