peterverebics/CodeNet_Python_118 huggingface dataset:
N = int(input())
H = list(map(int, input().split()))
points = [0]*N
points[1] = abs(H[1]-H[0])
for i in range(2,N):
    points[i] = min(points[i-2]+abs(H[i-2]-H[i]), points[i-1]+abs(H[i-1]-H[i]))
print(points[-1])
# A - Frog 1
def main():
    N, *H = map(int, open(0).read().split())
    H = [0] + H + [0, 0]
    dp = [1 << 30] * (N + 3)
    dp[1] = 0
    for i, a in enumerate(H[1:N + 1], 1):
        for j, b in enumerate(H[i + 1:i + 3], i + 1):
            dp[j] = min(dp[j], dp[i] + abs(a - b))
    print(dp[N])


if __name__ == "__main__":
    main()
def ch_min(a, b):
    if (a > b):
        a = b
    return a


if __name__ == "__main__":
    N = int(input())
    h = list(map(int, input().split()))
    INF = 10 ** 10
    dp = [INF] * 100010
    dp[0] = 0
    for i in range(N - 1):
        dp[i + 1] = ch_min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))
        if (i < N - 2):
            dp[i + 2] = ch_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] * 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])
def aminch(dp, pot, dp_1, pot_1): # Absolute MINimum CHanging
	return min(dp, abs(pot-pot_1)+dp_1)

N = int(input())
h = tuple(map(int, input().split()))
dp = [float("INF")]*N
dp[0], dp[1] = 0, abs(h[0]-h[1])

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

print(dp[-1])
n = int(input())
h = list(map(int, input().split()))
INF = 10 ** 18

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

for i, (e1, e2, e3) in enumerate(zip(h, h[1:], h[2:]), 2):
    dp[i] = min(dp[i], dp[i-1] + abs(e3 - e2), dp[i-2] + abs(e3 - e1))

ans = dp[-1]
print(ans)
n = int(input())
lst1 = list(map(int,input().split()))

dp = [0]*n

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

for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(lst1[i]-lst1[i-1]),dp[i-2]+abs(lst1[i]-lst1[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(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())
HS = [int(i) for i in input().split()]

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

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

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

print(dp[N-1])
def solve(N,h):
    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]))
    return dp[N-1]

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

dp= [0]*N

for i in range(N):
  if i == 0:
    continue
  if i == 1:
    dp[1] = abs(h[0] - h[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])
size = int(input())
arr = list(map(int, input().split()))
dp = [0]*(size)
dp[0] = 0
dp[1] = abs(arr[1] - arr[0])
for i in range(2,size):
    dp[i] = min(dp[i-1] + abs(arr[i-1]-arr[i]), dp[i-2] + abs(arr[i-2]- arr[i]))

print(dp[size-1])
N = int(input())
H = list(map(int, input().split()))
H = [0] + H
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-2] + abs(H[i-2] - H[i]), dp[i-1] + abs(H[i-1] - H[i]))

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

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

dp = [0] * n

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


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

print(dp[n-1])
n = int(input())
lis = list(map(int, input().split()))
dp = [0 for _ in range(n)]
for i,d in enumerate(dp):
    if i == 0:
        continue
    if i == 1:
        dp[1] = abs(lis[1]-lis[0])
        continue
    dp[i] = min((dp[i-2]+abs(lis[i-2]-lis[i])),(dp[i-1]+abs(lis[i-1]-lis[i])))
#print(dp)
print(dp[-1])
n=int(input())
arr=list(map(int,input().split()))
dp=[0]*len(arr)
dp[0]=0
dp[1]=abs(arr[1]-arr[0])
for i in range(2,len(arr)):
    dp[i]=min((dp[i-1]+abs(arr[i-1]-arr[i])),(dp[i-2]+abs(arr[i-2]-arr[i])))
print(dp[len(arr)-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):
    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()))
L = [0]*N
L[1]=abs(H[1]-H[0])
for i in range(2, N):
  L[i] = min(L[i-1]+abs(H[i]-H[i-1]), L[i-2]+abs(H[i]-H[i-2]))
print(L[-1])
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):
    one = abs(h[i] - h[i-1]) + dp[i-1]
    two = abs(h[i] - h[i-2]) + dp[i-2]
    dp[i] = min(one, two)
print(dp[n-1])
n = int(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] = abs(h[i - 1]- h[i])
    else:
        dp[i] = min(abs(h[i]-h[i-2]) + dp[i-2], abs(h[i]-h[i-1]) + dp[i-1])
print(dp[-1])
n = int(input())
H = [0]+list(map(int,input().split()))

