import java.util.Scanner;

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();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-2; x++){
            dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));
            dp[x+2] = Math.min(dp[x+2], dp[x] + Math.abs(h[x+2] - h[x]));
        }
        int x = N-2;
        dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));

        System.out.println(dp[N-1]);
    }
} import java.util.Scanner; Scanner 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();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-2; x++){
            dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));
            dp[x+2] = Math.min(dp[x+2], dp[x] + Math.abs(h[x+2] - h[x]));
        }
        int x = N-2;
        dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));

        System.out.println(dp[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();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-2; x++){
            dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));
            dp[x+2] = Math.min(dp[x+2], dp[x] + Math.abs(h[x+2] - h[x]));
        }
        int x = N-2;
        dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));

        System.out.println(dp[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();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-2; x++){
            dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));
            dp[x+2] = Math.min(dp[x+2], dp[x] + Math.abs(h[x+2] - h[x]));
        }
        int x = N-2;
        dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));

        System.out.println(dp[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 int[] dp = new int[N]; dp new int[N] N for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            dp[i] = (int) Math.pow(10, 9);
        } {
            dp[i] = (int) Math.pow(10, 9);
        } dp[i] = (int) Math.pow(10, 9) dp[i] dp i (int) Math.pow(10, 9) Math.pow Math 10 9 dp[0] = 0 dp[0] dp 0 0 for(int x=0; x<N-2; x++){
            dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));
            dp[x+2] = Math.min(dp[x+2], dp[x] + Math.abs(h[x+2] - h[x]));
        } int x=0; int x=0; x 0 x<N-2 x N-2 N 2 x++ x++ x {
            dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));
            dp[x+2] = Math.min(dp[x+2], dp[x] + Math.abs(h[x+2] - h[x]));
        } {
            dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));
            dp[x+2] = Math.min(dp[x+2], dp[x] + Math.abs(h[x+2] - h[x]));
        } dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x])) dp[x+1] dp x+1 x 1 Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x])) Math.min Math dp[x+1] dp x+1 x 1 dp[x] + Math.abs(h[x+1] - h[x]) dp[x] dp x Math.abs(h[x+1] - h[x]) Math.abs Math h[x+1] - h[x] h[x+1] h x+1 x 1 h[x] h x dp[x+2] = Math.min(dp[x+2], dp[x] + Math.abs(h[x+2] - h[x])) dp[x+2] dp x+2 x 2 Math.min(dp[x+2], dp[x] + Math.abs(h[x+2] - h[x])) Math.min Math dp[x+2] dp x+2 x 2 dp[x] + Math.abs(h[x+2] - h[x]) dp[x] dp x Math.abs(h[x+2] - h[x]) Math.abs Math h[x+2] - h[x] h[x+2] h x+2 x 2 h[x] h x int x = N-2; x N-2 N 2 dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x])) dp[x+1] dp x+1 x 1 Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x])) Math.min Math dp[x+1] dp x+1 x 1 dp[x] + Math.abs(h[x+1] - h[x]) dp[x] dp x Math.abs(h[x+1] - h[x]) Math.abs Math h[x+1] - h[x] h[x+1] h x+1 x 1 h[x] h x System.out.println(dp[N-1]) System.out.println System.out System System.out dp[N-1] dp 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();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-2; x++){
            dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));
            dp[x+2] = Math.min(dp[x+2], dp[x] + Math.abs(h[x+2] - h[x]));
        }
        int x = N-2;
        dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));

        System.out.println(dp[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();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-2; x++){
            dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));
            dp[x+2] = Math.min(dp[x+2], dp[x] + Math.abs(h[x+2] - h[x]));
        }
        int x = N-2;
        dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));

        System.out.println(dp[N-1]);
    }
} Main
import java.util.Scanner;

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();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-2; x++){
            dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));
            dp[x+2] = Math.min(dp[x+2], dp[x] + Math.abs(h[x+2] - h[x]));
        }
        int x = N-2;
        dp[x+1] = Math.min(dp[x+1], dp[x] + Math.abs(h[x+1] - h[x]));

        System.out.println(dp[N-1]);
    }
}