CodeEff/ECCO huggingface dataset:
# Original solution
"""
k=int(input())
a=list(map(int,input().split()))
if k==1:
    print(0)
else:
    dp = [0] * k
    dp[1] = abs(a[0]-a[1])
    for i in range(2,k):
        dp[i]=min(
            dp[i-1]+abs(a[i]-a[i-1]),
            dp[i-2]+abs(a[i]-a[i-2])
        )
    print(dp[-1])
"""
from collections import deque
n=int(eval(input()))
cost=list(map(int,input().split()))
if n==1:
    print((0))
else:
    # if we reach early step faster then terminate which makes more sense
    ways = [1, 2]
    ways.sort(reverse=True)
    q = deque([(0, 0)])  # path,cost
    min_cost = float('inf')
    explore_more = 1
    while q:
        # print(q)
        for _ in range(len(q)):
            path, cost_ = q.popleft()
            if path == n - 1:
                min_cost = min(min_cost, cost_)
                explore_more = 0
            if explore_more:
                for way in ways:
                    if path + way < n:
                        q.append((path + way, cost_ + abs(cost[path] - cost[path + way])))

    print(min_cost)




# Optimized solution
n=int(eval(input()))
cost=list(map(int,input().split()))
dp=[float('inf')]*n
dp[0]=0
for i in range(n):
    for j in [i+1,i+2]:
        if j<n:
            dp[j] = min(dp[j], dp[i] + abs(cost[i] - cost[j]))
print((dp[n-1]))
# Original solution
inf = float('inf')

n = int(eval(input()))
h = list(map(int, input().split())) + [inf]

dp = [inf] * (n + 1)
dp[0] = 0

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


# Optimized solution
def main():
    import sys
    readline = sys.stdin.readline

    inf = 10 ** 9

    n = int(readline())
    *h, = list(map(int, readline().split()))
    h = [inf] + h + [inf]  # 1-indexed化

    dp = [inf] * (n + 2)
    dp[0] = 0
    dp[1] = 0

    for i in range(1, n):  # ジャンプ元,1-indexed
        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]))


if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
h = list(map(int, input().split()))

dp = [1000000000] * 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]))



# Optimized solution
n = int(eval(input()))
h = list(map(int, input().split()))

INF = 1000000000
#最小値(コスト)を求める問題のため、DP配列を無限大に初期化
dp = [INF] * (n + 1)
#0番目の地点はコスト0
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]))
# Original solution
n=int(eval(input()))
h=list(map(int,input().split()))

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


# Optimized solution
n=int(eval(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):
      dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print((dp[-1]))
# Original solution
n=int(eval(input()))
a=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(a[i]-a[i-1]))
    if i==1:
        continue
    dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2])) 
print((dp[n-1]))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
dp=[float('inf')]*n
dp[0]=0
for i in range(1,n):
    dp[i]=min(dp[i],dp[i-1]+abs(a[i]-a[i-1]))
    if i==1:
        continue
    dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]))
print((dp[-1]))
# Original solution
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(eval(input()))

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

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

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

print((dp[N - 1]))


# Optimized solution
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(eval(input()))

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

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

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

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

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

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

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

print((dp[N - 1]))


# Optimized solution
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(eval(input()))

def main():
    N = gete(int)
    h = geta(int)

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

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

    print((dp[N - 1]))


if __name__ == "__main__":
    main()
# Original solution
def main(N, h):
    dp = [2**31-1] * N
    dp[0] = 0
    for i in range(N):
        if i+1 <= N-1:
            dp[i+1] = min(dp[i+1], dp[i] + (abs(h[i+1] - h[i])))
        if i+2 <= N-1:
            dp[i+2] = min(dp[i+2], dp[i] + (abs(h[i+2] - h[i])))
    return dp[-1]

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

# Optimized solution
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
N = I()
h = LI()
dp = [float('INF')]*N
dp[0],dp[1] = 0,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]))
# Original solution
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(list(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]))


