peterverebics/CodeNet_Python_118 huggingface dataset:
INF = 10e9

def frog(arr, n):
    dp = [INF]*n
    dp[0] = 0
    for i in range(n):
        for j in (i+1, i+2):
            if j < n:
                dp[j] = min(dp[j], dp[i] + abs(arr[i]-arr[j]))
    return(dp[-1])


if __name__ == '__main__':

    n = int(input())
    arr = [int(x) for x in input().split()]
    print(frog(arr, n))
import math

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

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

#初期値
dp[0] = 0

#Loop
for i in range(1, N):
    dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if i > 1:
        dp[i] = chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
print(dp[-1])
N = int( input() )
h = [int(x) for x in input().split()]

dp    = [0]*( len(h) )
dp[0] = 0
dp[1] = abs( h[0] - h[1] )
for ii in range( 2, len(dp) ):
    from_1 = abs(h[ii] - h[ii-1])
    from_2 = abs(h[ii] - h[ii-2])
    dp[ii] = min( dp[ii-1] + from_1, dp[ii-2] + from_2 )
    
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(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2])
print(dp[n-1])
n = int(input())

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

INF = 100100100100100
dp = [INF]*n

dp[0] = 0

for i in range(1,n):
    dp[i] = min(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
    if i > 1:
        dp[i] = min(dp[i],dp[i-2]+abs(h[i]-h[i-2]))
        
print(dp[n-1])
N = int(input())
h = list(map(int,input().split()))
ans = [0]*N
ans[1] = abs(h[1] - h[0])
for i in range(N - 2):
  p1 = ans[i] + abs(h[i] - h[i + 2])
  p2 = ans[i + 1] + abs(h[i+1] - h[i+2])
  ans[i + 2] = min([p1,p2])
print(ans[N-1])
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    h = [int(i) for i in input().split()]
    dp = [0] * N
    for i in range(1, N):
        if i < 2:
            dp[i] = 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[-1])

if __name__ == "__main__":
    main()
n = int(input())
h = list(map(int,input().split()))
dp = [0]*(n)
for i in range(n-1):
    if i == 0:
        dp[1] = abs(h[1]-h[0])
    else:
        dp[i+1] = min(abs(h[i+1] - h[i]) + dp[i],abs(h[i+1] - h[i-1]) + dp[i-1])
print(dp[-1])
N = int(input())
H = list(map(int, input().split()))
dp = [0 for n 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[N-1])
n = int(input())
L = list(map(int,input().split()))

inf = float("inf")
dp = [inf]*(n)
dp[0] = 0
dp[1] = abs(L[1] -L[0])
for i in range(n-2):
    dp[i+2] = min(dp[i+1] + abs(L[i+2] -L[i+1]) , dp[i] + abs(L[i+2] - L[i]))
    #print(dp)
print(dp[n-1])
f_inf = float('inf')
N = int(input())
h = list(map(int, input().split(' ')))
h.append(f_inf)
h.append(f_inf)
dp = [f_inf for _ in range(N + 100)]
dp[0] = 0
for i in range(N-1):
  dp[i+1] = min(dp[i] + abs(h[i+1] - h[i]), dp[i+1])
  dp[i+2] = min(dp[i] + abs(h[i+2] - h[i]), dp[i+2])
print(dp[N-1])
n = int(input())
h = list(map(int, input().split()))
dp = [0 for _ in range(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[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):
    two = abs(H[i]-H[i-2])
    one = abs(H[i]-H[i-1])
    if DP[i-2]+two <= DP[i-1]+one:
        DP[i] = DP[i-2]+two
    else:
        DP[i] = DP[i-1]+one

print(DP[-1])
# coding: utf-8
# Your code here!
import math
n=int(input())
h=list(map(int,input().split()))
dp=[math.inf for _ in range(n)]
dp[0]=0
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])
INF = float('inf')
N = int(input())
h = list(map(int, input().split()))

dp = [INF for i in range(N)]
dp[0] = 0
for i in range(N):
    if i - 1 >= 0:
        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])
import numpy as np

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

    return a

def chmax(a, b):
    a = a if a > b else b

    return a


N = int(input().strip())

