peterverebics/CodeNet_Python_118 huggingface dataset:
N=int(input())
H=[int(i) for i in input().split()]
dp=[0]*(N+5)
dp[0]=0
dp[1]=abs(H[1]-H[0])
for i in range(1,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()))

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

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

for i in range(1,n):
  d1 = dp[i-1] + abs(l[i] - l[i-1])
  if i > 1:
    d2 = dp[i-2] + abs(l[i] - l[i-2])
    if d1 > d2:
      d1 = d2
  dp[i] = d1
print(l,dp)
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
h=nl()

dp=[10**5]*(n+1)

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

ans = [100000000] * N
ans[0] = 0
for i in range(N-1):
    ans[i+1] = min(ans[i+1], ans[i] + abs(h[i] - h[i+1]))
    if i  < N - 2:
        ans[i+2] = min(ans[i+2], ans[i] + abs(h[i] - h[i+2]))
print(ans[-1])
import itertools

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

s=[0]+list(itertools.accumulate(a))

dp=[[10**20]*(n+1) for _ in range(n)]
for l in range(n):
    dp[l][l+1]=0
for d in range(2,n+1): 
    for k in range(1,d):
        for i in range(n-d+1):
            j=i+d
            S=s[j]-s[i]
            dp[i][j]=min(dp[i][i+k]+dp[i+k][j],dp[i][j])+S

print(dp[0][n])
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):
    if (abs(inp[i+1]-inp[i-1]) < abs(inp[i+1]-inp[i])):
        dp[i+1] = abs(inp[i+1]-inp[i-1]) + dp[i-1]
    else:
        dp[i+1] = abs(inp[i+1]-inp[i]) + dp[i]

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

DP = [0 for _ in range(N)]
DP[0] = 0
DP[1] = 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)
print(DP[N-1])
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 12:16:43 2020