# Optimized solution
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 = LI()
dp = [float('INF')]*N
dp[0] = 0
for i in range(N):
    if i-1>=0:
        dp[i] = min(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
    if i-2>=0:
        dp[i] = min(dp[i],dp[i-2]+abs(h[i]-h[i-2]))
print((dp[-1]))
# Original solution
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 = LI()
dp = [float('INF')]*N
dp[0] = 0
for i in range(N):
    if i-1>=0:
        dp[i] = min(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
    if i-2>=0:
        dp[i] = min(dp[i],dp[i-2]+abs(h[i]-h[i-2]))
print((dp[-1]))

# Optimized solution
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
h = LI()
dp = [float('INF')]*N
dp[0] = 0
for i in range(N):
    if i-1>=0:
        dp[i] = min(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
    if i-2>=0:
        dp[i] = min(dp[i],dp[i-2]+abs(h[i]-h[i-2]))
print((dp[-1]))
# Original solution
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
h = LI()
dp = [float('INF')]*N
dp[0] = 0
for i in range(N):
    if i+1<=N-1:
        dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
    if i+2<=N-1:
        dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
print((dp[-1]))


# Optimized solution
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 = LI()
dp = [float('INF')]*N
dp[0] = 0
for i,j in itertools.product(list(range(N)),[1,2]):
    if i+j<=N-1:
        dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))
print((dp[-1]))
# Original solution
n = int(eval(input()))
h = list(map(int,input().split()))
dp = [0 for i in range(n)]

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

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

print((dp[n-1]))

# Optimized solution
n = int(eval(input()))
H = list(map(int,input().split()))
dp = [0]*(len(H))
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]))
# Original solution
n = int(eval(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-2]),dp[i-1]+abs(H[i]-H[i-1]))
print((dp[-1]))

# Optimized solution
N = int(eval(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]))
# Original solution
import sys
sys.setrecursionlimit(10**9)

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

memo = [-1]*N

def calc_cost(i):
  if memo[i] != -1:
    return memo[i]
  
  if i == 0:
    return 0
  elif i == 1:
    return abs(h[0]-h[1])
  
  a = calc_cost(i-1)+abs(h[i]-h[i-1])
  b = calc_cost(i-2)+abs(h[i]-h[i-2])
  
  memo[i] = min(a,b)
  return(memo[i])

print((calc_cost(N-1)))

# Optimized solution
import sys
sys.setrecursionlimit(10**6)

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

memo = [-1]*N

def calc_cost(i):
  if memo[i] != -1:
    return memo[i]
  
  if i == 0:
    return 0
  elif i == 1:
    return abs(h[0]-h[1])
  
  a = calc_cost(i-1)+abs(h[i]-h[i-1])
  b = calc_cost(i-2)+abs(h[i]-h[i-2])
  
  memo[i] = min(a,b)
  return(memo[i])

print((calc_cost(N-1)))
# Original solution
#coding: utf-8
N = int(eval(input()))
a = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(1, N):
    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[N-1]))


# Optimized solution
#coding: utf-8
N = int(eval(input()))
h = list(map(int, input().split()))
dp = [float("inf") for _ 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]))
    dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
print((dp[N-1]))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
dp = [1e9]*n
dp[0] = 0
for i in range(1, n):
  dp[i] = min(dp[i], dp[i-1] + abs(a[i] - a[i-1]))
  if i > 1:
    dp[i] = min(dp[i], dp[i-2] + abs(a[i] - a[i-2]))
print((dp[n-1]))


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
dp = [1e9 for _ in range(n)]
#dp[i]...コストの最小
dp[0] = 0
dp[1] = abs(a[1] - a[0])
for i in range(n-2):
  dp[i+2] = min(dp[i+1] + abs(a[i+2] - a[i+1]), dp[i] + abs(a[i+2] - a[i]))
print((dp[n-1]))
# Original solution
n = int(eval(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] = dp[0] + 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]))

# Optimized solution
n=int(eval(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]))
# Original solution
n=int(eval(input()))
l=list(map(int,input().split()))
dp=[0 for _ in range(n)]
dp[1]=abs(l[1]-l[0])

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

print((dp[n-1]))

# Optimized solution
n=int(eval(input()))
H=list(map(int,input().split()))
dp=[10**9]*n
dp[0]=0
dp[1]=abs(H[1]-H[0])
for i in range(2,n):
    step1=dp[i-1]+abs(H[i]-H[i-1])
    step2=dp[i-2]+abs(H[i]-H[i-2])
    dp[i]=min(step1,step2)
