CodeEff/ECCO huggingface dataset:
# Original solution
def getxy(P,x,y,ans):
	for dy in range(m):
		for dx in range(m):
			if P[dy][dx] > -1:
				xy = [x+dx+1,y+dy+1]
				if ans == "NA" or xy[1] < ans[1] or (xy[1] == ans[1] and xy[0] < ans[0]):
					return xy
				else:
					return ans

# try-except is necessary
while 1:
	try:
		n,m = list(map(int,input().split()))
		if n == 0: break
		S = [list(map(int,input().split())) for i in range(n)]
		P = [list(map(int,input().split())) for i in range(m)]

		ans = "NA"
		for rot in range(4):
			if S == P:
				ans = getxy(P,0,0,ans)
			for y in range(n-m+1):
				for x in range(n-m+1):
					flag = 0
					for dy in range(m):
						for dx in range(m):
							if P[dy][dx] > -1 and S[y+dy][x+dx] - P[dy][dx] != 0:
								flag = 1
								break
						if flag == 1: break
					if flag == 0:
						ans = getxy(P,x,y,ans)
						break
				if flag == 0: break
			P = [[P[j][i] for j in range(m-1,-1,-1)] for i in range(m)]
		print(ans if ans == "NA" else " ".join(map(str,ans)))
	except:
		pass

# Optimized solution
def getxy(P,x,y,ans):
	for dy in range(m):
		for dx in range(m):
			if P[dy][dx] > -1:
				xy = [x+dx+1,y+dy+1]
				if xy[1] < ans[1] or (xy[1] == ans[1] and xy[0] < ans[0]):
					return xy
				else:
					return ans

# try-except is necessary
while 1:
	try:
		n,m = list(map(int,input().split()))
		if n == 0: break
		S = [list(map(int,input().split())) for i in range(n)]
		P = [list(map(int,input().split())) for i in range(m)]
		ans = [n+1,n+1]
		for rot in range(4):
			for y in range(min(ans[1],n-m+1)):
				for x in range(n-m+1):
					flag = 0
					for dy in range(m):
						for dx in range(m):
							if P[dy][dx] > -1 and S[y+dy][x+dx] - P[dy][dx] != 0:
								flag = 1
								break
						if flag == 1: break
					if flag == 0:
						ans = getxy(P,x,y,ans)
						break
				if flag == 0: break
			P = [[P[j][i] for j in range(m-1,-1,-1)] for i in range(m)]
		print("NA" if ans == [n+1,n+1] else " ".join(map(str,ans)))
	except:
		pass
# Original solution
def main(piece, c):
    for h in range(n-m+1):
        for w in range(n-m+1):
            if f(piece, h, w):
                break
    if c != 4:
        move(piece, c)
    else:
        if ans:
            print(ans[0], ans[1])
        else:
            print('NA')

def f(piece, h, w):
    global ans
    coordinate = None
    for _h in range(m):
        for _w in range(m):
            if piece[_h][_w] != '-1':
                if piece[_h][_w] == picture[h+_h][w+_w]:
                    if coordinate is None:
                        coordinate = (int(w+_w+1), int(h+_h+1))
                        if ans:
                            if coordinate[1] > ans[1]:
                                return
                            elif coordinate[1] == ans[1]:
                                if coordinate[0] > ans[0]:
                                    return
                else:
                    return
    else:
        ans = coordinate
        return True
    
def move(piece, c):
    _piece = []
    for w in range(m):
        lis = []
        for h in range(m):
            lis.append(piece[h][w])
        else:
            lis.reverse()
            _piece.append(lis)
    else:
        main(_piece, c+1)

while True:
    n, m = list(map(int, input().split()))
    if n == m == 0: break
    picture = [input().split() for i in range(n)]
    piece = [input().split() for i in range(m)]
    ans = None
    main(piece, 1)

# Optimized solution
def main(piece, c):
    for h in range(n-m+1):
        for w in range(n-m+1):
            if f(piece, h, w):
                break
    if c != 4:
        move(piece, c)
    else:
        if ans:
            print(ans[0], ans[1])
        else:
            print('NA')

def f(piece, h, w):
    global ans
    coordinate = None
    for _h in range(m):
        for _w in range(m):
            if piece[_h][_w] != '-1':
                if piece[_h][_w] == picture[h+_h][w+_w]:
                    if coordinate is None:
                        coordinate = (int(w+_w+1), int(h+_h+1))
                else:
                    return
    else:
        if ans is None:
            ans = coordinate
        elif coordinate[1] < ans[1]:
            ans = coordinate
        elif coordinate[1] == ans[1]:
            if coordinate[0] < ans[0]:
                ans = coordinate
        return True
    
