n = int(eval(input()))

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

cost = [float('inf')] * n

cost[0] = 0

for i in range(n - 2):

  cost[i + 1] = min(cost[i + 1], cost[i] + abs(h[i + 1] - h[i]))

  cost[i + 2] = min(cost[i + 2], cost[i] + abs(h[i + 2] - h[i]))

cost[n - 1] = min(cost[n - 1], cost[n - 2] + abs(h[n - 1] - h[n - 2]))

print((cost[n - 1]))

n = int(eval(input()))

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

cost = [0] * n

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

for i in range(2, n):

  cost[i] = min(abs(h[i] - h[i - 1]) + cost[i - 1], abs(h[i] - h[i - 2]) + cost[i - 2])

print((cost[n - 1]))

n = int(eval(input()))
h = list(map(int, input().split()))
cost = [float("inf")] * n
cost[0] = 0
for i in range(n - 2):
    cost[i + 1] = min(cost[i + 1], cost[i] + abs(h[i + 1] - h[i]))
    cost[i + 2] = min(cost[i + 2], cost[i] + abs(h[i + 2] - h[i]))
cost[n - 1] = min(cost[n - 1], cost[n - 2] + abs(h[n - 1] - h[n - 2]))
print((cost[n - 1]))

n = int(eval(input()))
h = list(map(int, input().split()))
cost = [0] * n
cost[1] = abs(h[1] - h[0])
for i in range(2, n):
    cost[i] = min(
        abs(h[i] - h[i - 1]) + cost[i - 1], abs(h[i] - h[i - 2]) + cost[i - 2]
    )
print((cost[n - 1]))

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