h_point = []
temp = input().split()
for i in range(N):
    h_point.append(int(temp[i]))

costs = [0, abs(h_point[1]-h_point[0])]
for i in range(2, N):
    ans_temp = chmin(costs[i-1]+abs(h_point[i]-h_point[i-1]), costs[i-2]+abs(h_point[i]-h_point[i-2]))
    costs.append(ans_temp)

print(costs[N-1])
n = int(input())
h = list(map(int, input().split()))

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

print(sol[n-1])
def chmin(a, b):
    if a > b:
        return b
    return a

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

c_array = [0] * N
c_array[0] = 0
c_array[1] = abs(h_array[0] - h_array[1])

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

print(c_array[-1])
import sys
input = sys.stdin.readline

def main():
    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])
    
if __name__ == "__main__":
    main()
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] = dp[i-1] + abs(h[i]-h[i-1])
	dp[i] = min(dp[i],dp[i-2] + abs(h[i] - h[i-2]))
print (dp[n-1])
n=int(input())
H=list(map(int,input().split()))
dp=[10**9]*n
dp[0]=0
dp[1]=abs(H[1]-H[0])
for i in range(2,n):
    step1=dp[i-1]+abs(H[i]-H[i-1])
    step2=dp[i-2]+abs(H[i]-H[i-2])
    dp[i]=min(step1,step2)
print(dp[-1])
n = int(input())
h = list(map(int,input().split()))
inf = float("inf")
dp =[inf for i in range(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])
N = int(input())
H = list(map(int, input().split()))
P = [0, abs(H[0]-H[1])]
for i in range(1, N-1):
	P.append(min(P[i-1]+abs(H[i-1]-H[i+1]), P[i]+abs(H[i]-H[i+1])))
print(P[-1])
#!/usr/bin/env python3

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

    INF = 1 << 60

    dp = [INF] * 100010

    dp[0] = 0

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

    print(dp[N - 1])


if __name__ == "__main__":
    main()
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-2] - h[i]), dp[i-1] + abs(h[i-1] - h[i]))

print(dp[n-1])
N = int(input())
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0

def calc_cost(now, next):
  global h_list
  global dp
  global N
  if next > N - 1: return
  if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):
    dp[next] = dp[now] + abs(h_list[next] - h_list[now])

for i in range(N):
  calc_cost(i, i + 1)
  calc_cost(i, i + 2)

print(dp[N - 1])
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):
    p = abs(h[i] - h[i-2]) + dp[i-2]
    q = abs(h[i] - h[i-1]) + dp[i-1]
    if p <= q:
        dp[i] = p
    else:
        dp[i] = q

print(dp[-1])
n=int(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])
import sys
N=int(input())
A=[int(i) for i in input().split()]
if N==1:
    print(0)
    sys.exit()
dp=[0]*N
dp[0]=0
dp[1]=abs(A[0]-A[1])
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[-1])
n = int(input())
l = list(map(int,input().split()))

dp = [0 for i in range(n)]

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


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


print(dp[-1])
n=int(input())
ab=abs
hr=list(map(int,input().split()))
dp=[-1]*(n+1)
dp[0]=0
dp[1]=ab(hr[1]-hr[0])
for i in range(2,n):
	x=ab(hr[i]-hr[i-2])+dp[i-2]
	y=ab(hr[i]-hr[i-1])+dp[i-1]
	dp[i]=min(x,y)
print(dp[n-1])
N = int(input())
H = list(map(int, input().split()))

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

dp[0] = 0

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

print(dp[N-1])
N = int(input())
arr = list(map(int,input().rstrip().split()))
dparr= [-1 for i in range(N)]
dparr[0] = 0
dparr[1] = abs(arr[0]-arr[1])
for num in range(2,N):
  dparr[num] = min(dparr[num-2]+ abs(arr[num]-arr[num-2]), dparr[num-1]+ abs(arr[num]-arr[num-1]))
print(dparr[-1])
t = int(input())
a = list(map(int, input().split()))

if t == 1:
    print(0)
elif t == 2:
    print(abs(a[0] - a[1]))

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

    print(dp[t - 1])
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

N = gete(int)
h = geta(int)