def move(piece, c):
    _piece = []
    for w in range(m):
        lis = []
        for h in range(m):
            lis.append(piece[h][w])
        else:
            lis.reverse()
            _piece.append(lis)
    else:
        main(_piece, c+1)

while True:
    n, m = list(map(int, input().split()))
    if n == m == 0: break
    picture = [input().split() for i in range(n)]
    piece = [input().split() for i in range(m)]
    ans = None
    main(piece, 1)
# Original solution
from functools import lru_cache
import sys

iMaxStackSize = 5000000
sys.setrecursionlimit(iMaxStackSize)
n = int(eval(input()))
heights = [int(x) for x in input().split()]

@lru_cache(None)
def solve(i):
    if i == n - 1:
        return 0
    if i + 2 >= len(heights):
        return abs(heights[i + 1] - heights[i])
    option1 = abs(heights[i] - heights[i + 1])
    option1 += solve(i + 1)
    option2 = abs(heights[i] - heights[i + 2])
    option2 += solve(i + 2)
    return min(option1, option2)

print((solve(0)))


# Optimized solution
n = int(eval(input()))
heights = [int(x) for x in input().split()]

dp = [float("inf")] * n
dp[0] = 0
for i in range(1, n):
    if i - 2 >= 0:
        val1 = abs(heights[i] - heights[i - 1]) + dp[i - 1]
        val2 = abs(heights[i] - heights[i - 2]) + dp[i - 2]
        dp[i] = min(val1, val2)
    else:
        dp[i] = abs(heights[i] - heights[i - 1]) + dp[i - 1]
print((dp[-1]))
# Original solution
n=int(eval(input()))
A=list(map(int,input().split()))
inf=float("inf")
dp=[inf for i in range(n)]
dp[0]=0
dp[1]=abs(A[1]-A[0])
for i in range(2,n):
	dp[i]=min(dp[i],abs(A[i-1]-A[i])+dp[i-1],abs(A[i-2]-A[i])+dp[i-2])
print((dp[n-1]))

# Optimized solution
n=int(eval(input()))
A=list(map(int,input().split()))
#dp[i]:=iにつくまでの最小コスト
dp=[1145141919810 for i in range(n)]
dp[0]=0
dp[1]=abs(A[0]-A[1])
for i in range(2,n):
  dp[i]=min(dp[i-2]+abs(A[i-2]-A[i]),dp[i-1]+abs(A[i-1]-A[i]))
print((dp[n-1]))
# Original solution
N = int(eval(input()))
High = list(map(int, input().split()))

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

print((DP[N-1]))

# Optimized solution
N = int(eval(input()))
H = [float('inf')] + list(map(int, input().split()))
DP = [0] * (N+1)

for i in range(2, 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]))
# 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):
    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 = [float('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 + 2 < n:
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print((dp[n - 1]))
# Original solution
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(eval(input()))
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

# # Top down
# def dp(current):
# 	if ans[current] != None: return ans[current]

# 	if current < 0: return 0
# 	else:
# 		t1 = t2 = int(1e9)
# 		if current-1 >= 0: t1 = abs(q[current] - q[current-1]) + dp(current-1)
# 		if current-2 >= 0: t2 = abs(q[current] - q[current-2]) + dp(current-2)

# 		ans[current] = min(t1, t2)
# 		return ans[current]

# dp(n-1)

for i in range(1, n):
	t1 = t2 = int(1e9)
	if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
	if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
	ans[i] = min(t1, t2)
# print(ans)
print((ans[n-1]))


# Optimized solution
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(eval(input()))
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

for i in range(1, n):
	t1 = t2 = int(1e9)
	if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
	if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
	ans[i] = min(t1, t2)

print((ans[n-1]))
# Original solution
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [0, abs(h[1] - h[0])]
for i in range(n - 2):
    a = dp[i] + abs(h[i + 2] - h[i])
    b = dp[i + 1] + abs(h[i + 2] - h[i + 1])
    dp.append(min(a, b))
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(n - 2):
    dp.append(min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 2] - h[i + 1])))
print((dp[-1]))
# Original solution
N = int(input())
h_str = input()
h = []
for h_i in h_str.split(" "):
    h.append(int(h_i))

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

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

dp = [10 ** 9 + 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]))
# Original solution
# coding: utf-8

def dp_flog(N, lst):
    lst_cost = [0] * N
    for i in range(N):
        if i==0:
            lst_cost[i]=0
        elif i==1:
            lst_cost[i] = abs(lst[0] - lst[1])
        else:
            lst_cost[i] = min(lst_cost[i-2] + abs(lst[i-2] - lst[i]), lst_cost[i-1] + abs(lst[i-1] - lst[i]))
    return lst_cost