print((dp[-1]))
# Original solution
n = int(eval(input()))
hs = list(map(int, input().split()))
dp = [0]*n

# cost1 = dp[i-1] + abs(dp[i-1]-dp[i])
# cost2 = dp[i-2] + abs(dp[i-2]-dp[i])
# dp[i] = min(cost1, cost2)

#for i in reversed(range(n)):
for i in range(n):
    if i == 0:
        dp[0] = 0
    elif i == 1:
        dp[1] = abs(hs[0]-hs[1])
    else:
        cost1 = dp[i-1] + abs(hs[i-1]-hs[i])
        cost2 = dp[i-2] + abs(hs[i-2]-hs[i])
        dp[i] = min(cost1, cost2)

print((dp[n-1]))

# Optimized solution
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [0]*n

for i in range(n):
    if i == 0:
        dp[0] = 0
    elif i == 1:
        dp[1] = abs(h[0]-h[1])
    else:
        cost1 = dp[i-1] + abs(h[i-1]-h[i])
        cost2 = dp[i-2] + abs(h[i-2]-h[i])
        dp[i] = min(cost1, cost2)

print((dp[n-1]))
# Original solution
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [[None] * 10**6 for _ in range(n)]

def solve(idx, cost):
    if dp[idx][cost] is not None:
        return dp[idx][cost]

    if idx == n - 1:
        return cost

    if idx == n - 2:
        return solve(idx + 1, cost + abs(h[idx] - h[idx+1]))

    c1 = solve(idx + 1, cost + abs(h[idx] - h[idx + 1]))
    c2 = solve(idx + 2, cost + abs(h[idx] - h[idx + 2]))

    dp[idx][cost] = min(c1, c2)
    return dp[idx][cost]

    # return min(c1, c2)

ans = solve(0, 0)

print(ans)

# Optimized solution
import sys
sys.setrecursionlimit(10**6)

n = int(eval(input()))
h = list(map(int, input().split()))
# dp = [[None] * 10**6 for _ in range(n)]
dp = [None] * (n+1)

# Return the smallest cost to reach the idx
def solve(idx):
    if dp[idx] is not None:
        return dp[idx]

    if idx == 1:
        dp[idx] = abs(h[idx] - h[idx - 1])
    elif idx == 0:
        dp[idx] = 0
    else:
        # jump from idx - 1
        c1 = solve(idx - 1) + abs(h[idx] - h[idx - 1])

        # jump from idx - 2
        c2 = solve(idx - 2) + abs(h[idx] - h[idx - 2])

        dp[idx] = min(c1, c2)

    return dp[idx]

ans = solve(n-1)

print(ans)
# Original solution
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [[None] * 10**6 for _ in range(n)]

def solve(idx, cost):
    if dp[idx][cost] is not None:
        return dp[idx][cost]

    if idx == n - 1:
        return cost

    if idx == n - 2:
        return solve(idx + 1, cost + abs(h[idx] - h[idx+1]))

    c1 = solve(idx + 1, cost + abs(h[idx] - h[idx + 1]))
    c2 = solve(idx + 2, cost + abs(h[idx] - h[idx + 2]))

    dp[idx][cost] = min(c1, c2)
    return dp[idx][cost]

    # return min(c1, c2)

ans = solve(0, 0)

print(ans)

# Optimized solution
import sys
sys.setrecursionlimit(10**6)

N = int(eval(input()))
h = list(map(int, input().split()))
dp = [None] * N

def solve(idx):
    if dp[idx] is not None:
        return dp[idx]

    if idx == N - 1:
        dp[idx] = 0
        # return 0
    elif idx == N - 2:
        dp[idx] = abs(h[idx] - h[idx + 1])
        # return abs(h[idx] - h[idx + 1])
    else:
        # Jump 1
        v1 = solve(idx + 1) + abs(h[idx] - h[idx + 1])

        # Jump 2
        v2 = solve(idx + 2) + abs(h[idx] - h[idx + 2])

        dp[idx] = min(v1, v2)

    return dp[idx]

