import sys

# import pdb

input = sys.stdin.readline



N = int(eval(input()))

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



dp_list = [-1 for _ in range(N)]

dp_list[0] = 0

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



sys.setrecursionlimit(1000000)

def dp_memo(p):

  if dp_list[p] != -1:

    return dp_list[p]



  result = min(dp_memo(p-1) + abs(hs[p] - hs[p-1]), dp_memo(p-2) + abs(hs[p] - hs[p-2]))

  dp_list[p] = result

  return result





def dp_recur():

  cost1 = 0

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



  if N == 2:

    print(cost2)

    exit()

  # pdb.set_trace()

  for i in range(2, N):

    cost3 = min(cost2 + abs(hs[i] - hs[i-1]), cost1 + abs(hs[i] - hs[i-2]))

    cost1 = cost2

    cost2 = cost3

  return cost3



# print(dp_recur())

print((dp_memo(N-1)))

N = int(eval(input()))

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



if N == 2:

  print((abs(hs[1] - hs[0])))

  exit()



total_cost = [-1 for _ in range(N)]

total_cost[0] = 0

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



for i in range(2, N):

  total_cost[i] = min(abs(hs[i]-hs[i-1]) + total_cost[i-1], abs(hs[i]-hs[i-2]) + total_cost[i-2])



print((total_cost[N-1]))

import sys

# import pdb
input = sys.stdin.readline
N = int(eval(input()))
hs = list(map(int, input().split()))
dp_list = [-1 for _ in range(N)]
dp_list[0] = 0
dp_list[1] = abs(hs[1] - hs[0])
sys.setrecursionlimit(1000000)


def dp_memo(p):
    if dp_list[p] != -1:
        return dp_list[p]
    result = min(
        dp_memo(p - 1) + abs(hs[p] - hs[p - 1]), dp_memo(p - 2) + abs(hs[p] - hs[p - 2])
    )
    dp_list[p] = result
    return result


def dp_recur():
    cost1 = 0
    cost2 = abs(hs[1] - hs[0])
    if N == 2:
        print(cost2)
        exit()
    # pdb.set_trace()
    for i in range(2, N):
        cost3 = min(cost2 + abs(hs[i] - hs[i - 1]), cost1 + abs(hs[i] - hs[i - 2]))
        cost1 = cost2
        cost2 = cost3
    return cost3


# print(dp_recur())
print((dp_memo(N - 1)))

N = int(eval(input()))
hs = list(map(int, input().split()))
if N == 2:
    print((abs(hs[1] - hs[0])))
    exit()
total_cost = [-1 for _ in range(N)]
total_cost[0] = 0
total_cost[1] = abs(hs[1] - hs[0])
for i in range(2, N):
    total_cost[i] = min(
        abs(hs[i] - hs[i - 1]) + total_cost[i - 1],
        abs(hs[i] - hs[i - 2]) + total_cost[i - 2],
    )
print((total_cost[N - 1]))

-import sys - -# import pdb -input = sys.stdin.readline -dp_list = [-1 for _ in range(N)] -dp_list[0] = 0 -dp_list[1] = abs(hs[1] - hs[0]) -sys.setrecursionlimit(1000000) - - -def dp_memo(p): -    if dp_list[p] != -1: -        return dp_list[p] -    result = min( -        dp_memo(p - 1) + abs(hs[p] - hs[p - 1]), dp_memo(p - 2) + abs(hs[p] - hs[p - 2]) +if N == 2: +    print((abs(hs[1] - hs[0]))) +    exit() +total_cost = [-1 for _ in range(N)] +total_cost[0] = 0 +total_cost[1] = abs(hs[1] - hs[0]) +for i in range(2, N): +    total_cost[i] = min( +        abs(hs[i] - hs[i - 1]) + total_cost[i - 1], +        abs(hs[i] - hs[i - 2]) + total_cost[i - 2], -    dp_list[p] = result -    return result - - -def dp_recur(): -    cost1 = 0 -    cost2 = abs(hs[1] - hs[0]) -    if N == 2: -        print(cost2) -        exit() -    # pdb.set_trace() -    for i in range(2, N): -        cost3 = min(cost2 + abs(hs[i] - hs[i - 1]), cost1 + abs(hs[i] - hs[i - 2])) -        cost1 = cost2 -        cost2 = cost3 -    return cost3 - - -# print(dp_recur()) -print((dp_memo(N - 1))) +print((total_cost[N - 1]))