N = int(eval(input()))
lst_flog = list(map(int, input().split()))
print((dp_flog(N, lst_flog)[N-1]))

# Optimized solution
# coding: utf-8

def dp_flog(N, lst):
    lst_cost = [0] * N
    lst_cost[1] = abs(lst[0] - lst[1])

    for i in range(2, N):
        lst_cost[i] = min(lst_cost[i-2] + abs(lst[i-2] - lst[i]), lst_cost[i-1] + abs(lst[i-1] - lst[i]))
    return lst_cost

N = int(eval(input()))
lst_flog = list(map(int, input().split()))
print((dp_flog(N, lst_flog)[N-1]))
# Original solution
# coding: utf-8

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

inf = pow(10, 10)

# current_shortests = [0] + [inf] * (n-1)

in_processing = [0]  # node-number
in_processing_len = [0]
shortest_fixed = []  # node-number
shortest_fixed_len = []


def argmin(l):
    output = 0
    for i in range(len(l)):
        if l[i] < l[output]:
            output = i

    return output


def search(l, v):
    for i in range(len(l)):
        if l[i] == v:
            return i


def fun():
    k = argmin(in_processing_len)
    node = in_processing[k]
    while node != n-1:

        # print("---------")
        # print(in_processing)
        # print(in_processing_len)
        # print(shortest_fixed)
        # print(shortest_fixed_len)
        # print(k)
        # print(node)
        # print("---------")

        # if node == n-1:
        #     return in_processing_len[k]

        shortest_fixed.append(node)
        shortest_fixed_len.append(in_processing_len[k])
        del in_processing[k]
        del in_processing_len[k]

        if node+1 < n and node+1 not in shortest_fixed:
            if node+1 not in in_processing:
                in_processing.append(node+1)
                in_processing_len.append(
                    shortest_fixed_len[-1] + abs(h[node+1] - h[node]))
            else:
                idx = search(in_processing, node+1)
                if in_processing_len[idx] > shortest_fixed_len[-1] + abs(h[node+1] - h[node]):
                    in_processing_len[idx] = shortest_fixed_len[-1] + abs(h[node+1] - h[node])
        if node+2 < n and node+2 not in shortest_fixed:
            if node+2 not in in_processing:
                in_processing.append(node+2)
                in_processing_len.append(
                    shortest_fixed_len[-1] + abs(h[node+2] - h[node]))
            else:
                idx = search(in_processing, node+2)
                if in_processing_len[idx] > shortest_fixed_len[-1] + abs(h[node+2] - h[node]):
                    in_processing_len[idx] = shortest_fixed_len[-1] + abs(h[node+2] - h[node])

        k = argmin(in_processing_len)
        node = in_processing[k]

    return in_processing_len[k]


print((fun()))


# Optimized solution
# coding: utf-8

"""
20191116
"""

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

cost = [0, abs(h[1]-h[0])] + [None for _ in range(N-2)]

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[N-1]))
# Original solution
n = int(eval(input()))
h = list(map(int, input().split()))

h.append(9999)
dp = [[0]*(n+1) for _ in range(n)]

def do_dp():
  for i in range(1,n):
    for j in range(n-1):
      #print("i:{} j:{}".format(i, j))
      if dp[i][j+1] == 0:
        dp[i][j+1] = dp[i-1][j] + abs(h[j] - h[j+1])
      else:
        dp[i][j+1] = min(dp[i][j+1],dp[i-1][j] + abs(h[j] - h[j+1]))
      if dp[i][j+2] == 0:
        dp[i][j+2] = dp[i-1][j] + abs(h[j] - h[j+2])
      else:
        dp[i][j+2] = min(dp[i][j+2],dp[i-1][j] + abs(h[j] - h[j+2]))
      #print(dp)
  return dp[n-1][n-1]
  
r = do_dp()
print(r)

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

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

if __name__ == '__main__':
    main()

# Optimized solution
def main():
    n = int(eval(input()))
    h = tuple(map(int, input().split()))
    dp = [0] * n
    dp[1] = abs(h[0] - h[1])

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

if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
dat_n = list(map(int, input().split()))
dp = [0] * n
dp [0]
for i in range(1, n):
    if i > 1:
        dp[i] = min(dp[i - 1] + abs(dat_n[i] - dat_n[i-1]),dp[i - 2] + abs(dat_n[i] - dat_n[i-2]) )
    else:
        dp[i] = dp[i - 1] + abs(dat_n[i] - dat_n[i-1])