print((solve(0)))
# Original solution
N = int(eval(input()))
h = list(map(int, input().split()))
 
DP = [0, abs(h[0]-h[1])]
for i in range(N-2):
    DP += [min(DP[-2] + abs(h[i]-h[i+2]), DP[-1] + abs(h[i+1]-h[i+2]))]
 
print((DP[-1]))

# Optimized solution
n = int(eval(input()))
h = list(map(int, input().split()))

dp = [0, abs(h[1]-h[0])]
for i in range(2, n):
  dp.append(min(dp[-2]+abs(h[i]-h[i-2]), dp[-1]+abs(h[i]-h[i-1])))
print((dp[-1]))
# Original solution
import sys
sys.setrecursionlimit(20000000)
n=int(eval(input()))
h=list(map(int,input().split()))
def cost(place):
    if place==n-1:
        return 0
    if place==n-2:
        return abs(h[n-2]-h[n-1])
    if place<=n-3:
        a=abs(h[place]-h[place+2])+cost(place+2)
        b=abs(h[place]-h[place+1])+cost(place+1)
        x=min(a,b)
        return x
print((cost(0)))


# Optimized solution
import sys
sys.setrecursionlimit(20000000)
n=int(eval(input()))
h=list(map(int,input().split()))
memory={}
def cost(place):
    if place in memory:
        return memory[place]
    if place==n-1:
        return 0
    if place==n-2:
        return abs(h[n-2]-h[n-1])
    if place<=n-3:
        a=abs(h[place]-h[place+2])+cost(place+2)
        b=abs(h[place]-h[place+1])+cost(place+1)
        x=min(a,b)
        memory[place]=x
        return x
print((cost(0)))
# Original solution
import sys
sys.setrecursionlimit(20000000)
n=int(eval(input()))
h=list(map(int,input().split()))
memory={}
def cost(place):
    if place in memory:
        return memory[place]
    if place==n-1:
        return 0
    if place==n-2:
        return abs(h[n-2]-h[n-1])
    if place<=n-3:
        a=abs(h[place]-h[place+2])+cost(place+2)
        b=abs(h[place]-h[place+1])+cost(place+1)
        x=min(a,b)
        memory[place]=x
        return x
print((cost(0)))


# Optimized solution
n=int(eval(input()))
h=[int(i) for i in input().split()]
p0=0
p1=abs(h[1]-h[0])
for i in range(2,n):
    p2=min(abs(h[i]-h[i-2])+p0,abs(h[i]-h[i-1])+p1)
    p0,p1=p1,p2
print(p1)
# Original solution
N=eval(input())
H=list(map(int, input().split()))

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

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

print(dp[N-1])


# Optimized solution
N=eval(input())
H=list(map(int, input().split()))

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

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

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

dp = [10**10] * 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]))



# Optimized solution
N = int(eval(input()))
h = list(map(int, input().split()))

dp = [10**10] * 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]))
# Original solution
N=int(eval(input()))
*H,=list(map(int,input().split()))

D=[10**4*N]*N

D[0]=0
for i in range(N):
    if 1<=i:
        #print(i,H[i],H[i-1],abs(H[i]-H[i-1]))
        D[i]=min(D[i],abs(H[i]-H[i-1])+D[i-1])
    if 2<=i:
        #print(i,H[i],H[i-2],abs(H[i]-H[i-2]))
        D[i]=min(D[i],abs(H[i]-H[i-2])+D[i-2])
print((D[-1]))

# Optimized solution
N=int(eval(input()))
*H,=list(map(int,input().split()))
D=[-1]*N
D[0]=0
D[1]=abs(H[1]-H[0])
for i in range(2,N):
    D[i]=min(abs(H[i]-H[i-1])+D[i-1],abs(H[i]-H[i-2])+D[i-2])
print((D[-1]))
# Original solution
n=int(eval(input()))
K=list(map(int,input().split()))

dp=[float('inf') for _ in range(n)]
dp[0]=0
for i in range(len(K)-1):
  dp[i+1]=min(dp[i+1],dp[i]+abs(K[i]-K[i+1]))
  if i+2<len(K):
    dp[i+2]=min(dp[i+2],dp[i]+abs(K[i]-K[i+2]))
