from functools import lru_cache

import sys

sys.setrecursionlimit(20000000)

N = int(eval(input()))

heights = [int(h) for h in input().split()]





# heights = [10, 30, 40, 20]



# heights = [10, 10]

# heights = [30, 10, 60, 10, 60, 50]

# 记忆化

@lru_cache(None)

def dfs(i):

    if i == len(heights) - 1:

        return 0

    return min(abs(heights[i] - heights[i + 1]) + dfs(i + 1) if i + 1 < len(heights) else float("inf"),



               abs(heights[i] - heights[i + 2]) + dfs(i + 2) if i + 2 < len(heights) else float("inf"))





print((dfs(0)))

import sys

from functools import lru_cache



sys.setrecursionlimit(20000000)

N = int(eval(input()))

heights = [int(h) for h in input().split()]





# heights = [10, 30, 40, 20]



# heights = [10, 10]

# heights = [30, 10, 60, 10, 60, 50]

# 记忆化

@lru_cache(None)

def dfs(i):

    if i == len(heights) - 1:

        return 0

    return min(abs(heights[i] - heights[i + 1]) + dfs(i + 1) if i + 1 < len(heights) else float("inf"),



               abs(heights[i] - heights[i + 2]) + dfs(i + 2) if i + 2 < len(heights) else float("inf"))





def helper():

    dp = [float("inf")] * len(heights)

    dp[0] = 0

    for i in range(1, len(heights)):

        dp[i] = min(dp[i], dp[i - 1] + abs(heights[i] - heights[i - 1]))

        if i > 1:

            dp[i] = min(dp[i], dp[i - 2] + abs(heights[i] - heights[i - 2]))

    return dp[-1]





# print(dfs(0))

print((helper()))
from functools import lru_cache
import sys

sys.setrecursionlimit(20000000)
N = int(eval(input()))
heights = [int(h) for h in input().split()]
# heights = [10, 30, 40, 20]
# heights = [10, 10]
# heights = [30, 10, 60, 10, 60, 50]
# 记忆化
@lru_cache(None)
def dfs(i):
    if i == len(heights) - 1:
        return 0
    return min(
        abs(heights[i] - heights[i + 1]) + dfs(i + 1)
        if i + 1 < len(heights)
        else float("inf"),
        abs(heights[i] - heights[i + 2]) + dfs(i + 2)
        if i + 2 < len(heights)
        else float("inf"),
    )


print((dfs(0)))

import sys
from functools import lru_cache

sys.setrecursionlimit(20000000)
N = int(eval(input()))
heights = [int(h) for h in input().split()]
# heights = [10, 30, 40, 20]
# heights = [10, 10]
# heights = [30, 10, 60, 10, 60, 50]
# 记忆化
@lru_cache(None)
def dfs(i):
    if i == len(heights) - 1:
        return 0
    return min(
        abs(heights[i] - heights[i + 1]) + dfs(i + 1)
        if i + 1 < len(heights)
        else float("inf"),
        abs(heights[i] - heights[i + 2]) + dfs(i + 2)
        if i + 2 < len(heights)
        else float("inf"),
    )


def helper():
    dp = [float("inf")] * len(heights)
    dp[0] = 0
    for i in range(1, len(heights)):
        dp[i] = min(dp[i], dp[i - 1] + abs(heights[i] - heights[i - 1]))
        if i > 1:
            dp[i] = min(dp[i], dp[i - 2] + abs(heights[i] - heights[i - 2]))
    return dp[-1]


# print(dfs(0))
print((helper()))

+import sys -import sys -print((dfs(0))) +def helper(): +    dp = [float("inf")] * len(heights) +    dp[0] = 0 +    for i in range(1, len(heights)): +        dp[i] = min(dp[i], dp[i - 1] + abs(heights[i] - heights[i - 1])) +        if i > 1: +            dp[i] = min(dp[i], dp[i - 2] + abs(heights[i] - heights[i - 2])) +    return dp[-1] + + +# print(dfs(0)) +print((helper()))