@author: PREET MODH
"""

input()
a=list(map(int,input().split()))
i=0
sum=0
a.append(1000000000)
while(i+1<len(a)-1):
    b=a[i]
    store=0
    if i+1<len(a):
        store=min(a[i+1],a[i+2])
    diff=abs(b-store)
    sum=sum + diff
    if store==a[i+1]:
        i=i+1
    else:
        i=i+2
print(sum)
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], dp[i] + abs(h[i] - h[i - 1]))
        if (i > 1):
            dp[i + 2] = ch_min(dp[i], dp[i] + abs(h[i] - h[i - 2]))
    print(dp[N - 1])
N = int( input() )
h = [int(x) for x in input().split()]

h     = [0] + h
dp    = [0]*( len(h) )
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 = [float('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)
print(dp[N-1])
#DP カエルの奴 A 　配るDP
N=int(input())
S=list(map(int,input().split()))
S.append(100010)
S.append(100010)
DP=[100000000]*100010

DP[0]=0
for i in range(N):
    if DP[i]+abs(S[i]-S[i+1])<DP[i+1]:
        DP[i+1]=DP[i]+abs(S[i]-S[i+1])
    if DP[i]+abs(S[i]-S[i+2])<DP[i+2]:
        DP[i+2]=DP[i]+abs(S[i]-S[i+2])


print(DP[N-1])
print(DP)
n=int(input())
a=list(map(int,input().split()))
dp=[-1]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,len(a)):
    dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]))
print(dp)
print(dp[-1])
dp = [10001 for i in range(100002)]
n = int(input())
hs = list(map(int, input().split()))

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

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


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


"""もらうDP"""
import math

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

dp = list([math.inf for i in range(N)])  # dpテーブル
dp[0] = 0
for i in range(N):
    dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
    if i > 1:
        dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))

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

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

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

for i in range(2,n):
    #dp[i]
    # 1
    tmp1 = dp[i-1] + abs(h_L[i-1] - h_L[i])
    dp[i] = min(dp[i],tmp1)
    # 2
    tmp2 = dp[i-2] + abs(h_L[i-2] - h_L[i])
    dp[i] = min(dp[i],tmp2)
#print(dp)
print(dp[n-1])
n = int(input())
h = list(map(int, input().split()))
c = []
for i in range(n-2):
  d = abs(h[i]-h[i+1])
  e = abs(h[i]-h[i+2])
  c.append(min(d,e))
  if d>e:
  	i+=1
  else:
    i+=2
print(sum(c))
def solution(h):
    n = len(h)
    if n == 1:
        return 0
    elif n == 2:
        return abs(h[1]-h[0])
    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)
    return dp[n-1]

N = int(input())
h = list(map(int,input().split()))
res = solution(h)
print(res)
N = int(input())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	dp[i + 1] = dp[i] + abs(h[i + 1] - h[i])
	if i < N - 2:
		dp[i + 2] =dp[i + 2], dp[i] + abs(h[i + 2] - h[i])
print(dp[N - 1])
n = int(input())
x =list(map(int,input().split()))
a = [0,abs(x[1]-x[0])]
if n>2:
    for i in range(2,n):
        a.append(min(abs(x[i-2]-x[i])+a[-2],abs(x[i-1]+x[i])+a[-1]))
else:
    print(a[-1])
    exit()
  
print(a[-1])
n = int(input())
heights = list(map(int, input().split()))

dp = [0] * n

for i in range(n):
  act_h = heights[i]
  for j in [(i+1), (i+2)]:
    if j < n:
      next_h = heights[j]
      new_w = abs(next_h -act_h)
      if dp[j] == 0:
        dp[j] = dp[i] + new_w
      else:
        dp[j] = min(dp[i] + new_w, dp[j])

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

print(dp[N])
def solution(h):
    n = len(h)
    INF = float('inf')
    dp = [INF]*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(h[i]-h[j]) )
    print(*dp)
    return dp[n-1]

N = int(input())
h = list(map(int,input().split()))
res = solution(h)
print(res)
n = int(input())
h = list(map(int, input().split()))
INF = 10**8
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])
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[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(0,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[n-1])
# ume 20/01/03
# abc149-dが解けないのでやった
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])

if __name__ == '__main__':
  main()
def edpcA(n, hs):
    hm2, hm1 = hs[0], hs[1]
    dp = [0, abs(hm2-hm1)]
    hs = list(reversed(hs[2:]))
    for i in range(2, n):
        h = hs.pop()
        d1 = dp[i-1] + abs(h-hm1)
        d2 = dp[i-2] + abs(h-hm2)
        dp.append(min(d1, d2))
        hm2, hm1 = hm1, h
    print(dp)
n = int(input())
hs = list(map(int, input().split(' ')))
edpcA(n, hs)
import numpy as np

N = int(input())
heights = [int(i) for i in input().split()]

dp = np.full((N), np.Inf)

dp[0] = 0
dp[1] = heights[1] - heights[0]


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

print(int(dp[N-1]))
def solution(h):
    n = len(h)
    INF = float('inf')
    dp = [INF]*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(h[i]-h[j]) )
    print(*dp)
    return dp[n-1]

N = int(input())
h = list(map(int,input().split()))
res = solution(h)
print(res,end="")
"""
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):
    print(i)
    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)
print(dp[N-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**4] * 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(" ")))

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

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

cost = [0]*n
cost[0] = arr[0]
for i in range(1, n):
  if i > 1:
    cost[i] = min(abs(arr[i]-arr[i-2])+cost[i-2], abs(arr[i]-arr[i-1])+cost[i-1])
  else:
    cost[i] = abs(arr[i]-arr[i-1])
    
print(cost[-1])
N = int(input())
h = tuple(map(int, input().split()))
cost = [float('inf')] * N
cost[0] = 0
cost[1] = abs(h[0] - h[1])
for i in range(N-2):
  cost[i+1] = min(cost[i+1], cost[i] + abs(h[i] - h[i+1]))
  cost[i+2] = min(cost[i+2], cost[i] + abs(h[i] - h[i+2]))
print(cost[-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]), 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 = list(map(int, input().split()))

dp = [10001] * 110000
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 n - 2 > i:
        dp[i+2] = 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=[0]*(n)
for i in range(1,n):
  if i-2>=0:
    dp[i]=min(dp[i-2]+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[-1])
