peterverebics/CodeNet_Python_118 huggingface dataset:
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 = int(input())
*H, = map(int, input().split())
DP = [0 for i in range(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[n-1])
N = int(input())
seq = [int(x) for x in input().split()]
cost1 = [seq[0]] + seq[1::2]
if N % 2 != 0:
  cost1.append(seq[-1])

cost2 = seq[::2]
if N % 2 == 0:
  cost2.append(seq[-1])

ans1 = 0
for i in range(len(cost1)-1):
  ans1 += abs(cost1[i+1] - cost1[i])
ans2 = 0
for i in range(len(cost2)-1):
  ans2 += abs(cost2[i+1] - cost2[i])
print(min(ans1, ans2))
N = int(input())
H = list(map(int, input().split()))
         
# N = 4
# H = [10,30,40,20]
         
table = [0]*N

for i in range(N-1):
    if i <= N-3:
        table[i+2] = min(
            table[i] + abs(H[i]-H[i+2]),
            table[i+1] + abs(H[i+1] - H[i+2])
        )
    else: #N-2
        table[i+1] = table[i] + abs(H[i]-H[i+1])

print(table[-1])
n=int(input())
li=[int(k) for k in input().split()]
dp=[0]*(n)
dp[0]=li[0]
dp[1]=abs(li[1]-li[0])
for i in range(2,n):
  dp[i]=min(abs(li[i]-dp[i-1]),abs(li[i]-dp[i-2]))
print(dp[n-1])
n = int(input())
h = [i for i in map(int, input().split())]

dp = [0]*n

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

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

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

dp = [float('inf')]*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]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

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

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

dp = [10010] * 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])
n=int(input())
h=list(map(int,input().split()))
dp=[10**5]*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 [1,2]:
      dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])
n=int(input())
l=list(map(int,input().split()))
dp=[float("INF")]*n
dp[0]=0
if n==1:
  print(0)
elif n==2:print(abs(l[-1]-l[0]))
else:
  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()))
H = [0] + H
dp = [0] * (N+1)
dp[1] = H[1]

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

res = dp[N]
print(res)
#DP カエルの奴 A 　配るDP
N=int(input())
S=list(map(int,input().split()))
S.append(0)
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])
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)
def main():
  n = int(input())
  hs = tuple(map(int, input().split()))

  a, b = 0, abs(hs[1] - hs[0])

  for i in range(2, n):
    d1 = a + abs(hs[i] - hs[i-2])
    d2 = b + abs(hs[i] - hs[i-1])
    a, b = b, d1 if d1 <= d2 else d2

  print(b)
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)
N = eval(input())
H = list(map(int, input().split()))
dp = [0, H[1] - H[0]]
if N > 2:
    for i in range(2, N):
        dp.append(min(abs(H[i] - H[i-2])+dp[-2], abs(H[i] - H[i-1])+dp[-1]))
else:
    print(dp[-1])
    exit()
print(dp[-1])
size = int(input())
array =  list(map(int, input().split()))
dp = [0]* size
dp[1]=  dp[0] + abs(array[1] - array[0]) 
for i in range(2,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 = list(map(int, input().split()))
dp = [0] * n
for i in range(n):
  if i == 0:
    continue
  elif i == 1:
    dp[1] = abs(h[1] - h[0])
    continue
  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())
costlist = list(map(int,input().split()))
DP = [0 for i in range(N)]
DP[1]=abs(costlist[1]-costlist[0])
for i in range(N-2):
    probmin1 = abs(costlist[i+2]-costlist[i+1]) + costlist[i+1]
    probmin2 = abs(costlist[i+2]-costlist[i]) + costlist[i]
    plusmin = min(probmin1,probmin2) 
    DP[i+2]=plusmin
print(DP[-1])
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])
n = int(input())
h = list(map(int, input().split()))

INF = 1 << 40
dp = [INF] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
	pos = h[i]
	if abs(h[i-2] - pos) < abs(h[i-1] - pos):
		diff = abs(h[i-2] - pos)
		dp[i] = dp[i-2] + diff
	else:
		diff = abs(h[i-1] - pos)
		dp[i] = dp[i-1] + diff

print(dp[-1])
n = int(input())
H = [0]
here = 1
ans = 0
H += list(map(int, input().split()))
while not here == n:
    if here == n - 1:
        one_step = abs(H[here + 1] - H[here])
        ans += one_step
        break
    else:
        one_step = abs(H[here + 2] - H[here])
        two_step = abs(H[here + 1] - H[here]) + abs(H[here + 2] - H[here + 1])
    if one_step >= two_step:
        ans += two_step
        here += 1
    else:
        ans += one_step
        here += 2
