import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)



INF = 10 ** 10



n = int(eval(input()))

# 貰うDPだと0へのアクセスが、配るDPだとn+1へのアクセスが必要になる

h = [INF] + list(map(int, input().split())) + [INF]

dp = [INF] + [INF] * n + [INF]

dp[1] = 0



def chmin(dp_table, index, value):

    if dp_table[index] > value:

        dp_table[index] = value



# 再帰(DFS) (メモ化あり: テーブル使用)

def dfs(i):

    if i == 0:

        return INF

    if i == 1:

        return 0

    if dp[i] != INF:

        return dp[i]



    ans = INF

    prev_cost = dfs(i-1)

    if ans > prev_cost + abs(h[i] - h[i-1]):

        ans = prev_cost + abs(h[i] - h[i-1])

    prev_cost = dfs(i-2)

    if ans > prev_cost + abs(h[i] - h[i-2]):

        ans = prev_cost + abs(h[i] - h[i-2])



    dp[i] = ans

    return dp[i]



print((dfs(n)))

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)



INF = 10 ** 20

n = int(eval(input()))

h = [INF] + list(map(int, input().split())) + [INF]



dp = [INF] + [INF] * n + [INF]

dp[1] = 0



for i in range(1, n):

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

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**10
n = int(eval(input()))
# 貰うDPだと0へのアクセスが、配るDPだとn+1へのアクセスが必要になる
h = [INF] + list(map(int, input().split())) + [INF]
dp = [INF] + [INF] * n + [INF]
dp[1] = 0


def chmin(dp_table, index, value):
    if dp_table[index] > value:
        dp_table[index] = value


# 再帰(DFS) (メモ化あり: テーブル使用)
def dfs(i):
    if i == 0:
        return INF
    if i == 1:
        return 0
    if dp[i] != INF:
        return dp[i]
    ans = INF
    prev_cost = dfs(i - 1)
    if ans > prev_cost + abs(h[i] - h[i - 1]):
        ans = prev_cost + abs(h[i] - h[i - 1])
    prev_cost = dfs(i - 2)
    if ans > prev_cost + abs(h[i] - h[i - 2]):
        ans = prev_cost + abs(h[i] - h[i - 2])
    dp[i] = ans
    return dp[i]


print((dfs(n)))

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**20
n = int(eval(input()))
h = [INF] + list(map(int, input().split())) + [INF]
dp = [INF] + [INF] * n + [INF]
dp[1] = 0
for i in range(1, n):
    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]))

-INF = 10**10 +INF = 10**20 -# 貰うDPだと0へのアクセスが、配るDPだとn+1へのアクセスが必要になる - - -def chmin(dp_table, index, value): -    if dp_table[index] > value: -        dp_table[index] = value - - -# 再帰(DFS) (メモ化あり: テーブル使用) -def dfs(i): -    if i == 0: -        return INF -    if i == 1: -        return 0 -    if dp[i] != INF: -        return dp[i] -    ans = INF -    prev_cost = dfs(i - 1) -    if ans > prev_cost + abs(h[i] - h[i - 1]): -        ans = prev_cost + abs(h[i] - h[i - 1]) -    prev_cost = dfs(i - 2) -    if ans > prev_cost + abs(h[i] - h[i - 2]): -        ans = prev_cost + abs(h[i] - h[i - 2]) -    dp[i] = ans -    return dp[i] - - -print((dfs(n))) +for i in range(1, n): +    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]))