import sys

INF=100000000

def frog(i,h,dp):

    global INF

    if dp[i]!=INF:

        return dp[i]

    else:

        if i==1:

            dp[i]=0

            return dp[i]

        elif i==2:

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

            return dp[i]

        else:

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

            return dp[i]

sys.setrecursionlimit(INF)

N=int(eval(input()))

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

dp=[INF for i in range(N+1)]

print((frog(N,h,dp)))

INF=10**15

N=int(eval(input()))

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

dp=[INF for i in range(N)]

dp[0]=0

for i in range(1,N):

    if i>1:

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

    else:

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

print((dp[N-1]))
import sys

INF = 100000000


def frog(i, h, dp):
    global INF
    if dp[i] != INF:
        return dp[i]
    else:
        if i == 1:
            dp[i] = 0
            return dp[i]
        elif i == 2:
            dp[i] = abs(h[1] - h[0])
            return dp[i]
        else:
            dp[i] = min(
                frog(i - 2, h, dp) + abs(h[i - 1] - h[i - 3]),
                frog(i - 1, h, dp) + abs(h[i - 1] - h[i - 2]),
            )
            return dp[i]


sys.setrecursionlimit(INF)
N = int(eval(input()))
h = list(map(int, input().split()))
dp = [INF for i in range(N + 1)]
print((frog(N, h, dp)))

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

-import sys - -INF = 100000000 - - -def frog(i, h, dp): -    global INF -    if dp[i] != INF: -        return dp[i] -    else: -        if i == 1: -            dp[i] = 0 -            return dp[i] -        elif i == 2: -            dp[i] = abs(h[1] - h[0]) -            return dp[i] -        else: -            dp[i] = min( -                frog(i - 2, h, dp) + abs(h[i - 1] - h[i - 3]), -                frog(i - 1, h, dp) + abs(h[i - 1] - h[i - 2]), -            ) -            return dp[i] - - -sys.setrecursionlimit(INF) +INF = 10**15 -dp = [INF for i in range(N + 1)] -print((frog(N, h, dp))) +dp = [INF for i in range(N)] +dp[0] = 0 +for i in range(1, N): +    if i > 1: +        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])) +    else: +        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]) +print((dp[N - 1]))