print((dp[-1]))

# Optimized solution
n=int(eval(input()))
H=list(map(int,input().split()))

dp=[float('inf')]*n
dp[0]=0
dp[1]=abs(H[1]-H[0])
for i in range(2,n):
  dp[i]=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]))
# Original solution
n = int(eval(input()))
initial_vals = list(map(int, input().split(" ")))


table = [[None for x in range(n)] for x in range(n)]


def calc(from_stone, to_stone):
    if table[from_stone][to_stone] is not None:
        return table[from_stone][to_stone]
    elif (to_stone - from_stone) == 1:
        table[from_stone][to_stone] = abs(
            initial_vals[from_stone] - initial_vals[to_stone]
        )
        return table[from_stone][to_stone]
    elif (to_stone - from_stone) == 2:
        table[from_stone][to_stone] = min(
            abs(initial_vals[from_stone] - initial_vals[to_stone - 1])
            + abs(initial_vals[to_stone - 1] - initial_vals[to_stone]),
            abs(initial_vals[from_stone] - initial_vals[to_stone]),
        )
        return table[from_stone][to_stone]
    else:
        table[from_stone][to_stone] = min(
            calc(from_stone, to_stone - 1) + calc(to_stone - 1, to_stone),
            calc(from_stone, to_stone - 2) + calc(to_stone - 2, to_stone),
        )
        return table[from_stone][to_stone]


print((calc(0, n - 1)))


# Optimized solution
n = int(eval(input()))
initial_vals = list(map(int, input().split(" ")))


# print(calc(0, n - 1))


arr = [0 for x in range(n)]

arr[1] = abs(initial_vals[0] - initial_vals[1])

for i in range(2, len(arr)):
    arr[i] = min(
        arr[i - 1] + abs(initial_vals[i - 1] - initial_vals[i]),
        arr[i - 2] + abs(initial_vals[i - 2] - initial_vals[i]),
    )

print((arr[n - 1]))
# Original solution
n = int(eval(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(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]))

# Optimized solution
n = int(eval(input()))
h = [0] + list(map(int, input().split()))

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

for i in range(3, 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[n]))
# Original solution
n = int(eval(input()))
h = [0] + list(map(int, input().split()))

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

for i in range(3, 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[n]))

# Optimized solution
n = int(eval(input()))
h = list(map(int, input().split()))

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

dp = [float('inf')] * 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 > 1:
        dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[n-1]))
# Original solution
import sys
sys.setrecursionlimit(200000)
 
n = int(eval(input()))
 
h = [int(i) for i in input().split()]
 
def dp(cost, p):
  if p == n-1:
    return cost
  if p < n-2:
    return min(dp(cost+abs(h[p]-h[p+1]), p+1), dp(cost+abs(h[p]-h[p+2]), p+2))
  if p == n-2:
    return dp(cost+abs(h[p]-h[p+1]), p+1)

print((dp(0, 0)))

# Optimized solution
import sys
sys.setrecursionlimit(200000)
 
n = int(eval(input()))
 
h = [int(i) for i in input().split()]
 
d = {}
 
def dp(p):
  if p in d:
    return d[p]
  if p == n-1:
    return 0
  if p < n-2:
    m = min(dp(p+1)+abs(h[p]-h[p+1]), dp(p+2)+abs(h[p]-h[p+2]))
    d[p] = m
    return m
  if p == n-2:
    return dp(p+1)+abs(h[p]-h[p+1])

print((dp(0)))
# Original solution
import sys
sys.setrecursionlimit(200000)
 
n = int(eval(input()))
 
h = [int(i) for i in input().split()]
 
d = {}
 
def dp(p):
  if p in d:
    return d[p]
  if p == n-1:
    return 0
  if p < n-2:
    m = min(dp(p+1)+abs(h[p]-h[p+1]), dp(p+2)+abs(h[p]-h[p+2]))
    d[p] = m
    return m
  if p == n-2:
    return dp(p+1)+abs(h[p]-h[p+1])

print((dp(0)))


# Optimized solution
n = int(eval(input()))
h = list(map(int, input().split()))

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

print((dp[-1]))