peterverebics/CodeNet_Python_118 huggingface dataset:
import sys
n = int(input())
h = list(map(int,input().split()))
inf = float("inf")
dp = [inf]*(n+1)
if n == 2:
    print(abs(h[1]-h[0]))
    sys.exit()

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

for i in range(3,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])
import numpy as np

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

dp = np.zeros(N+1, dtype=np.int32)
for i in range(2, N+1):
    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])
N = int(input())
h = [int(i) for i in input().split()]
dp = [10001]*N
dp[0] = 0
dp[1] = abs(h[0]-h[1])

def chmin(i, b):
    if dp[i] > b: dp[i] = b

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

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

print(dp[N])
def frog_jump(n:int, stones)->int:
    dp = [float('inf')] * n
    jumps = (1, 2)
    dp[0] = 0
    for idx in range(len(dp)):
        for jump in jumps:
            if idx+jump < len(dp):
                dp[idx+jump] =  min(dp[idx]+abs(stones[idx+jump]-stones[idx]), dp[idx+jump])
    return dp[-1]

frog_jump(6, [30, 10, 60, 10, 60, 50])
arr = [10,30,40,20]

dp = [-1 for i in range(len(arr))]
dp[0] = 0
dp[1] = abs(arr[1]-arr[0])

for i in range(2, len(arr)):
    dp[i] = min(dp[i-2] + abs(arr[i]-arr[i-2]), dp[i-1] + abs(arr[i]-arr[i-1]))
    
print(dp[-1])
N = int(input())
h = [int(i) for i in input().split()]
dp = [10**5 for _ in range(N)]
dp[0] = 0
for i in range(N-1):
    if dp[i+1] > dp[i] + abs(h[i] -h[i+1]):
        dp[i+1] = dp[i] + abs(h[i] -h[i+1])
    if i+2 < N:
        if dp[i+2] > dp[i] + abs(h[i] -h[i+2]):
            dp[i+2] = dp[i] + abs(h[i] -h[i+2])
