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

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

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

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

-dp = [1e9] * n +dp = [1e9 for _ in range(n)] +# dp[i]...コストの最小 -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])) +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]))