INF = 1 << 60
dp = [INF] * N
dp[0], dp[1] = 0, 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 - 1] + abs(h[i] - h[i - 1]))

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

#sub problem: min cost from 0 to i
memo = []

for i, num in enumerate(H):
  if i == 0:
    memo.append(0)
  elif i == 1:
    memo.append(abs(num - H[i-1]))
  else:
    memo.append(min(abs(num - H[i-2])+ memo[i-2], abs(num - H[i-1]) + memo[i-1]) )
print(memo[-1])
n = int(input())
h = [int(i) for i in input().split()]
inf = 10**7
dp = [inf]*100005
dp[0] = 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])
n=int(input())
arr=list(map(int, input().split()))
INF=1e9+5

dp=[INF for i in range(n)]
dp[0]=0

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

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

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

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

INF = float("inf")
dp = [INF for _ in range(N + 1)]
dp[1] = 0

for i in range(2, N + 1):
    if i == 2:
        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])
def findmin(arr,n):
  dp = [0]*n
  dp[1] = abs(arr[0]-arr[1])
  for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(arr[i-1]-arr[i]), dp[i-2]+abs(arr[i-2]-arr[i]))
  return dp[-1]

n = int(input())
arr = list(map(int,input().split()))
print(findmin(arr,n))
N=int(input())
hlist=list(map(int,input().split()))
dp=[10*5]*N
dp[0]=0
dp[1]=abs(hlist[1]-hlist[0])

if N>2:
    for i in range (2,N):
        c1=abs(hlist[i]-hlist[i-2])+dp[i-2]
        c2=abs(hlist[i]-hlist[i-1])+dp[i-1]
        dp[i]=min(c1,c2)

print(dp[-1])
N = int(input())
[*h] = map(int, input().split())
dp = [float('inf') for _ in range(N)]
dp[0] = 0
dp[1] = abs(h[0]-h[1])
for i in range(2, N):
    dp[i] = dp[i-1]+abs(h[i]-h[i-1])
    dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2]))

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

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

if N > 3:
    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()))
cost = [10**9]*N
cost[0] = 0
cost[1] = abs(h[1]-h[0])
for i in range(2, N):
  cost[i] = min((abs(h[i-1] - h[i]) + cost[i-1]),cost[i])
  cost[i] = min((abs(h[i-2] - h[i]) + cost[i-2]), cost[i])
print(cost[-1])
n = int(input())
a = 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(a[i] - a[i-1]))
  if i > 1:
    dp[i] = min(dp[i], dp[i-2] + abs(a[i] - a[i-2]))

print(dp[-1])
n = int(input())
heights = [int(x) for x in input().split()]

dp = [float("inf")] * n
dp[0] = 0
for i in range(1, n):
    if i - 2 >= 0:
        val1 = abs(heights[i] - heights[i - 1]) + dp[i - 1]
        val2 = abs(heights[i] - heights[i - 2]) + dp[i - 2]
        dp[i] = min(val1, val2)
    else:
        dp[i] = abs(heights[i] - heights[i - 1]) + dp[i - 1]
print(dp[-1])
n = int(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])
import sys
INF = 10**18

if __name__ == "__main__":
    n = int(input())
    h = list(map(int,input().split()))
    dp = [INF]*(n)
    dp[0] = 0
    for i in range(1,n):
        d1 = abs(h[i] - h[i-1])
        d2 = INF
        if i>=2:
            d2 = abs(h[i] - h[i-2])
        dp[i] = min(d1+dp[i-1],d2+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()

dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
count = 1
for i in range(2,n):
  dp[i] = min(abs(h[i-1]-h[i])+dp[i-1], abs(h[i-2]-h[i])+dp[i-2])
print(dp[-1])
N  = int(input())
h =  list(map(int , input().split(' ')))
#N = 6
#h = [30,10,60 , 10, 60,50]

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

m=N-3

while m>=0:
    diff = 0
    index  = 0
    diff = min(abs(h[m]-h[m+2]) + dp[m+2]  ,  abs(h[m]-h[m+1])+dp[m+1])
    dp[m] = diff 
    m -=1
print(dp[m+1])
def frog1(h):
    dp = [float('inf')]*3
    dp[0] = 0
    for i in range(1,len(h)):
        dp[i%3] = min([dp[(i-j)%3] + abs(h[i]-h[i-j]) for j in range(1,3)])
    return dp[(len(h)-1)%3]
    
n = input()
vals = list(map(int, input().split()))

print(frog1(vals))
import sys
input=sys.stdin.readline
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()))
inf = 10**9
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
n = int(input())
l = list(map(int, input().split()))
dp = [sys.maxsize] *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(l[i]-l[j]))
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-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i]- h[i-1]))