print((dp[n-1]))


# Optimized solution
n = int(eval(input()))
dat = list(map(int, input().split()))
inf = 10**10
dp = [inf] * (n + 10)
dp[0] = 0
for i in range(n):
    if i+1 > n-1:
        continue
    dp[i+1] = min(dp[i+1], dp[i] + abs(dat[i] - dat[i+1]))
    if i+2 > n-1:
        continue
    dp[i+2] = min(dp[i+2], dp[i] + abs(dat[i] - dat[i+2]))
print((dp[n-1]))
# Original solution
import sys
sys.setrecursionlimit(10**5-10)

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

memo = [-1]*N

def func(i):
  # メモのロード
  if memo[i]!=-1:
    return memo[i]
  # 初期値の部分
  if i==0:
    return 0
  elif i==1: 
    return abs(h[1]-h[0])
  # 二択の部分
  a = func(i-1)+abs(h[i]-h[i-1])
  b = func(i-2)+abs(h[i]-h[i-2])
  memo[i] = min(a,b) # メモのセーブ
  return memo[i]

print((func(N-1)))


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

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

# dp[i][j]: 足場iまで見た時 jまでの最小コスト
dp = [[0 for j in range(n)] for i in range(n)]

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

for i in range(n):
    if i == 0 or i == 1:
        continue

    dp[i] = dp[i - 1]

    cost1jump = dp[i - 1][i - 1] + abs(h[i] - h[i - 1])
    cost2jump = dp[i - 1][i - 2] + abs(h[i] - h[i - 2])
    dp[i][i] = min(cost1jump, cost2jump)

print((dp[-1][-1]))


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

# dp[i][j]: 足場iまで見た時 jまでの最小コスト
dp = [0 for i in range(n)]

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

for i in range(n):
    if i == 0 or i == 1:
        continue

    cost1jump = dp[i - 1] + abs(h[i] - h[i - 1])
    cost2jump = dp[i - 2] + abs(h[i] - h[i - 2])
    dp[i] = min(cost1jump, cost2jump)

print((dp[-1]))
# Original solution
# EduDPA - Frog 1
n = int(eval(input()))
lst = list(map(int, input().rstrip().split()))
ans = [0] + [float("inf")] * (n - 1)
for i in range(1, n):
    ans[i] = min(ans[i], ans[i - 1] + abs(lst[i] - lst[i - 1]))
    
    if i == 1:
        continue
    ans[i] = min(ans[i], ans[i - 2] + abs(lst[i] - lst[i - 2]))

print((ans[-1]))

# Optimized solution
# EduDPA - Frog 1
n = int(eval(input()))
lst = list(map(int, input().rstrip().split()))
ans = [0, abs(lst[0] - lst[1])] + [float("inf")] * (n - 2)
for i in range(2, n):
    ans[i] = min(ans[i], ans[i - 1] + abs(lst[i] - lst[i - 1]))
    ans[i] = min(ans[i], ans[i - 2] + abs(lst[i] - lst[i - 2]))

print((ans[-1]))
# Original solution
# EduDPA - Frog 1
def main():
    n = int(eval(input()))
    A = tuple(map(int, input().rstrip().split()))
    dp = [0, abs(A[1] - A[0])] + [float("inf")] * (n - 2)
    for i in range(2, n):
        dif1 = dp[i - 2] + abs(A[i] - A[i - 2])
        dif2 = dp[i - 1] + abs(A[i] - A[i - 1])
        dp[i] = min(dif1, dif2)
    print((dp[-1]))


if __name__ == "__main__":
    main()

# Optimized solution
# dpA - Frog 1
def main():
    n = int(eval(input()))
    A = tuple(map(int, input().rstrip().split()))
    x, y = 0, abs(A[1] - A[0])
    for i in range(2, n):
        dif1 = x + abs(A[i] - A[i - 2])
        dif2 = y + abs(A[i] - A[i - 1])
        x, y = y, min(dif1, dif2)
    print(y)


if __name__ == "__main__":
    main()
# Original solution
# dpA - Frog 1
def main():
    n = int(eval(input()))
    A = tuple(map(int, input().rstrip().split()))
    x, y = 0, abs(A[1] - A[0])
    for i in range(2, n):
        dif1 = x + abs(A[i] - A[i - 2])
        dif2 = y + abs(A[i] - A[i - 1])
        x, y = y, min(dif1, dif2)
    print(y)


if __name__ == "__main__":
    main()