print(dp[-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(2,n):
	dp[i]=min(abs(l[i-1]-l[i])+dp[i-1],abs(l[i-2]-l[i]+dp[i-2]))
print(dp[-1])
#frog
N = int(input())
h = list(map(int,input().split()))
dp = [10000000000000] * N
dp[0] = 0

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

def solve():
    dpf()
    print(dp)
    print(dp[N-1])

if __name__ == "__main__":
    solve()
N = int(input())
H = list(map(int, input().split()))
dp = [10**5] * N
dp[0] = 0

for i in range(0, 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)
print(dp[N-1])
def chmin(a, b):
  if a > b:
    return b
  else:
    return a

def main():
  dp = [1e4+10]*100010
  hs = [0]*100010
  
  N = int(input())
  hs[:N] = map(int, input().split())
  
  dp[0] = 0
  for i in range(N):
    dp[i+1] = chmin(dp[i+1], dp[i]+abs(hs[i+1]-hs[i]))
    dp[i+2] = chmin(dp[i+2], dp[i]+abs(hs[i+2]-hs[i]))
  print(dp[N-1])
  return

if __name__ == '__main__':
  main()
n = int(input())
a = list(map(int, input().split()))

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

for i, v in enumerate(a):
  if i > n - 1:
    break
  if i - 2 < 0:
    dp[i] = abs(a[i] - a[i-1])
    continue
  dp[i] = min(dp[i], dp[i-1] + abs(a[i] - a[i-1]))
  dp[i] = min(dp[i], dp[i-2] + abs(a[i] - a[i-2]))

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

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

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

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

dp = [10**8]*n

def chmin(a,b,index):
    if a > b:
        dp[index] = b

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

print(dp[n-1])
n=int(input())
hs=input().rstrip().split(" ")
costs=[0 for i in range(n)]
costs[1]=abs(int(hs[1])-int(hs[0]))
for i in range(n-2):
    jump=costs[i]+abs(int(hs[i+2])-int(hs[i]))
    walk=costs[i+1]+abs(int(hs[i+1])-int(hs[i]))
    costs[i+2]=min(jump,walk)
print(costs[-1])
def chmin(dp, i, target):
    if (dp[i] > target):
        dp[i] = target

n = int(input())
h = [i for i in input().split(" ")]
dp =[10**6] * n

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

print(dp[n - 1])
N = int(raw_input())
# h = list(map(int, input().split(" ")))
h_str = raw_input()
h = []
for h_i in h_str.split(" "):
    h.append(int(h_i))

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

dp = [10 ** 5 for i in range(n)]
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(n-2):
    dp[i+2] = min(dp[i] + abs(h[i+2] - h[i]), dp[i+1] + abs(h[i+1] - h[i]))
print(dp[-1])
N=int(input())
line=input().split(" ")
dp=[]
for i in range(N):
    line[i]=int(line[i])
    dp.append(100010)
dp[0]=0
dp[1]=abs(line[1]-line[0])
for j in range(2,N):
    dp[j]=min(dp[j], dp[j-1]+abs(line[j]-line[j-1]))
    dp[j]=min(dp[j], dp[j-2]+abs(line[j]-line[j-2]))
print(dp[N-1])
n=int(input())
h=list(map(int,input().split()))
cost=[0]*n
cost[0]=0
cost[1]=abs(h[0]-h[1])
def compare(i):
    cost[i]=max(cost[i-2]+abs(h[i]-h[i-2]),cost[i-1]+abs(h[i]-h[i-1]))
for j in range(2,n):
    compare(j)
print(cost[-1])
def aFrog(N,h):
    dp = [0 for i in range(10)]
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    print(dp)
    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]
# EDPC A Frog 1

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

cost = [10001]*N
cost[0] = 0

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

print(cost[N-1])
n=int(input())
data=[int(x) for x in input().split()]
ans=[0]*n
ans[0]=0
ans[1]=abs(data[1]-data[0])
for q in range(2,n):
    temp2=abs(data[q]-data[q-2])
    temp1=abs(data[q]-data[q-1])
    if(temp2<temp1):
        ans[q]=temp2+ans[q-2]
    else:
        ans[q]=temp1+ans[q-1]
print(ans[-1])
def main():
    import sys
    input = sys.stdin.readline

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

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

    dp[0] = 0

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


if __name__ == "__main__":
    main()
N = int(input())
H = list(map(int, input().split()))

dp = []

for i, h in enumerate(H) :
  if (i==0) :
    dp.append(0)
    continue
  
  if (i==1) :
    dp.append(abs(H[0]-H[1]))
    continue
  
  one = abs(H[i]-H[i-1])
  two = abs(H[i]-H[i-2])
  
  if (one < two):
    dp.append(dp[i-1] + one)
  else :
    dp.append(dp[i-2] + two)

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

import numpy as np

d = [0] * n #ex. [0, 0, 0, 0, 0, 0]

d[1] = np.abs(h[1] - h[0])

for i in range(n-2):
    d[i+2] = min(d[i] + np.abs(h[i+2] - h[i]), d[i] + np.abs(h[i+1] - h[i]))
    
print(d[n-1])
import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    h = list(IL())
    l = [10**4+1]*n
    l[0] = 0
    for i in range(1,n):
        l[i] = min(l[i],l[i-1]+abs(h[i-1]-h[i]))
        if 1<i:
            l[i] = min(l[i],l[i-2]+abs(h[i-2]-h[i]))
    print(l[-1])
    return

if __name__=='__main__':
    Main()
N = input()
heights = input()

N = int(N)
heights = map(int, heights.split(' '))
n = int(input())
h = [i for i in map(int, input().split())]

DP = [0]*n
DP[0] = 0
DP[1] = h[1]-h[0]

for i in range(n-2):
    if abs(h[i+2] - h[i]) < abs(h[i+2] - h[i+1]):
        DP[i+2] = DP[i] + abs(h[i+2] - h[i])
    else:
        DP[i+2] = DP[i+1] + abs(h[i+2] - h[i+1])

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

while(n<N-1):
    if n == N-2 :
        cost += abs(h[n]-h[n+1])
        n += 1
        break
    if abs(h[n]-h[n+1])+abs(h[n+1]-h[n+2]) == abs(h[n]-h[n+2]) :
        cost += abs(h[n]-h[n+1])
        n += 1
    else:
        cost += abs(h[n]-h[n+2])
        n += 2
print(cost)
N = int(input())
seq = [int(x) for x in input().split()]
last_val = [seq[0], seq[0]]
cost = [0, 0]
for i, val in enumerate(seq[1:-1]):
  if i % 2 == 1:
    j = 0
  else:
    j = 1
  cost[j] += abs(last_val[j] - seq[i+1])
  last_val[j] = seq[i+1]
for j in range(2):
  cost[j] += abs(last_val[j] - seq[-1])
print(min(cost))
# A - Frog1
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(1, N-1):
    dp[i+1] = min(dp[i-1]+abs(h[i+1]-h[i-2]), dp[i]+abs(h[i]-h[i-1]))
print(dp[N-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,min_ln[-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):
    a,b=abs(H[i-1]-H[i]),abs(H[i-2]-H[i])
    if a<b:
        dp[i]+=dp[i-1]+a
    else:
        dp[i]+=dp[i-2]+b

print(dp[-1])
import math
from decimal import *

n = int(input())
nos = list(map(int, input().split()))
arr = [0 for i in range(n)]
if(n>1):
    arr[1] = abs(nos[1]-nos[0])
for i in range(2, n):
    a ,b = abs(nos[i]-nos[i-1]), abs(nos[i]-nos[i-2])
    if(a>b):
        arr[i]=arr[i-2]+b
    else:
        arr[i] = arr[i-1]+a
print(arr[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)
  a, b = b, d1 if d1 <= d2 else d2

print(b)
n=int(input())
h=list(map(int,input().split()))
dp=[10**5+1]*n
for i in range(n):
  if i==0:
    dp[i]=0
  if i==1:
    dp[i]=abs(h[1]-h[0])
  else:
    for j in range(1,3):
      dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
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])
N=int(input())
A=list(map(int,input().split()))
dp=[0]*(N)
dp[0]=A[0]
dp[1]=abs(A[1]-A[0])
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())
height = list(map(int, input().split()))

dp = [0]
cost_initial = height[1] -height[0]
dp.append(cost_initial)

#print(dp)
#for h in height:

for i in range(len(height)-2):
    a1 = dp[i+1] + abs(height[i+2] - height[i+1])
    a2 = dp[i] + abs(height[i+2] - height[i])
    dp.append(min(a1, a2))

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

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

dp[0] = 0
dp[1] = 0
for i in range(2,N+1):
    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])