print(ans)
# -*- 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
while(i+2<len(a)):
    if i >=len(a):
        break
    b=a[i]
    store=min(a[i+1],a[i+2])
    diff=abs(b-store)
    sum=sum + diff
    if a[i+1]<a[i+2]:
        i=i+1
    else:
        i=i+2
print(sum)
n = int(input())
hlis = list(map(int, input().split()))
dp = [0] + [float('inf')]*(n-1)
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 = list(map(int, input().split()))

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

for i in range(2, n):
    dp[i] = min(dp[i-2] + abs(h[i] - h[i-1]), dp[i-1] + abs(h[i] - h[i-1]))
print(dp[-1])
# -*- coding: utf-8 -*-

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

dp = [100000] * N
dp[0] = 0
for i, h in enumerate(A):
    for j in (range(1,3)):
        if i+j < len(A):
            dp[i + j] = min(dp[i + j], dp[i] + abs(A[i] - A[i+j]))
        #print(dp)

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

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

dp[0]=0
dp[1]=0

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

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

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

def solve():
  global n, h_list
  n = int(input())
  h_list = list(map(int, input().split()))
  ans = hoge()
  print(ans)
  return 0

if __name__ == "__main__":
  solve()
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[-2]))
else:
    dp[1]=dp[0]+abs(a[0]-a[1])
print(dp[-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 <= n - 2:
        val1 = dp[i] + abs(h[i+1] - h[i])
        if val1 < dp[i+1]:
            dp[i+1] = val1
    if i <= n - 3:
        val2 = dp[i] + abs(h[i+2] - h[i])
        if val2 < dp[i+2]:
            dp[i+2] = val2
print(dp[-1])
import sys

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

def frog1(n,h):
  s = [0]*n
  s[0] = 0
  s[1] = min(h[1],s[0]+abs(h[1]-h[0]))
  for i in range(2,n):
    s[i]=min(s[i-2]+abs(h[i]-h[i-2]),s[i-1]+abs(h[i]-h[i-1]))
  return s[n-1]

print(frog1(N,H))
n = int(input())
h = list(map(int, input().split()))
INF = 10000
dp = [INF] * n
dp[0] = 0
for i in range(1, n):
    tmp = dp[i - 1] + abs(h[i] - h[i - 1])
    if dp[i] > tmp:
        dp[i] = tmp
    if i > 1:
        tmp = dp[i - 2] + abs(h[i] - h[i - 2])
        if dp[i] > tmp:
            dp[i] = tmp
print(dp[-1])
n = int(input())
h = list(map(int, input().split()))

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

dp = [float('inf')] * n
dp[0] = 0
for i in range(0, n - 1):
    print(i)
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))
    if i + 2 >= n:
        continue
    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
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()))
H = [0]*N
for i in range(1,N):
    if i == 1:
        H[i] = abs(h[1]-h[0])
    else:
        H[i] = max(H[i-1]+abs(h[i]-h[i-1]),H[i-2]+abs(h[i]-h[i-2]))
print(H[N-1])
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-1]-h[i]), dp[i-2]+abs(dp[i-1]-h[i]))

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

inf = 10 * 10
dp = [inf] * (n)
dp[0] = 0

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

print(dp[n-1])
N=int(input())
height_list=list(map(int,input().split()))
score_list=[ 0, abs(height_list[0]-height_list[1]) ]



for i in range(2,N):

    tmp=min(
        abs(height_list[i]-height_list[i-1])+score_list[i-1],
        abs(height_list[i]-height_list[i-2])+score_list[i-2]
    )

    score_list.append(tmp)

print(score_list)
n=int(input())
f=[0]*n
a=list(map(int,input().split()))
f[0]=0
f[1]=abs(a[0]-a[1])
for i in range(2,n):
    a1=abs(a[i]-a[i-2])
    b=abs(a[i]-a[i-1])
    f[i]=min((f[i-2]+a1),(f[i-1]+b))
    
print(f)
print(f[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(h[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-1])
n = int(input())
h = list(map(int,input().split()))
dp = [99999999]*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])
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,end="\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]))
    print(dp)
    return dp[-1]

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

DP = [0]*n
DP[0] = 0
DP[1] = abs(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())
lis=list(map(int,input().split()))
num=0
for i in range(0,len(lis)-1):
    m=0
    k=0
    m=abs(lis[i]-lis[i+1])
    if(i<len(lis)-2):
        k=abs(lis[i]-lis[i+2])
    if(m<k):
        num=num+m
    else:
        num=num+k
        i=i+1
print(num)
import sys
input = sys.stdin.readline
import numpy as np

N = int(input())
hight_list = np.array([int(item) for item in input().split()])

dp = np.full(N, hight_list.sum(), dtype='int64')

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

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

N = int(input())

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

dp = [INF] * N

dp[0] = 0


if N ==1:
    print(dp[0])
elif N == 2:
    dp[1] = h[1]-h[0]
    print(dp[1])
