#!/usr/bin/env python3

# -*- coding: utf-8 -*-





def solve(ins):

    ins = ins.split("\n")

    h = list(map(int, ins[1].split(" ")))

    # costs = [abs(h1 - h2) for h1, h2 in zip(h, h[1:])]

    costs = [0, abs(h[0] - h[1])]

    for i in range(2, len(h)):

        costs.append(min(costs[i - 2] + abs(h[i] - h[i - 2]), costs[i - 1] + abs(h[i] - h[i - 1])))

    return costs[-1]





if __name__ == "__main__":

    print((solve("\n".join([eval(input()), eval(input())]))))

def solve2(ins):

    ins = ins.split("\n")

    h = list(map(int, ins[1].split(" ")))

    # costs = [abs(h1 - h2) for h1, h2 in zip(h, h[1:])]

    a, b = 0, abs(h[0] - h[1])

    for i in range(2, len(h)):

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

    return b





if __name__ == "__main__":

    print((solve2("\n".join([eval(input()), eval(input())]))))

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def solve(ins):
    ins = ins.split("\n")
    h = list(map(int, ins[1].split(" ")))
    # costs = [abs(h1 - h2) for h1, h2 in zip(h, h[1:])]
    costs = [0, abs(h[0] - h[1])]
    for i in range(2, len(h)):
        costs.append(
            min(
                costs[i - 2] + abs(h[i] - h[i - 2]), costs[i - 1] + abs(h[i] - h[i - 1])
            )
        )
    return costs[-1]


if __name__ == "__main__":
    print((solve("\n".join([eval(input()), eval(input())]))))

def solve2(ins):
    ins = ins.split("\n")
    h = list(map(int, ins[1].split(" ")))
    # costs = [abs(h1 - h2) for h1, h2 in zip(h, h[1:])]
    a, b = 0, abs(h[0] - h[1])
    for i in range(2, len(h)):
        a, b = b, min(a + abs(h[i] - h[i - 2]), b + abs(h[i] - h[i - 1]))
    return b


if __name__ == "__main__":
    print((solve2("\n".join([eval(input()), eval(input())]))))

-#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -def solve(ins): +def solve2(ins): -    costs = [0, abs(h[0] - h[1])] +    a, b = 0, abs(h[0] - h[1]) -        costs.append( -            min( -                costs[i - 2] + abs(h[i] - h[i - 2]), costs[i - 1] + abs(h[i] - h[i - 1]) -            ) -        ) -    return costs[-1] +        a, b = b, min(a + abs(h[i] - h[i - 2]), b + abs(h[i] - h[i - 1])) +    return b -    print((solve("\n".join([eval(input()), eval(input())])))) +    print((solve2("\n".join([eval(input()), eval(input())]))))