

import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < N; i++) h[i] = in.nextInt();
        System.out.println(minCost(h, N));
    }

    public static int minCost(int[] h, int N) {
        int st1 = 0;
        int st2 = Math.abs(h[1] - h[0]);
        for (int i = 2; i < N; i++) {
            int next = Math.min(st2 + Math.abs(h[i] - h[i-1]), st1 + Math.abs(h[i] - h[i-2]));
            st1 = st2;
            st2 = next;
        }
        return st2;
    }
} import java.util.Scanner; Scanner java.util class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < N; i++) h[i] = in.nextInt();
        System.out.println(minCost(h, N));
    }

    public static int minCost(int[] h, int N) {
        int st1 = 0;
        int st2 = Math.abs(h[1] - h[0]);
        for (int i = 2; i < N; i++) {
            int next = Math.min(st2 + Math.abs(h[i] - h[i-1]), st1 + Math.abs(h[i] - h[i-2]));
            st1 = st2;
            st2 = next;
        }
        return st2;
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < N; i++) h[i] = in.nextInt();
        System.out.println(minCost(h, N));
    } main {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < N; i++) h[i] = in.nextInt();
        System.out.println(minCost(h, N));
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int N = in.nextInt(); N in.nextInt() in.nextInt in int[] h = new int[N]; h new int[N] N for (int i = 0; i < N; i++) h[i] = in.nextInt(); int i = 0; int i = 0; i 0 i < N i N i++ i++ i h[i] = in.nextInt(); h[i] = in.nextInt() h[i] h i in.nextInt() in.nextInt in System.out.println(minCost(h, N)) System.out.println System.out System System.out minCost(h, N) minCost h N String[] args args public static int minCost(int[] h, int N) {
        int st1 = 0;
        int st2 = Math.abs(h[1] - h[0]);
        for (int i = 2; i < N; i++) {
            int next = Math.min(st2 + Math.abs(h[i] - h[i-1]), st1 + Math.abs(h[i] - h[i-2]));
            st1 = st2;
            st2 = next;
        }
        return st2;
    } minCost {
        int st1 = 0;
        int st2 = Math.abs(h[1] - h[0]);
        for (int i = 2; i < N; i++) {
            int next = Math.min(st2 + Math.abs(h[i] - h[i-1]), st1 + Math.abs(h[i] - h[i-2]));
            st1 = st2;
            st2 = next;
        }
        return st2;
    } int st1 = 0; st1 0 int st2 = Math.abs(h[1] - h[0]); st2 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++) {
            int next = Math.min(st2 + Math.abs(h[i] - h[i-1]), st1 + Math.abs(h[i] - h[i-2]));
            st1 = st2;
            st2 = next;
        } int i = 2; int i = 2; i 2 i < N i N i++ i++ i {
            int next = Math.min(st2 + Math.abs(h[i] - h[i-1]), st1 + Math.abs(h[i] - h[i-2]));
            st1 = st2;
            st2 = next;
        } {
            int next = Math.min(st2 + Math.abs(h[i] - h[i-1]), st1 + Math.abs(h[i] - h[i-2]));
            st1 = st2;
            st2 = next;
        } int next = Math.min(st2 + Math.abs(h[i] - h[i-1]), st1 + Math.abs(h[i] - h[i-2])); next Math.min(st2 + Math.abs(h[i] - h[i-1]), st1 + Math.abs(h[i] - h[i-2])) Math.min Math st2 + Math.abs(h[i] - h[i-1]) st2 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 st1 + Math.abs(h[i] - h[i-2]) st1 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 st1 = st2 st1 st2 st2 = next st2 next return st2; st2 int[] h h int N N


import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < N; i++) h[i] = in.nextInt();
        System.out.println(minCost(h, N));
    }

    public static int minCost(int[] h, int N) {
        int st1 = 0;
        int st2 = Math.abs(h[1] - h[0]);
        for (int i = 2; i < N; i++) {
            int next = Math.min(st2 + Math.abs(h[i] - h[i-1]), st1 + Math.abs(h[i] - h[i-2]));
            st1 = st2;
            st2 = next;
        }
        return st2;
    }
}