print(dp)
import sys
n = int(sys.stdin.readline().strip('\n'))
h = list(map(int, sys.stdin.readline().strip('\n').split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0
for i in range(n-2):
  # 配るdp
  if i+1<=n-1: dp[i+1] = min(dp[i+1], dp[i] + abs(h[i]-h[i+1]))
  if i+2<=n-1: dp[i+2] = min(dp[i+2], dp[i] + abs(h[i]-h[i+2])) 
print(dp[n-1])
#DPまとめコンテストA問題より
infinity=10**6
N = int(input())
h = list(map(int,input().split()))

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

print(dp[N-1])
n = int(input())
h = list(map(int,input().split()))
dp = [10**4] * (n+1)
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-2] + abs(h[i-2] - h[i]), dp[i-1] + abs(h[i-1] - h[i]))
print(dp)
print(dp[n-1])
n=int(input())
h=list(map(int, input().split()))

dp=[10**5 for i in range(n)]
dp[0]=0
for i in range(n):
    if i+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+2]-h[i]))

print(dp[n-1])
n=int(input())
dp=[100000]*n
h=list(map(int,input().split()))
dp[0]=0
for i in range(n):
   for j in range(i+1,i+3):
       if j<n:
           dp[j]=min(dp[j],abs(h[i]-h[j])+dp[i])
print(dp[n-1])
def main():
    n = int(input())
    h = list(map(int, input().split()))
    # dpテーブル作成,スタート地点のdpテーブルの値は0にする
    dp =[10**5] * n
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])
    for i in range(2,n):
        dp[i] = min([dp[i], dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i])])
    print(dp[n-1])

if __name__ == "__main__":
    main()
n=int(input())
h=list(map(int,input().split()))
f=[0]+[10**5]*(n-1)
rage=range #lol
for i in rage(1,n):
    for j in range(i-2,i):
        if j>=0:
            f[i]=min(f[i],f[j]+abs(h[i]-h[j]))
print(f[-1])
INF = 10**6

N = int(input())
h = [int(i) for i in input().split()] + [0, 0]

dp = [INF] * 100010
dp[0] = 0

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

print(dp[N-1])
n = int(input())
H = list(map(int, input().split()))
inf = 10**10
cost = [None]*n
h1 = [None]*(n-1)
h2 = [None]*(n-2) 
one_ago = H[1]
two_ago = H[0]
h1[0] = abs(two_ago-one_ago)
for i in range(1, n-1):
    new = H[i]
    h1[i] = abs(one_ago-new)
    h2[i-1] = abs(two_ago-new)
    two_ago, one_ago = one_ago, new
cost[0], cost[1] = 0, h1[0]
for i in range(2, n):
    cost[i] = min(cost[i-2]+h2[i-2], cost[i-1]+h1[i-1])