else:
    dp[1] = 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])
# 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-2]))

print(dp[N-1])
import sys
sample = sys.stdin.read().splitlines()
n, stones = int(sample[0]), list(map(int, sample[1].split()))
#print(n, stones)


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(n, stones)
n = int(input())
h = [int(i) for i in input().split()]

cost = [float("inf") for i in range(n)]
cost[:2] = 0, h[0]

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

print(cost[-1])
n = int(input())
h = list(map(int,input().split()))
dp = [int(1e+10) for _ in range(n)]
dp[0],dp[1] = 0,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()))
H = [0] + H
dp = [0] * (N+1)

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]))
res = dp[N]
print(res)
N = int(input())
a = [int(x) for x in input().split()]
def dp(N,a):
    F = [0]*(len(a)+1)
    F[0]=0
    F[1]=a[0]
    F[2]=abs(a[1]-a[0])
    if N == 1: return F[1]
    elif N == 2: return F[2]
    #F[3] = min(F[1]+abs(a[2]))
    for n in range(3,N+1):
        F[n] = min(F[n-1] + abs(a[n-1]-a[n-2]),F[n-2]+abs(a[n-1]-a[n-3]))
    print(F)
    return F[-1] 
print(dp(N,a))
N = int(input())
Array=list(map(int, input().split(' ')[:N]))
cp = 0
ts = 0
while(cp != N-1):
    try:
        if( Array[cp+1]<Array[cp+2]):
            ts += abs(Array[cp]- Array[cp+1])
            cp = cp+1
            
        else:
            ts += abs(Array[cp]- Array[cp+2])
            cp = cp+2
    except : 
        ts += abs(Array[cp]- Array[cp+1])
        cp = cp+1
    

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

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

else:
    print(abs(h[1]-h[0]))
a=int(input())
b=list(map(int,input().split()))

c=[0,abs(b[0]-b[1])]
for i in range(2,a):
  d=min(c[i-2]+abs(b[i-2]-b[i]),c[i-1]+abs(b[i-1]-b[i]))
  c.append(d)
print(c)
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 - 1]) - int(h[i])))
    if i > 1:
        chmin(dp, i, dp[i - 2] + abs(int(h[i - 2]) - int(h[i])))

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

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

dp = [1000000000]* len(hs)

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(min(limit_a, len(hs)-2)):
  
  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])
n = int(input())
h = list(map(int, input().split()))

dp = [0] * (n)
dp[0] = h[0]
dp[1] = abs(h[0]-h[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])
INF = 10 ** 4 + 10

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

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

def main():
  dp = [1e4]*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())
h = [int(x) for x in input().split()]

dp = [1000000 for _ in range(N)]
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    dp[i] = min(dp[i], dp[i] + abs(h[i] - h[i-1]))
    dp[i] = min(dp[i], dp[i] + abs(h[i] - h[i-2]))
print(dp[-1])
s=str(input())
t=str(input())
n,m=len(s),len(t)
ans=''
dp=[[0]*(m+1) for _ in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:
      dp[i+1][j+1]=max(dp[i][j]+1,dp[i+1][j+1])
    else:
      dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1])
while m>0 and n>0:
  if s[n-1]==t[m-1]:ans=s[n-1]+ans;n-=1;m-=1
  elif dp[n][m]==dp[n-1][m]:n-=1
  else:m-=1
print(ans)
n=int(input())
dp=[10000000]*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])
# 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(h[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+1)
dp[1]=0
dp[2]=abs(h[0]-h[1])
for i in range(3,n+1):
    dp[i]=min(dp[i-2]+abs(h[i-3]-h[i-1]),dp[i-1]+abs(h[i-2]-h[i-1]))
    print(dp)
print(dp[-1])
def solve():
    N = int(input())
    heights = map(int, input().split(" "))
    dp1 = 0
    dp2 = abs(heights[1] - heights[0])
    for i in range(2, N):
        tmp = dp2
        dp2 = min(
            dp2 + abs(heights[i] - heights[i-1]),
            dp1 + abs(heights[i] - heights[i-2])
        )
        dp1 = tmp
    print(dp2)
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]-h[i-1]))
  if i-2>=0:
    dp[i]=chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])
def cost_1(n, heights):
    if n == 1:
        return 0
    min_costs = [0] * n
    # Base case - First stone
    min_costs[0] = 0
    # Baze case - Second stone
    min_costs[1] = abs(heights[1] - heights[0])
    for i in range(2, n):
        min_costs[i] = min(
            abs(heights[i] - heights[i-2]) + min_costs[i-2],
            abs(heights[i] - heights[i-1]) + min_costs[i-1]
        )
    print(min_costs[-1])
n = int(input())
h = [int(x) for x in input().split()]
inf = float('inf')
dp = [inf] * n  # initialize dp
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(1, n):
    if 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])