import java.util.Scanner;

public class Main {

    private static int frog1(int N, int[] h) {
        // subproblem:
        // f(k) = cost when standing on stone k (0 <= k < N)
        // f(N-1)

        // f(0) = 0
        // f(1) = abs(h[1], h[0])
        // f(k) = min:
        //        f(k-1) + abs(h[k], h[k-1])
        //        f(k-2) + abs(h[k], h[k-2])

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

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
        }
        int res = frog1(N, h);
        System.out.println(res);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    private static int frog1(int N, int[] h) {
        // subproblem:
        // f(k) = cost when standing on stone k (0 <= k < N)
        // f(N-1)

        // f(0) = 0
        // f(1) = abs(h[1], h[0])
        // f(k) = min:
        //        f(k-1) + abs(h[k], h[k-1])
        //        f(k-2) + abs(h[k], h[k-2])

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

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
        }
        int res = frog1(N, h);
        System.out.println(res);
    }
} Main private static int frog1(int N, int[] h) {
        // subproblem:
        // f(k) = cost when standing on stone k (0 <= k < N)
        // f(N-1)

        // f(0) = 0
        // f(1) = abs(h[1], h[0])
        // f(k) = min:
        //        f(k-1) + abs(h[k], h[k-1])
        //        f(k-2) + abs(h[k], h[k-2])

        int[] dp = new int[N];
        dp[0] = 0;
        dp[1] = Math.abs(h[0] - h[1]);
        for (int k = 2; k < N; k++) {
            dp[k] = Math.min(
                    dp[k-1] + Math.abs(h[k] - h[k-1]),
                    dp[k-2] + Math.abs(h[k] - h[k-2])
            );
        }
        return dp[N-1];
    } frog1 {
        // subproblem:
        // f(k) = cost when standing on stone k (0 <= k < N)
        // f(N-1)

        // f(0) = 0
        // f(1) = abs(h[1], h[0])
        // f(k) = min:
        //        f(k-1) + abs(h[k], h[k-1])
        //        f(k-2) + abs(h[k], h[k-2])

        int[] dp = new int[N];
        dp[0] = 0;
        dp[1] = Math.abs(h[0] - h[1]);
        for (int k = 2; k < N; k++) {
            dp[k] = Math.min(
                    dp[k-1] + Math.abs(h[k] - h[k-1]),
                    dp[k-2] + Math.abs(h[k] - h[k-2])
            );
        }
        return dp[N-1];
    } int[] dp = new int[N]; dp new int[N] N dp[0] = 0 dp[0] dp 0 0 dp[1] = Math.abs(h[0] - h[1]) dp[1] dp 1 Math.abs(h[0] - h[1]) Math.abs Math h[0] - h[1] h[0] h 0 h[1] h 1 for (int k = 2; k < N; k++) {
            dp[k] = Math.min(
                    dp[k-1] + Math.abs(h[k] - h[k-1]),
                    dp[k-2] + Math.abs(h[k] - h[k-2])
            );
        } int k = 2; int k = 2; k 2 k < N k N k++ k++ k {
            dp[k] = Math.min(
                    dp[k-1] + Math.abs(h[k] - h[k-1]),
                    dp[k-2] + Math.abs(h[k] - h[k-2])
            );
        } {
            dp[k] = Math.min(
                    dp[k-1] + Math.abs(h[k] - h[k-1]),
                    dp[k-2] + Math.abs(h[k] - h[k-2])
            );
        } dp[k] = Math.min(
                    dp[k-1] + Math.abs(h[k] - h[k-1]),
                    dp[k-2] + Math.abs(h[k] - h[k-2])
            ) dp[k] dp k Math.min(
                    dp[k-1] + Math.abs(h[k] - h[k-1]),
                    dp[k-2] + Math.abs(h[k] - h[k-2])
            ) Math.min Math dp[k-1] + Math.abs(h[k] - h[k-1]) dp[k-1] dp k-1 k 1 Math.abs(h[k] - h[k-1]) Math.abs Math h[k] - h[k-1] h[k] h k h[k-1] h k-1 k 1 dp[k-2] + Math.abs(h[k] - h[k-2]) dp[k-2] dp k-2 k 2 Math.abs(h[k] - h[k-2]) Math.abs Math h[k] - h[k-2] h[k] h k h[k-2] h k-2 k 2 return dp[N-1]; dp[N-1] dp N-1 N 1 int N N int[] h h public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
        }
        int res = frog1(N, h);
        System.out.println(res);
    } main {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
        }
        int res = frog1(N, h);
        System.out.println(res);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] h = new int[N]; h new int[N] N for (int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            h[i] = scanner.nextInt();
        } {
            h[i] = scanner.nextInt();
        } h[i] = scanner.nextInt() h[i] h i scanner.nextInt() scanner.nextInt scanner int res = frog1(N, h); res frog1(N, h) frog1 N h System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {

    private static int frog1(int N, int[] h) {
        // subproblem:
        // f(k) = cost when standing on stone k (0 <= k < N)
        // f(N-1)

        // f(0) = 0
        // f(1) = abs(h[1], h[0])
        // f(k) = min:
        //        f(k-1) + abs(h[k], h[k-1])
        //        f(k-2) + abs(h[k], h[k-2])

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

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

    private static int frog1(int N, int[] h) {
        // subproblem:
        // f(k) = cost when standing on stone k (0 <= k < N)
        // f(N-1)

        // f(0) = 0
        // f(1) = abs(h[1], h[0])
        // f(k) = min:
        //        f(k-1) + abs(h[k], h[k-1])
        //        f(k-2) + abs(h[k], h[k-2])

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

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
        }
        int res = frog1(N, h);
        System.out.println(res);
    }
} Main
import java.util.Scanner;

public class Main {

    private static int frog1(int N, int[] h) {
        // subproblem:
        // f(k) = cost when standing on stone k (0 <= k < N)
        // f(N-1)

        // f(0) = 0
        // f(1) = abs(h[1], h[0])
        // f(k) = min:
        //        f(k-1) + abs(h[k], h[k-1])
        //        f(k-2) + abs(h[k], h[k-2])

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

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