
import java.io.*;
import java.util.*;

class Main {
    private static int[] heights;
    private static int n, ans = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        heights = new int[n + 3];
        dp = new int[n + 3];
        for (int i = 1; i <= n; i++) {
            heights[i] = sc.nextInt();
        }
        Arrays.fill(dp, -1);
        System.out.println(findJumpCost(1));
        sc.close();
    }

    private static int[] dp;

    private static int findJumpCost(int ind) {
        if (ind == n)
            return 0;

        if (dp[ind] != -1) {
            return dp[ind];
        }
        int min = Integer.MAX_VALUE;
        for (int i = ind + 1; i <= Math.min(n, ind + 2); i++) {
            min = Math.min(min, Math.abs(heights[i] - heights[ind]) + findJumpCost(i));
            // System.out.println(min);
        }
        return dp[ind] = min;
    }
} import java.io.*; io.* java import java.util.*; util.* java class Main {
    private static int[] heights;
    private static int n, ans = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        heights = new int[n + 3];
        dp = new int[n + 3];
        for (int i = 1; i <= n; i++) {
            heights[i] = sc.nextInt();
        }
        Arrays.fill(dp, -1);
        System.out.println(findJumpCost(1));
        sc.close();
    }

    private static int[] dp;

    private static int findJumpCost(int ind) {
        if (ind == n)
            return 0;

        if (dp[ind] != -1) {
            return dp[ind];
        }
        int min = Integer.MAX_VALUE;
        for (int i = ind + 1; i <= Math.min(n, ind + 2); i++) {
            min = Math.min(min, Math.abs(heights[i] - heights[ind]) + findJumpCost(i));
            // System.out.println(min);
        }
        return dp[ind] = min;
    }
} Main private static int[] heights; heights private static int n n ans = Integer.MAX_VALUE; ans Integer.MAX_VALUE Integer Integer.MAX_VALUE private static int[] dp; dp public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        heights = new int[n + 3];
        dp = new int[n + 3];
        for (int i = 1; i <= n; i++) {
            heights[i] = sc.nextInt();
        }
        Arrays.fill(dp, -1);
        System.out.println(findJumpCost(1));
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        heights = new int[n + 3];
        dp = new int[n + 3];
        for (int i = 1; i <= n; i++) {
            heights[i] = sc.nextInt();
        }
        Arrays.fill(dp, -1);
        System.out.println(findJumpCost(1));
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc heights = new int[n + 3] heights new int[n + 3] n + 3 n 3 dp = new int[n + 3] dp new int[n + 3] n + 3 n 3 for (int i = 1; i <= n; i++) {
            heights[i] = sc.nextInt();
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            heights[i] = sc.nextInt();
        } {
            heights[i] = sc.nextInt();
        } heights[i] = sc.nextInt() heights[i] heights i sc.nextInt() sc.nextInt sc Arrays.fill(dp, -1) Arrays.fill Arrays dp -1 1 System.out.println(findJumpCost(1)) System.out.println System.out System System.out findJumpCost(1) findJumpCost 1 sc.close() sc.close sc String[] args args private static int findJumpCost(int ind) {
        if (ind == n)
            return 0;

        if (dp[ind] != -1) {
            return dp[ind];
        }
        int min = Integer.MAX_VALUE;
        for (int i = ind + 1; i <= Math.min(n, ind + 2); i++) {
            min = Math.min(min, Math.abs(heights[i] - heights[ind]) + findJumpCost(i));
            // System.out.println(min);
        }
        return dp[ind] = min;
    } findJumpCost {
        if (ind == n)
            return 0;

        if (dp[ind] != -1) {
            return dp[ind];
        }
        int min = Integer.MAX_VALUE;
        for (int i = ind + 1; i <= Math.min(n, ind + 2); i++) {
            min = Math.min(min, Math.abs(heights[i] - heights[ind]) + findJumpCost(i));
            // System.out.println(min);
        }
        return dp[ind] = min;
    } if (ind == n)
            return 0; ind == n ind n return 0; 0 if (dp[ind] != -1) {
            return dp[ind];
        } dp[ind] != -1 dp[ind] dp ind -1 1 {
            return dp[ind];
        } return dp[ind]; dp[ind] dp ind int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = ind + 1; i <= Math.min(n, ind + 2); i++) {
            min = Math.min(min, Math.abs(heights[i] - heights[ind]) + findJumpCost(i));
            // System.out.println(min);
        } int i = ind + 1; int i = ind + 1; i ind + 1 ind 1 i <= Math.min(n, ind + 2) i Math.min(n, ind + 2) Math.min Math n ind + 2 ind 2 i++ i++ i {
            min = Math.min(min, Math.abs(heights[i] - heights[ind]) + findJumpCost(i));
            // System.out.println(min);
        } {
            min = Math.min(min, Math.abs(heights[i] - heights[ind]) + findJumpCost(i));
            // System.out.println(min);
        } min = Math.min(min, Math.abs(heights[i] - heights[ind]) + findJumpCost(i)) min Math.min(min, Math.abs(heights[i] - heights[ind]) + findJumpCost(i)) Math.min Math min Math.abs(heights[i] - heights[ind]) + findJumpCost(i) Math.abs(heights[i] - heights[ind]) Math.abs Math heights[i] - heights[ind] heights[i] heights i heights[ind] heights ind findJumpCost(i) findJumpCost i return dp[ind] = min; dp[ind] = min dp[ind] dp ind min int ind ind

import java.io.*;
import java.util.*;

class Main {
    private static int[] heights;
    private static int n, ans = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        heights = new int[n + 3];
        dp = new int[n + 3];
        for (int i = 1; i <= n; i++) {
            heights[i] = sc.nextInt();
        }
        Arrays.fill(dp, -1);
        System.out.println(findJumpCost(1));
        sc.close();
    }

    private static int[] dp;

    private static int findJumpCost(int ind) {
        if (ind == n)
            return 0;

        if (dp[ind] != -1) {
            return dp[ind];
        }
        int min = Integer.MAX_VALUE;
        for (int i = ind + 1; i <= Math.min(n, ind + 2); i++) {
            min = Math.min(min, Math.abs(heights[i] - heights[ind]) + findJumpCost(i));
            // System.out.println(min);
        }
        return dp[ind] = min;
    }
}