import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        int[] nums = new int[n];
        String[] line = scanner.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(line[i]);
        }

        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);

        for (int i = 2; i < n; i++) {
            int choice1 = dp[i - 1] + Math.abs(nums[i] - nums[i - 1]);
            int choice2 = dp[i - 2] + Math.abs(nums[i] - nums[i - 2]);

            dp[i] = Math.min(choice1, choice2);
        }

        System.out.println(dp[n - 1]);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        int[] nums = new int[n];
        String[] line = scanner.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(line[i]);
        }

        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);

        for (int i = 2; i < n; i++) {
            int choice1 = dp[i - 1] + Math.abs(nums[i] - nums[i - 1]);
            int choice2 = dp[i - 2] + Math.abs(nums[i] - nums[i - 2]);

            dp[i] = Math.min(choice1, choice2);
        }

        System.out.println(dp[n - 1]);
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        int[] nums = new int[n];
        String[] line = scanner.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(line[i]);
        }

        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);

        for (int i = 2; i < n; i++) {
            int choice1 = dp[i - 1] + Math.abs(nums[i] - nums[i - 1]);
            int choice2 = dp[i - 2] + Math.abs(nums[i] - nums[i - 2]);

            dp[i] = Math.min(choice1, choice2);
        }

        System.out.println(dp[n - 1]);
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        int[] nums = new int[n];
        String[] line = scanner.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(line[i]);
        }

        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);

        for (int i = 2; i < n; i++) {
            int choice1 = dp[i - 1] + Math.abs(nums[i] - nums[i - 1]);
            int choice2 = dp[i - 2] + Math.abs(nums[i] - nums[i - 2]);

            dp[i] = Math.min(choice1, choice2);
        }

        System.out.println(dp[n - 1]);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = Integer.parseInt(scanner.nextLine()); n Integer.parseInt(scanner.nextLine()) Integer.parseInt Integer scanner.nextLine() scanner.nextLine scanner int[] nums = new int[n]; nums new int[n] n String[] line = scanner.nextLine().split(" "); line scanner.nextLine().split(" ") scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(line[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            nums[i] = Integer.parseInt(line[i]);
        } {
            nums[i] = Integer.parseInt(line[i]);
        } nums[i] = Integer.parseInt(line[i]) nums[i] nums i Integer.parseInt(line[i]) Integer.parseInt Integer line[i] line i int[] dp = new int[n]; dp new int[n] n dp[0] = 0 dp[0] dp 0 0 dp[1] = Math.abs(nums[1] - nums[0]) dp[1] dp 1 Math.abs(nums[1] - nums[0]) Math.abs Math nums[1] - nums[0] nums[1] nums 1 nums[0] nums 0 for (int i = 2; i < n; i++) {
            int choice1 = dp[i - 1] + Math.abs(nums[i] - nums[i - 1]);
            int choice2 = dp[i - 2] + Math.abs(nums[i] - nums[i - 2]);

            dp[i] = Math.min(choice1, choice2);
        } int i = 2; int i = 2; i 2 i < n i n i++ i++ i {
            int choice1 = dp[i - 1] + Math.abs(nums[i] - nums[i - 1]);
            int choice2 = dp[i - 2] + Math.abs(nums[i] - nums[i - 2]);

            dp[i] = Math.min(choice1, choice2);
        } {
            int choice1 = dp[i - 1] + Math.abs(nums[i] - nums[i - 1]);
            int choice2 = dp[i - 2] + Math.abs(nums[i] - nums[i - 2]);

            dp[i] = Math.min(choice1, choice2);
        } int choice1 = dp[i - 1] + Math.abs(nums[i] - nums[i - 1]); choice1 dp[i - 1] + Math.abs(nums[i] - nums[i - 1]) dp[i - 1] dp i - 1 i 1 Math.abs(nums[i] - nums[i - 1]) Math.abs Math nums[i] - nums[i - 1] nums[i] nums i nums[i - 1] nums i - 1 i 1 int choice2 = dp[i - 2] + Math.abs(nums[i] - nums[i - 2]); choice2 dp[i - 2] + Math.abs(nums[i] - nums[i - 2]) dp[i - 2] dp i - 2 i 2 Math.abs(nums[i] - nums[i - 2]) Math.abs Math nums[i] - nums[i - 2] nums[i] nums i nums[i - 2] nums i - 2 i 2 dp[i] = Math.min(choice1, choice2) dp[i] dp i Math.min(choice1, choice2) Math.min Math choice1 choice2 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 scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        int[] nums = new int[n];
        String[] line = scanner.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(line[i]);
        }

        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);

        for (int i = 2; i < n; i++) {
            int choice1 = dp[i - 1] + Math.abs(nums[i] - nums[i - 1]);
            int choice2 = dp[i - 2] + Math.abs(nums[i] - nums[i - 2]);

            dp[i] = Math.min(choice1, choice2);
        }

        System.out.println(dp[n - 1]);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        int[] nums = new int[n];
        String[] line = scanner.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(line[i]);
        }

        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);

        for (int i = 2; i < n; i++) {
            int choice1 = dp[i - 1] + Math.abs(nums[i] - nums[i - 1]);
            int choice2 = dp[i - 2] + Math.abs(nums[i] - nums[i - 2]);

            dp[i] = Math.min(choice1, choice2);
        }

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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        int[] nums = new int[n];
        String[] line = scanner.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(line[i]);
        }

        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);

        for (int i = 2; i < n; i++) {
            int choice1 = dp[i - 1] + Math.abs(nums[i] - nums[i - 1]);
            int choice2 = dp[i - 2] + Math.abs(nums[i] - nums[i - 2]);

            dp[i] = Math.min(choice1, choice2);
        }

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