import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        if (n == 2) {
            System.out.println(Math.abs(h[0] - h[1]));
            return;
        }

        int[] cost = new int[n];
        cost[0] = 0;
        cost[1] = Math.abs(h[1] - h[0]);
        for (int i = 2; i < n; i++) {
            cost[i] = Math.min(cost[i-2] + Math.abs(h[i] - h[i-2]),
                    cost[i-1] + Math.abs(h[i] - h[i-1]));
        }

        System.out.println(cost[n-1]);

    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        if (n == 2) {
            System.out.println(Math.abs(h[0] - h[1]));
            return;
        }

        int[] cost = new int[n];
        cost[0] = 0;
        cost[1] = Math.abs(h[1] - h[0]);
        for (int i = 2; i < n; i++) {
            cost[i] = Math.min(cost[i-2] + Math.abs(h[i] - h[i-2]),
                    cost[i-1] + Math.abs(h[i] - h[i-1]));
        }

        System.out.println(cost[n-1]);

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        if (n == 2) {
            System.out.println(Math.abs(h[0] - h[1]));
            return;
        }

        int[] cost = new int[n];
        cost[0] = 0;
        cost[1] = Math.abs(h[1] - h[0]);
        for (int i = 2; i < n; i++) {
            cost[i] = Math.min(cost[i-2] + Math.abs(h[i] - h[i-2]),
                    cost[i-1] + Math.abs(h[i] - h[i-1]));
        }

        System.out.println(cost[n-1]);

    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        if (n == 2) {
            System.out.println(Math.abs(h[0] - h[1]));
            return;
        }

        int[] cost = new int[n];
        cost[0] = 0;
        cost[1] = Math.abs(h[1] - h[0]);
        for (int i = 2; i < n; i++) {
            cost[i] = Math.min(cost[i-2] + Math.abs(h[i] - h[i-2]),
                    cost[i-1] + Math.abs(h[i] - h[i-1]));
        }

        System.out.println(cost[n-1]);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] h = new int[n]; h new int[n] n for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            h[i] = sc.nextInt();
        } {
            h[i] = sc.nextInt();
        } h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc if (n == 2) {
            System.out.println(Math.abs(h[0] - h[1]));
            return;
        } n == 2 n 2 {
            System.out.println(Math.abs(h[0] - h[1]));
            return;
        } System.out.println(Math.abs(h[0] - h[1])) System.out.println System.out System System.out Math.abs(h[0] - h[1]) Math.abs Math h[0] - h[1] h[0] h 0 h[1] h 1 return; int[] cost = new int[n]; cost new int[n] n cost[0] = 0 cost[0] cost 0 0 cost[1] = Math.abs(h[1] - h[0]) cost[1] cost 1 Math.abs(h[1] - h[0]) Math.abs Math h[1] - h[0] h[1] h 1 h[0] h 0 for (int i = 2; i < n; i++) {
            cost[i] = Math.min(cost[i-2] + Math.abs(h[i] - h[i-2]),
                    cost[i-1] + Math.abs(h[i] - h[i-1]));
        } int i = 2; int i = 2; i 2 i < n i n i++ i++ i {
            cost[i] = Math.min(cost[i-2] + Math.abs(h[i] - h[i-2]),
                    cost[i-1] + Math.abs(h[i] - h[i-1]));
        } {
            cost[i] = Math.min(cost[i-2] + Math.abs(h[i] - h[i-2]),
                    cost[i-1] + Math.abs(h[i] - h[i-1]));
        } cost[i] = Math.min(cost[i-2] + Math.abs(h[i] - h[i-2]),
                    cost[i-1] + Math.abs(h[i] - h[i-1])) cost[i] cost i Math.min(cost[i-2] + Math.abs(h[i] - h[i-2]),
                    cost[i-1] + Math.abs(h[i] - h[i-1])) Math.min Math cost[i-2] + Math.abs(h[i] - h[i-2]) cost[i-2] cost i-2 i 2 Math.abs(h[i] - h[i-2]) Math.abs Math h[i] - h[i-2] h[i] h i h[i-2] h i-2 i 2 cost[i-1] + Math.abs(h[i] - h[i-1]) cost[i-1] cost i-1 i 1 Math.abs(h[i] - h[i-1]) Math.abs Math h[i] - h[i-1] h[i] h i h[i-1] h i-1 i 1 System.out.println(cost[n-1]) System.out.println System.out System System.out cost[n-1] cost n-1 n 1 String[] args args public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        if (n == 2) {
            System.out.println(Math.abs(h[0] - h[1]));
            return;
        }

        int[] cost = new int[n];
        cost[0] = 0;
        cost[1] = Math.abs(h[1] - h[0]);
        for (int i = 2; i < n; i++) {
            cost[i] = Math.min(cost[i-2] + Math.abs(h[i] - h[i-2]),
                    cost[i-1] + Math.abs(h[i] - h[i-1]));
        }

        System.out.println(cost[n-1]);

    }
} public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        if (n == 2) {
            System.out.println(Math.abs(h[0] - h[1]));
            return;
        }

        int[] cost = new int[n];
        cost[0] = 0;
        cost[1] = Math.abs(h[1] - h[0]);
        for (int i = 2; i < n; i++) {
            cost[i] = Math.min(cost[i-2] + Math.abs(h[i] - h[i-2]),
                    cost[i-1] + Math.abs(h[i] - h[i-1]));
        }

        System.out.println(cost[n-1]);

    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        if (n == 2) {
            System.out.println(Math.abs(h[0] - h[1]));
            return;
        }

        int[] cost = new int[n];
        cost[0] = 0;
        cost[1] = Math.abs(h[1] - h[0]);
        for (int i = 2; i < n; i++) {
            cost[i] = Math.min(cost[i-2] + Math.abs(h[i] - h[i-2]),
                    cost[i-1] + Math.abs(h[i] - h[i-1]));
        }

        System.out.println(cost[n-1]);

    }
}
