n = int(eval(input()))



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



dp = [0] * n



dp[0] = 0

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



for i in range(2,n):

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



print((dp[n-1]))

n = int(eval(input()))



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



dp = [0] * n



dp[0] = 0

dp[1] = abs(pedras[0] - pedras[1])





for i in range(2,n):

    custo1 = dp[i-1] + abs(pedras[i-1] - pedras[i])

    custo2 = dp[i-2] + abs(pedras[i-2] - pedras[i])

    dp[i] = min(custo1,custo2)



print((dp[n-1]))

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

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

-h = list(map(int, input().split())) +pedras = list(map(int, input().split())) -dp[1] = abs(h[1] - h[0]) +dp[1] = abs(pedras[0] - pedras[1]) -    dp[i] = min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i])) +    custo1 = dp[i - 1] + abs(pedras[i - 1] - pedras[i]) +    custo2 = dp[i - 2] + abs(pedras[i - 2] - pedras[i]) +    dp[i] = min(custo1, custo2)