N = int(eval(input()))

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

INF = 10**9

dp = [INF] * N

dp[0] = 0

for i in range(1, N):

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

    if i > 1:

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

print((dp[N-1]))
N = int(eval(input()))

h = [0] * (2*N)

h[:N] = list(map(int, input().split()))

INF = 10**9

dp = [INF] * (2*N)

dp[0] = 0

for i in range(N):

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

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

print((dp[N-1]))
N = int(eval(input()))
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(1, N):
    dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[N - 1]))

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

-h = list(map(int, input().split())) +h = [0] * (2 * N) +h[:N] = list(map(int, input().split())) -dp = [INF] * N +dp = [INF] * (2 * N) -for i in range(1, N): -    dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1])) -    if i > 1: -        dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2])) +for i in range(N): +    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1])) +    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))