N = int(input())
lst = [int(x) for x in input().split()]
dp = [10 ** 5 for _ in range(N)]
dp[0] = 0
dp[1] = abs(lst[1] - lst[0])
for i in range(N - 1):
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(lst[i + 1] - lst[i]))
    if i < N - 2:
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(lst[i + 2] - lst[i]))
print(dp[N - 1])
def solution(h):
    n = len(h)
    INF = float('inf')
    dp = [INF]*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(h[i]-h[j]) )
    print(*dp)
    return dp[n-1]

N = int(input())
h = list(map(int,input().split()))
res = solution(h)
print(res,end="\n")
import numpy as np
import sys
f = sys.stdin
n = int(f.readline())
h = list(map(int, f.readline().split()))
h = np.array(h)
dp = np.zeros(n, int)
for i in range(n - 1):
    np.minimum(
        dp[1:-1] + np.abs(h[2:] - h[1:-1]), dp[:-2] + np.abs(h[2:] - h[:-2]), out=dp[2:]
    )
print(dp[-1])
import math
import os
import random
import re
import sys
def dpfindpath(a):
	dpath=[int(0) for _ in range(len(a))]
	print(len(dpath))
	dpath[0]=0
	dpath[1]=abs(a[1]-a[0])
	for i in range(2,len(a)):
		dpath[i]=min(abs(a[i]-a[i-1])+dpath[i-1],abs(a[i]-a[i-2])+dpath[i-2])
	return dpath[len(a)-1]
n=int(input())
a=input().split()
for i in range(n):
  a[i]=int(a[i])
print (dpfindpath(a))
#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[-1])
N = int(input())
H = list(map(int, input().split())) + [0] * 100
dp = [10**5] * (N+10)
dp[0] = 0

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

DP = [0]*(N+1)

for i in range(1, N+1):
    if i == 1:
        DP[i] = H[1]
        continue
    if i == 2:
        DP[i] = abs(H[1] - H[2])
        continue
    c1 = abs(H[i-1] - H[i])
    c2 = abs(H[i-2] - H[i])
    DP[i] = min(DP[i-1] + c1, DP[i-2] + c2)


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

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

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

for i in range(2,n):
    #dp[i]
    # 1
    tmp1 = dp[i-1] + abs(h_L[i-1] - h_L[i])
    dp[i] = min(dp[i],tmp1)
    # 2
    tmp2 = dp[i-2] + abs(h_L[i-2] - h_L[i])
    dp[i] = min(dp[i],tmp2)
#print(dp)
print(dp[len(h_L)-1])
import sys
sys.setrecursionlimit(200000)
 
n = int(input())
 
h = [int(i) for i in input().split()]

d = {}
 
def dp(cost, p):
  if p in d:
    return d[p]
  if p == n-1:
    return cost
  if p < n-2:
    m = min(dp(cost+abs(h[p]-h[p+1]), p+1), dp(cost+abs(h[p]-h[p+2]), p+2))
    d[p] = m
    return m
  if p == n-2:
    return dp(cost+abs(h[p]-h[p+1]), p+1)

print(dp(0, 0))
def cmin(a,b):
    if a>b:
        return b
    else:
        return a
 
N = int(input())
h = list(map(int,input().split()))
 
dp = [0] + [float("inf")]*(N-1)
for i in range(1,N):
    dp[i] = cmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
print(dp[-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-2]), dp[i-1] + abs(h[i] - h[i-1]))
print(dp[-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] + abs(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()))
dp=[float("INF")]*n
dp[0]=0
for i in range(2,n):
  for j in range(1,3):
    dp[i]=min(dp[i-j]+abs(l[i]-l[i-j]),dp[i])
print(dp[-1])
n = int(input())
H = list(map(int, input().split()))
DP = [10 ** 5] * 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())
Hn = [float("inf")] + list(map(int, input().split()))

cur = N
ans = 0
while cur > 1:
    a = abs(Hn[cur] - Hn[cur - 1])
    b = abs(Hn[cur] - Hn[cur - 2])
    if a < b:
        ans += a
        cur -= 1
    else:
        ans += b
        cur -= 2

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