N = int(input())
hhh = list(map(int, input().split()))

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

print(dp[N])
n=int(input())
l=list(map(int,input().split()))
dp=[10**4 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(l[i+1]-l[i]))
    if (i+2<n):
        dp[i+2]=min(dp[i+2],dp[i]+abs(l[i+2]-l[i]))
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 = abs(H[i] - H[i - 2])
    b = abs(H[i] - H[i - 1])
    if a <= b:
        DP[i] = DP[i - 2] + a
    else:
        DP[i] = DP[i - 1] + b
print(DP[n - 1])
def frog(TC,hs,dp):

    #base case
    if TC == 0 :
        return 0
    if TC == 1:
        return abs(hs[1]-hs[0])
    #lookup
    if dp[TC]!=0:
        return dp[TC]

    op1 = abs(hs[TC-1]-hs[TC]) + frog(TC-1, hs, dp)
    op2 = abs(hs[TC - 2] - hs[TC]) + frog(TC - 2, hs, dp)
    dp[TC]= min(op1, op2)
    return dp[TC]
import sys

def frog():
    n = int(sys.stdin.readline())
    numbers = sys.stdin.readline().split()
    for i in range(n):
        numbers[i] = int(numbers[i])
    a_list = [0, abs(numbers[1] - numbers[0])]
    if n > 2:
        a_list.append(abs(numbers[2] - numbers[0]))
    else:
        return a_list[-1]
    for i in range(3, n):
        a_list.append(min(a_list[i-1]+abs(numbers[i-1] - numbers[i]), a_list[i-2]+abs(numbers[i-2] - numbers[i])))
    return a_list[-1]

frog()
def chmin(target, index, value):
    if (target[index] > value):
        print("i:%d value:%d" % (index, value))
        target[index] = value

n = int(input())
h = [i for i in input().split(" ")]
dp =[10000] * n

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

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