# Optimized solution
# dpA - Frog 1
"""
Example:
x y
  x y
    x y ...
        x y (y: answer)
"""
def main():
    n = int(eval(input()))
    A = tuple(map(int, input().split()))
    x, y = 0, abs(A[1] - A[0])
    for i in range(2, n):
        dif1 = x + abs(A[i] - A[i - 2])
        dif2 = y + abs(A[i] - A[i - 1])
        x = y
        y = dif1 if dif1 <= dif2 else dif2
    print(y)


if __name__ == "__main__":
    main()
# Original solution
# A - Frog 1
from collections import defaultdict


def main():
    N, *H = list(map(int, open(0).read().split()))
    H = [0] + H + [0, 0]
    dp = defaultdict(lambda: 1 << 30)
    dp[1] = 0
    for i, a in enumerate(H[1:N + 1], 1):
        for j, b in enumerate(H[i + 1:i + 3], i + 1):
            dp[j] = min(dp[j], dp[i] + abs(a - b))
    print((dp[N]))


if __name__ == "__main__":
    main()


# Optimized solution
# A - Frog 1
def main():
    N, *H = list(map(int, open(0).read().split()))
    H = [0] + H + [0, 0]
    dp = [1 << 30] * (N + 3)
    dp[1] = 0
    for i, a in enumerate(H[1:N + 1], 1):
        for j, b in enumerate(H[i + 1:i + 3], i + 1):
            dp[j] = min(dp[j], dp[i] + abs(a - b))
    print((dp[N]))


if __name__ == "__main__":
    main()
# Original solution
N = int(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):
  dp[i+1] = min(dp[i+1],dp[i] + abs(h[i+1]-h[i]))
  if i < N-2:
    dp[i+2] = min(dp[i+2],dp[i] + abs(h[i+2]-h[i]))
print((dp[N-1]))
  

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
ans = [float('inf')]*N
ans[0] = 0
ans[1] = abs(A[0]-A[1])
for i in range(2,N):
  ans[i] = min(ans[i-1]+abs(A[i]-A[i-1]), ans[i-2]+abs(A[i]-A[i-2]))
print((ans[N-1]))
# Original solution
n = int(eval(input()))
hl = list(map(int, input().split()))

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

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


print((cost[-1]))

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

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

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

print((cost[-1]))
# Original solution
def main():
    n = int(eval(input()))
    h = [int(i) for i in input().split()]
    cost = [0 for _ in range(n)]
    cost[0] = 0
    cost[1] = abs(h[1] - 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]))
main()


# Optimized solution
def main():
    n = int(eval(input()))
    h = tuple(map(int, input().split()))
    cost = [0 for _ in range(n)]
    cost[0] = 0
    cost[1] = abs(h[1] - 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]))
main()
# Original solution
n = int(eval(input()))
H = [int(h)for h in input().split()]
A = [0]*n

A[0] = 0
A[1] = abs(H[1]-H[0])

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

print((A.pop()))


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

C = [0]*(n)

for i in range(1, n):
  if i == 1:
    C[i] = abs(H[i]-H[i-1])
  else:
    C[i] = min(C[i-1]+abs(H[i]-H[i-1]), C[i-2]+abs(H[i]-H[i-2]))
  
print((C.pop()))
# Original solution
n = int(eval(input()))
H = list(map(int, input().split()))

C = [0]*(n)

for i in range(1, n):
  if i == 1:
    C[i] = abs(H[i]-H[i-1])
  else:
    C[i] = min(C[i-1]+abs(H[i]-H[i-1]), C[i-2]+abs(H[i]-H[i-2]))
  
print((C.pop()))

# Optimized solution
n = int(eval(input()))
H = [0]+list(map(int, input().split()))
dp = [0]*(n+1)
dp[2] = abs(H[2]-H[1])

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[-1]))
# Original solution
from sys import stdin

input=stdin.readline

n=int(eval(input()))

cost=[0 for i in range(n)]

s=list(map(int,input().split()))
cost[1]=abs(s[1]-s[0])

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

print((cost[-1]))


# Optimized solution
n=int(eval(input()))

cost=[0 for i in range(n)]

s=list(map(int,input().split()))
cost[1]=abs(s[1]-s[0])

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

print((cost[-1]))
# Original 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-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))

print((dp[n-1]))

# Optimized solution
import sys
input = sys.stdin.readline

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(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
print((dp[-1]))
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(eval(input()))
H = [int(x) for x in input().split()]

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

answer = dp[-1]
print(answer)

# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*H = list(map(int,read().split()))

dp = [0]*N
for i in range(1,N):
    x = dp[i-1] + abs(H[i]-H[i-1])
    if i > 1:
        y = dp[i-2] + abs(H[i]-H[i-2])
        if x>y: x=y
    dp[i] = x

answer = dp[-1]
print(answer)