N = int(eval(input()))

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



dp = [float("INF")]*(N+1)

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 = list(map(int,input().split()))



dp = [float("INF")]*N

dp[0] = 0

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



for i in range(2, N):

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

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

  dp[i] = min(c1, c2)



print((dp[N-1]))
N = int(eval(input()))
h = list(map(int, input().split()))
dp = [float("INF")] * (N + 1)
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 = list(map(int, input().split()))
dp = [float("INF")] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
    c1 = dp[i - 1] + abs(h[i] - h[i - 1])
    c2 = dp[i - 2] + abs(h[i] - h[i - 2])
    dp[i] = min(c1, c2)
print((dp[N - 1]))

-dp = [float("INF")] * (N + 1) +dp = [float("INF")] * 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])) +dp[1] = abs(h[1] - h[0]) +for i in range(2, N): +    c1 = dp[i - 1] + abs(h[i] - h[i - 1]) +    c2 = dp[i - 2] + abs(h[i] - h[i - 2]) +    dp[i] = min(c1, c2)