print(cost[n-1])
"""
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
INF = 10 ** 9

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

for i in range(0, N-2):
    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())
if n == 0:
  print(n)
else:
  dano = 0
  frog = []
  a = input().split()
  for i in range(len(a)):
    frog.append(int(a[i]))
  a = len(frog)-1
  while a > 0:
    if a == 1:
      dano += abs(frog[1] - frog[0])
      a = 0
    else:
      if abs(frog[a] - frog[a-1]) < abs(frog[a] - frog[a-2]):
        dano += abs(frog[a] - frog[a-1])
        a -= 1
      else:
        dano += abs(frog[a] - frog[a-2])
        a -= 2
print(dano)
n = int(input())
a = list(map(int,input().split()))
cost = [0] * n
cost[1] = abs(a[1]-a[0])
for i in range(2,n):
    cost[i] = min(cost[i-1]+abs(a[i]-a[i-1]),cost[i-2]+abs(a[i]-a[i-2]))
print(cost)
print(cost[n-1])
import sys
sys.setrecursionlimit(200000)
 
n = int(input())
 
h = [int(i) for i in input().split()]
 
def dp(cost, p):
  if p == n-1:
    return cost
  if p < n-2:
    return min(dp(cost+abs(h[p]-h[p+1]), p+1), dp(cost+abs(h[p]-h[p+2]), p+2))
  if p == n-2:
    return dp(cost+abs(h[p]-h[p+1]), p+1)
N = int(input())
hs = list(map(int, input().split()))

Cost = [1e7 for _ in range(N)]
Cost[0] = 0

for i in range(N-2):
  if (i+1 > N-1):
    continue
  Cost[i+1] = min(Cost[i+1], Cost[i] + abs(hs[i]-hs[i+1]))
  if (i+2 > N-1):
    continue
  Cost[i+2] = min(Cost[i+2], Cost[i] + abs(hs[i]-hs[i+2]))

print(Cost[N-1])
N = int(input())
h = list(map(int,input().split()))
cost = [1000000]*(N+10)
cost[0] = 0
for i in range(1, N):
  cost[i] = min((abs(h[i-1] - h[i]) + cost[i-1]),cost[i])
  if i >= 2:
    cost[i] = min((abs(h[i-2] - h[i]) + cost[i-2]), cost[i])
print(cost[N-1])
# A - Frog1
import numpy as np

N = int(input())
h = list(map(int, input().split()))
dp = [10000]*(N+2)
dp[0] = 0

for i in range(N):
    if i+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+2]-h[i]))
print(dp[N-1])
N=int(input())
A=list(map(int,input().split()))
dp=[float("INF")]*(N+1)
dp[0]=0
for i in range(1,N):
  dp[i]=min(dp[i],abs(A[i]-A[i-1]))
print(dp[N-1])
N = int(input())
h = list(map(int,input().split()))
cost = [100000]*N

cost[0] = 0
for i in range(N-1): 
  num = cost[i] + abs(h[i+1]-h[i])
  if cost[i+1] > num:
    cost[i+1] = num
  if i > 0:
    num2 = cost[i-1] + abs(h[i+1]-h[i-1])
    if cost[i+1] > num2:
      cost[i+1] =  num2
      
print(cost[N-1])
N = int(input())
h = list(map(int, input().split(" ")))

dp = [1000000 for i in range(N)]
dp[0] = 0

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

print(dp[N-1])
n = int(input())
h = [int(x) for x in input().split()]
inf = float('inf')
dp = [inf] * n  # initialize dp
dp[0] = 0
for i in range(1, n):
    if i == 1:
        dp[i] = abs(h[i] - h[i-1])
    elif abs(dp[i-1] + h[i] - h[i-1]) < abs(dp[i-2] + h[i] - h[i-2]):
        dp[i] = dp[i-1] + abs(h[i] - h[i-1])
    else:
        dp[i] = dp[i-2] + abs(h[i] - h[i-2])
print(dp[-1])
n = int(input())
li = list(map(int,input().split()))

dp = [0]*n
dp[1] = abs(li[1]-li[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(li[i-1]-li[i]),dp[i-2]+abs(li[i]-li[i-2]))
print(dp)
n = int(input())
*A, = map(int, input().split())
DP = [[0 for j in range(n+1)] for i in range(n+1)]
for l in range(1, n+1):
    for i in range(n-l+1):
        j = i+l
        DP[i][j] = max(A[i]-DP[i+1][j], A[j-1]-DP[i][j-1])
print(DP[0][n])
N=int(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[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=int(input())
h=list(map(int,input().split()))
c=0
i=0
while i<n-1:
	if i+1==n-1:
		c+=abs(h[i+1]-h[i])
		i+=1
	elif abs(h[i+2]-h[i])<=abs(h[i+2]-h[i+1])-abs(h[i+1]-h[i]):
		c+=abs(h[i+2]-h[i])
		i+=2
	else:
		c+=abs(h[i+1]-h[i])
		i+=1
print(c)