if n >= 3:
    dp = [0]*(n+1)
    dp[2] = abs(H[2]-H[1])
    dp[3] = min(abs(H[3]-H[2])+dp[2], abs(H[3]-H[1]))
    for i in range(4,n+1):
        dp[i] = min(abs(H[i]-H[i-1])+dp[i-1], abs(H[i]-H[i-2])+dp[i-2])
    print(dp[n])
else:
    print(abs(H[2]-H[1]))
n = int(input())
h = tuple(map(int, input().split()))

INF = float('inf')
dp = [INF] * n
dp[0] = 0
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

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())
H = list(map(int, input().split()))
B = [0]*N
B[1]=abs(H[1]-H[0])
for i in range(2, N):
    B[i] = min(B[i-2]+abs(H[i]-H[i-2]), B[i-1]+abs(H[i]-H[i-1]))
print(B[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])
def main():
    n, height = getInputs()

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

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

    print(cost[-1])

def getInputs():
    return int(input()), tuple(map(lambda x: int(x), input().split()))

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

dp = [-1] * N
for x in range(N):
    if x == 0:
        dp[0] = 0
    elif x == 1:
        dp[1] = abs(h[1] - h[0])
    else:
        dp[x] = min(abs(h[x] - h[x - 1]) + dp[x - 1],
                    abs(h[x] - h[x - 2]) + dp[x - 2])
print(dp[N - 1])
N = int(input())
H = list(map(int, input().split()))
INF = 10000000000
dp = [INF] * N
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 - 3:
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]))

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

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

print(dp[n - 1])
N=int(input())
dp=[float('inf') for i in range(N+1)]
l=[int(x) for x in input().rstrip().split()]
dp[0]=0
dp
for i in range(1,N):
    if i==1:
        dp[i]=dp[i-1]+abs(l[i]-l[i-1])
    else:
        dp[i]=min(dp[i-1]+abs(l[i]-l[i-1]),dp[i-2]+abs(l[i]-l[i-2]))

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

minlist = [0]*N
minlist[0] = 0
minlist[1] = abs(H[1] - H[0])
for i in range(2,N):
    minlist[i] = min(minlist[i-2] + abs(H[i-2] - H[i]), minlist[i-1] + abs(H[i-1] - H[i]))

print(minlist[N-1])
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
H = [int(x) for x in input().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)
N = int(input())
list = [int(i) for i in input().split(" ")]

def cost(N):
    dp = [0] * N
    dp[0] = 0
    dp[1] = abs(list[1]-list[0])
    for i in range(2,N):
        dp[i] = min([dp[i-1]+abs(list[i-1]-list[i]),dp[i-2]+abs(list[i-2]-list[i])])
    return dp[N-1]

print(cost(N))
def chmin(DP,b,i):
    if (DP[i]> b):
        DP[i] = b
        return True
    return False
N = int(input())
H = [i for i in map(int,input().split())]
dp = [10**10 for i in range(N)]
dp[0] = 0
for i in range(1,N):
    chmin(dp,dp[i-1]+abs(H[i]-H[i-1]),i)
    if i > 1:
        chmin(dp,dp[i-2]+abs(H[i]-H[i-2]),i)
print(dp[-1])
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
sys.setrecursionlimit(1000000)
# do magic here
n = int(input())
heights = [int(x) for x in input().split()]

MAX = 10000000

dp = {}


def solve(x):
    if x==0:
        return 0
    if x < 0:
        return MAX
    if x in dp:
        return dp[x]
    a = abs(heights[x-1] - heights[x]) + solve(x-1)
    b = abs(heights[x-2] - heights[x]) + solve(x-2)
    dp[x] = min(a,b)
    return dp[x]

print(solve(n-1))
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 21 16:49:00 2020