dp = [1e7]*N
dp[0] = h[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])
size = int(input())
array =  list(map(int, input().split()))
dp = [0]* size
for jump in range(1,size):
	z= [1,2]
	for i in range(len(z)):
		dp[jump] = min(dp[jump],dp[i] + dp[jump] )

print(dp[-1])
def frog(arr):
    
    n=len(arr)
    if n<=1:
        return 0
    dp=[0]*(n+1)
#     dp[2]=abs(arr[0]-arr[1])
#     if n==2:
#         return dp[2]
    for i in range(2,n+1):
        
        dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i-2]),dp[i-2]+abs(arr[i-1]-arr[i-3]))
    return dp[n]
n=int(input())
arr=[int(i) for i in input().split()]
frog(arr)
#DP カエルの奴 A 　配るDP
N=int(input())
S=list(map(int,input().split()))
S.append(100010)
DP=[100000000]*100010

DP[0]=0
for i in range(N-1):
    if DP[i]+abs(S[i]-S[i+1])<DP[i+1]:
        DP[i+1]=DP[i]+abs(S[i]-S[i+1])
    if DP[i]+abs(S[i]-S[i+2])<DP[i+2]:
        DP[i+2]=DP[i]+abs(S[i]-S[i+2])


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

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

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

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

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

dp = [1000000000]* len(hs)

if a == 0:
  print(0)
  exit()
if a == 1:
  print(hs[0])
  exit()

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

if a == 2:
  print(dp[1])
  exit()

limit_a = max(0, a-2)


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

print(dp[-1])
INF = 10 ** 4 + 10

n = int(input())
H = list(map(int, input().split()))
DP = [INF] * 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]))
print(DP[-1])
def chmin(a, b):
  if a > b:
    return b
  return a

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

if __name__ == '__main__':
  main()
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 != N-2:
        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[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):
    a = dp[i-1] + abs(h[i]-h[i-1])
    b = dp[i-2] + abs(h[i]-h[i-2])
    dp[i] = min(a,b)

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

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

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])
n = int(input())
h = list(map(int, input().split()))
c = []
for i in range(n-2):
  d = abs(h[i]-h[i+1])
  e = abs(h[i]-h[i+2])
  c.append(min(d,e))
  i+=1
print(sum(c))
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[+1] + np.abs(h[i+1] - h[i+2]))
    
print(d[n-1])
N = int(input())
h = list(map(int,input().split()))
dp = [10**5 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+2 < N:
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] -h[i]))
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])
for i in range(2, 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 - 1])
N = int(input())
H = list(map(int, input().split()))
INF = 100000
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())
h=list(map(int,input().split(' ')))
h2=[[0,0]]
h2.append([abs(h[0]-h[1]),0])
for i in range(0,len(h)-2):
    if abs(h[i+1]-h[i+2]) >= abs(h[i]-h[i+2]):
        h2.append([abs(h[i]-h[i+2]),i])
    else:
        h2.append([abs(h[i+1]-h[i+2]),i+1])
a=h2[int(len(h2)-1)][1]
total=h2[int(len(h2)-1)][0]
while a!=0:
    total=total +h2[int(a)][0]
    a=h2[a][1]
print(total)
n=int(input())
arr=[int(x) for x in input().split()]
arr.append(0)
val=[0]*(n+1)
for i in range(n-2,-1,-1):
    val[i]=min(abs(arr[i]-arr[i+1])+val[i+1],abs(arr[i]-arr[i+2])+val[i+2])

print(val[0])
N = int(input())
*h, = map(int, input().split())

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

print(dp[N - 1])
def main():
    N = int(input())
    H = [int(x) for x in input().split()]
    inf=float("inf")
    DP = [float("inf")]*N
    DP[0] = H[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])

if __name__ == "__main__":
    main()
    pass
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]=max(abs(l[i]-l[i-2])+dp[i-2],dp[i-1]+abs(l[i]-l[i-1]))
print(dp[-1])
N = int(input())
list = [int(i) for i in input().split(" ")]

def cost(N):
    dp = [0] * N
    dp[0] = list[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))