h_inf = 10 ** 5
dp = [h_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+2 < N:
        dp[i+2] = min(dp[i+2], dp[i]+abs(h[i]-h[i+2]))

print(dp[N-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(dp[-1])
n = int(input())
h = [int(x) for x in input().split()]
inf = float('inf')
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
    if i == 1:
        dp[i] = abs(h[i] - h[i-1])
    elif abs(h[i] - h[i-1]) < abs(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())
h = list(map(int, input().split()))
dp = [float("inf")] * N
dp[0] = 0
dp[1] = abs(h[0] - h[1])
h_2 = h[0]
h_1 = h[1]

for i in range(2, N):
    x = h[i]
    dp[i] = min(
        dp[i - 1] + abs(x - h_1),
        dp[i - 2] - abs(x - h_2)
    )
    h_2 = h_1
    h_1 = x
print(dp[-1])
N = int(input())
h = list(map(int,input().split()))
cost = [1000000]*(N+10)
cost[0] = 0
for i in range(N - 1):
  cost[i+1] = min(abs(h[i] - h[i+1]), cost[i+1])
  if i < N - 3:
    cost[i+2] = min(abs(h[i] - h[i+2]), cost[i+2])
print(cost[N-1])
# DP practice
# https://atcoder.jp/contests/dp/tasks/dp_a

# 入力方法としてはこれが手軽
N = int(input())
h = list(map(int, input().split()))

dp = list()

# N = 0, 1 の時の処理も必要。だが省く
dp.append(0)
dp.append(dp[0] + h[1] - h[0])

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

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):
    a=abs(h[i]-h[i-1])
    b=abs(h[i]-h[i-2])
    if a < b:
        dp[i]=dp[i-1]+a
    else:
        dp[i]=dp[i-2]+b

print(dp[n-1])
#https://atcoder.jp/contests/dp/tasks/dp_a
n = int(input())
h = [int(i) for i in input().split()]

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

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

else:
    print(abs(h[1]-h[0]))
N = int(input())
h = [int(i) for i in input().split()]
dp = [10**5 for _ in range(N)]
dp[0] = 0
for i in range(N-1):
    if dp[i+1] > dp[i] + abs(h[i+1] -h[i]):
        dp[i+1] = dp[i] + abs(h[i+1] -h[i])
    if i+2 < N:
        if dp[i+2] > dp[i] + abs(h[i+2] -h[i]):
            dp[i+2] = dp[i] + abs(h[i+2] -h[i])
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(n-2):
    DP[i+2]=min(DP[i]+abs(h[i]-h[i+2]),DP[i+1]+abs(h[i+2]-h[i+1]))
print(DP)
def chmin(a,b):
  return a if a<=b else b

n,*h=map(int,open(0).read().split())
dp=[10000]*n
dp[0]=0
for i in range(1,n):
  dp[i]=chmin(dp[i],dp[i-1]+abs(h[i-1]-h[i]))
  if i-2>=0:
    dp[i]=chmin(dp[i],dp[i-2]+abs(h[i-2]-h[i]))
print(dp[n-1])
# 初期化
dp = []
for i in range(100001):
    dp.append(float('inf'))

# 入力 添え字のN-1が足場Nに相当する
N = int(input())
h = list(map(int, input().split()))

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

# 添え字N-1=足場Nまで計算している
for i in range(N - 2):
    dp[i + 2] = min(dp[i + 1] + abs(h[i + 2] - h[i + 1]), dp[i] + abs(h[i + 2] - h[i]))

for i in range(N):
    print(dp[i])
n=int(input())
hs=list(map(int,input().split()))
dp=[10**4]*n
dp[0]=0

for i in range(1,n):
  dp[i]=min(dp[i],dp[i-1]+abs(hs[i]-hs[i-1]))
  if i-2<0: continue
  dp[i]=min(dp[i],dp[i-2]+abs(hs[i]-hs[i-2]))
  #print(dp[i])

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

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

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

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

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

print(dp[-1])
# A
# 若干解説を見た
# 2020/04/27  17:5-
n = int(input())
h = list(map(int, input().split()))

dp = [0]*n
for i in range(2, n):
    if i == 1:
        dp[i] = 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)]