@author: matsui
"""

def cost(i,j):
    return abs(int(h[i])-int(h[j]))

N=int(input())
h=input().split()

dp=[0]*N
dp[1]=cost(0,1)
   
for i in range(2,N):
    dp[i]=min(cost(i,i-1)+dp[i-1],cost(i,i-2)+dp[i-2])
    
print(dp[N-1])
n = int(input())
ar = list(map(int,input().split(" ")))
br = [0]
for i in range(n):
    if i == 1:
        br.append(abs(ar[i-1] - ar[i]))
    elif i != 0:
        a = br[-2] + abs(ar[i-2] - ar[i]) 
        b = br[-1] + abs(ar[i-1] - ar[i]) 
        br.append(min(a,b))
print(br[-1])
n = int(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])
n = int(input())
h = list(map(int, input().split()))


INF = 1000000000
h += [INF] * 2
#最小値(コスト)を求める問題のため、DP配列を無限大に初期化
dp = [INF] * (n + 2)
#0番目の地点はコスト0
dp[0] = 0

for i in range(n):
  #もらうDPとやらで実装
  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_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])
  return

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()))
    
inf = 10**9
dp = [0] + [inf]*N
    
for i in range(1,N):
    if i == 1:
        dp[1] = abs(h[1]-h[0])
    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())
arr = input().split()
arr = list(map(int, arr))

arr = [arr[0]] + arr
dp = [0]*len(arr)
dp[0] = 0
dp[1] = 0

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

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

for i in range(2, n):

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

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

print(dp[n-1])
n=int(input())
l=list(map(int,input().split()))
a=0
b=abs(l[0]-l[1])
for i in range(2,n):
    h1=a+abs(l[i]-l[i-2])
    h2=b+abs(l[i]-l[i-1])
    a=b
    b=min(h1,h2)
print(b)
import sys

N = int(sys.stdin.readline())
h = [int(hi) for hi in sys.stdin.readline().split(' ')]

dp = [1000000 * N] * N
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[-1])
n = int(input())
ln = list(map(int, input().split()))
min_ln = []
for i in range(n):
    if i == 0:
        min_ln.append(0)
    elif i == 1:
        min_ln.append(abs(ln[1] - ln[0]))
    else:
        min_ln.append(min(abs(ln[i] - ln[i-1]) + min_ln[i-1], abs(ln[i] - ln[i-2]) + min_ln[i-2]))
print(min_ln[-1])
N = int(input())
H = list(map(int,input().split()))
dp = [10**9 for i in range(N+1)]
dp[1] = 0
for i in range(2,N+1):
    x = H[i-2] - H[i-1]
    y = 100000
    if i >= 3:
        y = H[i-3] - H[i-1]
    if x < 0:
        x = -x
    if y < 0:
        y = -y
    x = min(dp[i-1]+x,dp[i-2]+y)
    dp[i] = x
print(dp[N])
N = int(input())
h = list(map(int, input().split()))

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

print(dp[-1])
#!/usr/bin/env python3

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

costs = [0] * N
costs[0] = 0
costs[1] = abs(h[1] - h[0])
for i in range(2,N):
  tmp1 = costs[i-2] + abs(h[i] - h[i-2])
  tmp2 = costs[i-1] + abs(h[i] - h[i-1])
  costs[i] = min(tmp1,tmp2)
print(costs[N-1])
n=int(input())
a=list(map(int,input().split()))
dp=[0]*n
dp[0]=0
dp[1]=abs(a[0]-a[1])
for i in range(2,n):
  dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]))
print(dp[n-1])
n = int(input())
h = [0]
for i in input().split(): h.append(int(i))
def cost(i,j): return abs(h[i]-h[j])

#dp[i]:= 足場iにたどり着く為の最小コスト
#dp[0]:= 0
#dp[1]:= 0
#dp[2]:= abs(h[1]-h[2])
dp = [0 for _ in range(n+1)]
dp[2] = cost(1,2)
for i in range(3,n+1):
    dp[i] = min(dp[i-1]+cost(i,i-1),dp[i-2]+cost(i,i-2))

print(dp[n])
def cost(n, nums):
    dp = [0 for _ in range(n)]
    dp[0] = 0
    dp[1] = abs(nums[1] - nums[0])
    for i in range(2, n):
        dp[i] = min(
            dp[i-1] + abs(nums[i]-nums[i-1]),
            dp[i-2] + abs(nums[i]-nums[i-2]))
    return dp[-1]

n = int(input())
nums = [int(i) for i in input().split()]
print(cost(n, nums))
n=int(input())
a=list(map(int,input().split()))

dp_table=[]
for i in range(n):
    if i==0:dp_table.append(0)
    elif i==1:dp_table.append(abs(a[i]-a[i-1]))
    else:dp_table.append(min(abs(a[i]-a[i-2])+dp_table[-2],abs(a[i]-a[i-1])+dp_table[-1]))
print(dp_table[-1])
def main():
    N = int(input())
    h = list(map(int, input().split()))
    dp = [float("inf")]*N
    dp[0] = 0
    for i in range(1, 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[-1])


if __name__ == "__main__":
    main()
n=int(input())
l=list(map(int,input().split()))
dp=[0]*(n)
dp[0]=0
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())
h=list(map(int,input().split()))

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

dp = [float("inf") for i in range(n)]

dp[0] = 0
for idx, h in enumerate(hl):
    if idx + 2 < n:
        dp[idx+2] = min(dp[idx] + abs(hl[idx] - hl[idx+2]), dp[idx+2])
    if idx+1 < n:
        dp[idx+1] = min(dp[idx] + abs(hl[idx] - hl[idx+1]), dp[idx+1])

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

DP = [0]*N
DP[1] = abs(High[0]-High[1])
for i in range(2, N):
    DP[i] = min(DP[i-2] + abs(High[i] - High[i - 2]), DP[i-1] + abs(High[i] - High[i - 1]))

print(DP[N-1])
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):
    c1 = dp[i-1] + abs(h[i] - h[i-1])
    c2 = dp[i-2] + abs(h[i] - h[i-2])
    dp[i] = c1 if c1 < c2 else c2
print(dp[n-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])
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-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 = [0]*(n+1)
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])
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 = [float("inf")] * (n + 10)
dp[0] = 0

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

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(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])
from sys import stdin
n = int(stdin.readline())
h = list(map(int,stdin.readline().split()))
dp = [0]
for i in range(1,n):
    dp.append(min(dp[i-1]+abs(h[i]-h[i-1]),10**9 if i==1 else dp[i-2]+abs(h[i]-h[i-2])))
print(dp[-1])
N = int(input())
h = list(map(int, input().split()))
x = [0] * N
x[1] = x[0] + abs(h[1] - h[0])
for i in range(2, N):
    x[i] = min(x[i - 1] + abs(h[i] - h[i - 1]),
               x[i - 2] + abs(h[i] - h[i - 2]))
print(x[N-1])
def frog(H,N):
    #print(H)
    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-2])+DP[i-2],abs(H[i]-H[i-1])+DP[i-1])
    #print(DP)
    return DP[-1]    
if __name__ == '__main__':
    N = int(input())
    H = list(map(int,input().split()))
    ans = frog(H,N)
    print(ans)
N= int(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):
    # print((dp[i-1]+ abs(h[i]-h[i-1])))
    # print((dp[i-2]+ abs(h[i]-h[i-2])))
    # print()
    dp[i]= min( (dp[i-1]+ abs(h[i]-h[i-1])) , (dp[i-2]+ abs(h[i]-h[i-2])))
    # print(dp[i])

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

mincost = [float("inf") for _ in range(N)]
mincost[0] = 0
mincost[1] = abs(h[1] - h[0])

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

print(mincost[N - 1])
import sys
import math
from collections import deque

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

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

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

DP = [10 ** 9] * 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])
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
h = [None]+LI()
dp = [float('INF')]*(N+1) #1_indexed
dp[1] = 0
for i,j in itertools.product(range(1,N+1),[1,2]):
    if i+j>=N+1:
        continue
    dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))
print(dp[-1])
n=int(input())
dp=[0]*(n+1)
h=list(map(int,input().split()))
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())
H = list(map(int, sys.stdin.readline().rsplit()))

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

print(dp[N - 1])
n = int(input())
h = [int(i) for i in input().split()]

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

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])
def chmin(a, b):
    if a > b:
        a = b
        return a
    else:
        return a

n = int(input())
ls = list(map(int, input().split()))

dp = [10**9] * n
dp[0] = 0

for i in range(1, n):
    dp[i] = chmin(dp[i], dp[i - 1] + abs(ls[i] - ls[i - 1]))
    if i > 1:
        dp[i] =  chmin(dp[i], dp[i - 2] + abs(ls[i] - ls[i - 2]))

print(dp[n - 1])
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    inf=10**10
    n=int(readline())
    h=np.array(list(map(int,readline().split())),dtype=np.int64)

    dp=np.full(n,inf,dtype=np.int64)
    dp[0]=0
    for i in range(n):
        nex_end=i+2+1
        dp[i+1:nex_end]=np.minimum(dp[i+1:nex_end],dp[i]+np.abs(h[i]-h[i+1:nex_end]))

    print(dp[-1])

if __name__=="__main__":
    main()
n=int(input())
cost=list(map(int, input().split()))
dp=[0]*n
dp[0]=0
dp[1]=abs(cost[1]-cost[0])
for i in range(2,n):
	dp[i]=min(abs(cost[i]-cost[i-1]) + dp[i-1], abs(cost[i]-cost[i-2])+dp[i-2])
print(dp[n-1])
import sys
sys.setrecursionlimit(1000000)

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

def ans(n):
  if cost[n] != -1:
    return cost[n]
  cost[n] = min(ans(n-1) + abs(h[n-1] - h[n]), ans(n-2) + abs(h[n-2] - h[n]))
  return cost[n]

cost[0] = 0
cost[1] = abs(h[0] - h[1])
print(ans(n-1))