for i in range(1, 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])
import sys
def m_mcm(l , n ):
    if  n == 0:
        return 0
    if n == 1:
        return abs(l[n]-l[n-1])
    return min(abs(l[n] - l[n-1])+ m_mcm(l,n-1),abs(l[n]-l[n-2])+m_mcm(l , n - 2))
    n = int(input())
    l = list(map(int,input().split()))
    res = m_mcm(l,len(l)-1)
    print(res)
# A
# 若干解説を見た
# 2020/04/27  17:5-
n = int(input())
h = list(map(int, input().split()))

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

dp = [10**8]*n

def chmin(a,b,i):
    if a > b:
        dp[i] = b

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

print(dp[n-1])
import decimal
N = int(input())
h = tuple(map(int, input().split()))
dp = [10**5+1 for i in range(N)]
dp[0] = 0
def chmin(lis, i, j):
  if lis[i] > j:
    lis[i] = j

chmin(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])
n = int(input())
h = [int(x) for x in input().split()]
inf = float('inf')
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
    if i == 1:
        dp[i] = abs(h[i] - h[i-1])
    elif abs(h[i] - h[i-1]) < abs(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[n-1])
def fu(n):
    if n<0:
        return (n*(-1))
    return n
n = int(input())
h = list(map(int,input().split()))

l1 = [0 for i in range(n)]
l1[n-1] = 0
l1[n-2] = abs(h[n-1]-h[n-2])
for i in range(n-3,-1,-1):
    l1[i] = min(abs(h[i]-h[i+1])+l1[i+1],abs(h[i]-h[i+2])+l1[i+2])
print(l1)
print(l1[0])
def main():
    INF = 10**9
    N = int(input())
    h = list(map(int,input().split()))
    h.insert(0,0)
    dp = [INF]*(N+1)
    dp[0] = 0
    dp[1] = h[0]
    for i in range(2,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])

if __name__ == '__main__':
    main()
N = int(input())
h = list(map(int, input().split()))

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

def chmin(a, b):
    if a > b:
        return b
    else:
        return a
        
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])
# Vicfred
# https://atcoder.jp/contests/dp/tasks/dp_a
# dynamic programming
n = int(input())
h = [0]+list(map(int, input().split()))

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

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

dp = [0]*(n+1)
for i in range(n):
  dp[i+1] = min(dp[i] + abs(h[i]-h[i-1]), dp[i-1] + abs(h[i]-h[i-2]))
  
print(dp[-1])
n=int(input())
a=[int(x) for x in input().split()]
if n==2:
    print(abs(a[0]-a[1]))
else:
    l=[0]*(n)
    l[0]=a[0]
    l[1]=abs(a[0]-a[1])
    for i in range(2,n):
        l[i]=min(l[i-2]+abs(a[i-2]-a[i]),l[i-1]+abs(a[i-1]-a[i]))
    print(l[n-1])
n=int(input())
h=list(map(int,input().split()))
dp=[10**5]*n
for i in range(n):
   if i==0:
    dp[i]=0
   elif i==1:
    dp[i]=abs(h[1]-h[0])
   else:
    for j in (1,3):
      dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])
# DP practice
# https://atcoder.jp/contests/dp/tasks/dp_a

# 入力方法としてはこれが手軽
N = int(input())
h = list(map(int, input().split()))

dp = list()

# N = 0, 1 の時の処理も必要。だが省く
dp.append(0)
dp.append(dp[0] + h[1] - h[0])

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


print(dp)
n = int(input())
l = list(map(int, input().split()))
diff = 0
prev = l[0]
i = 1
while(i < n-1):
    diff += prev-min(l[i],l[i+1])
    prev = min(l[i],l[i+1])
    if(prev == l[i]):
        i += 1
    else:
        i += 2
print(diff)
n=int(input())
a=list(map(int,input().split()))

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

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

dp = [10**8]*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 >= 2:
        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**5 for i in range(n)]
dp[0]=0
dp[1]=abs(H[1]-H[0])
for i in range(n-2):
    dp[i+2]=min(dp[i]+abs(H[i]-H[i+2]),dp[i+1]+abs(H[i]-H[i+1]))
print(dp[n-1])
N = int(input())
H = [int(i) for i in input().split()]

dp = [0]*N

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