import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static int minCost(int[] h, int i, int[] dp) {

        if (i == 0) {
            return 0;
        }
        if (i == 1) {
            return Math.abs(h[0] - h[1]);
        }
        if(dp[i] !=-1){
            return dp[i];
        }


        return dp[i] = Math.min(minCost(h, i - 1,dp) + Math.abs(h[i] - h[i - 1]), minCost(h, i - 2,dp) + Math.abs(h[i] - h[i - 2]));
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try {
            int size = scanner.nextInt();
            int[] nums = new int[size];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = scanner.nextInt();
            }
            int[] dp = new int[size];
            Arrays.fill(dp, -1);
            System.out.println(minCost(nums, size - 1, dp));
        } finally {
            scanner.close();
        }
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {

    public static int minCost(int[] h, int i, int[] dp) {

        if (i == 0) {
            return 0;
        }
        if (i == 1) {
            return Math.abs(h[0] - h[1]);
        }
        if(dp[i] !=-1){
            return dp[i];
        }


        return dp[i] = Math.min(minCost(h, i - 1,dp) + Math.abs(h[i] - h[i - 1]), minCost(h, i - 2,dp) + Math.abs(h[i] - h[i - 2]));
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try {
            int size = scanner.nextInt();
            int[] nums = new int[size];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = scanner.nextInt();
            }
            int[] dp = new int[size];
            Arrays.fill(dp, -1);
            System.out.println(minCost(nums, size - 1, dp));
        } finally {
            scanner.close();
        }
    }
} Main public static int minCost(int[] h, int i, int[] dp) {

        if (i == 0) {
            return 0;
        }
        if (i == 1) {
            return Math.abs(h[0] - h[1]);
        }
        if(dp[i] !=-1){
            return dp[i];
        }


        return dp[i] = Math.min(minCost(h, i - 1,dp) + Math.abs(h[i] - h[i - 1]), minCost(h, i - 2,dp) + Math.abs(h[i] - h[i - 2]));
    } minCost {

        if (i == 0) {
            return 0;
        }
        if (i == 1) {
            return Math.abs(h[0] - h[1]);
        }
        if(dp[i] !=-1){
            return dp[i];
        }


        return dp[i] = Math.min(minCost(h, i - 1,dp) + Math.abs(h[i] - h[i - 1]), minCost(h, i - 2,dp) + Math.abs(h[i] - h[i - 2]));
    } if (i == 0) {
            return 0;
        } i == 0 i 0 {
            return 0;
        } return 0; 0 if (i == 1) {
            return Math.abs(h[0] - h[1]);
        } i == 1 i 1 {
            return Math.abs(h[0] - h[1]);
        } return Math.abs(h[0] - h[1]); Math.abs(h[0] - h[1]) Math.abs Math h[0] - h[1] h[0] h 0 h[1] h 1 if(dp[i] !=-1){
            return dp[i];
        } dp[i] !=-1 dp[i] dp i -1 1 {
            return dp[i];
        } return dp[i]; dp[i] dp i return dp[i] = Math.min(minCost(h, i - 1,dp) + Math.abs(h[i] - h[i - 1]), minCost(h, i - 2,dp) + Math.abs(h[i] - h[i - 2])); dp[i] = Math.min(minCost(h, i - 1,dp) + Math.abs(h[i] - h[i - 1]), minCost(h, i - 2,dp) + Math.abs(h[i] - h[i - 2])) dp[i] dp i Math.min(minCost(h, i - 1,dp) + Math.abs(h[i] - h[i - 1]), minCost(h, i - 2,dp) + Math.abs(h[i] - h[i - 2])) Math.min Math minCost(h, i - 1,dp) + Math.abs(h[i] - h[i - 1]) minCost(h, i - 1,dp) minCost h i - 1 i 1 dp 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 minCost(h, i - 2,dp) + Math.abs(h[i] - h[i - 2]) minCost(h, i - 2,dp) minCost h i - 2 i 2 dp 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 int[] h h int i i int[] dp dp public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try {
            int size = scanner.nextInt();
            int[] nums = new int[size];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = scanner.nextInt();
            }
            int[] dp = new int[size];
            Arrays.fill(dp, -1);
            System.out.println(minCost(nums, size - 1, dp));
        } finally {
            scanner.close();
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        try {
            int size = scanner.nextInt();
            int[] nums = new int[size];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = scanner.nextInt();
            }
            int[] dp = new int[size];
            Arrays.fill(dp, -1);
            System.out.println(minCost(nums, size - 1, dp));
        } finally {
            scanner.close();
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) try {
            int size = scanner.nextInt();
            int[] nums = new int[size];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = scanner.nextInt();
            }
            int[] dp = new int[size];
            Arrays.fill(dp, -1);
            System.out.println(minCost(nums, size - 1, dp));
        } finally {
            scanner.close();
        } {
            scanner.close();
        } scanner.close() scanner.close scanner {
            int size = scanner.nextInt();
            int[] nums = new int[size];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = scanner.nextInt();
            }
            int[] dp = new int[size];
            Arrays.fill(dp, -1);
            System.out.println(minCost(nums, size - 1, dp));
        } int size = scanner.nextInt(); size scanner.nextInt() scanner.nextInt scanner int[] nums = new int[size]; nums new int[size] size for (int i = 0; i < nums.length; i++) {
                nums[i] = scanner.nextInt();
            } int i = 0; int i = 0; i 0 i < nums.length i nums.length nums nums.length i++ i++ i {
                nums[i] = scanner.nextInt();
            } {
                nums[i] = scanner.nextInt();
            } nums[i] = scanner.nextInt() nums[i] nums i scanner.nextInt() scanner.nextInt scanner int[] dp = new int[size]; dp new int[size] size Arrays.fill(dp, -1) Arrays.fill Arrays dp -1 1 System.out.println(minCost(nums, size - 1, dp)) System.out.println System.out System System.out minCost(nums, size - 1, dp) minCost nums size - 1 size 1 dp String[] args args public class Main {

    public static int minCost(int[] h, int i, int[] dp) {

        if (i == 0) {
            return 0;
        }
        if (i == 1) {
            return Math.abs(h[0] - h[1]);
        }
        if(dp[i] !=-1){
            return dp[i];
        }


        return dp[i] = Math.min(minCost(h, i - 1,dp) + Math.abs(h[i] - h[i - 1]), minCost(h, i - 2,dp) + Math.abs(h[i] - h[i - 2]));
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try {
            int size = scanner.nextInt();
            int[] nums = new int[size];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = scanner.nextInt();
            }
            int[] dp = new int[size];
            Arrays.fill(dp, -1);
            System.out.println(minCost(nums, size - 1, dp));
        } finally {
            scanner.close();
        }
    }
} public class Main {

    public static int minCost(int[] h, int i, int[] dp) {

        if (i == 0) {
            return 0;
        }
        if (i == 1) {
            return Math.abs(h[0] - h[1]);
        }
        if(dp[i] !=-1){
            return dp[i];
        }


        return dp[i] = Math.min(minCost(h, i - 1,dp) + Math.abs(h[i] - h[i - 1]), minCost(h, i - 2,dp) + Math.abs(h[i] - h[i - 2]));
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try {
            int size = scanner.nextInt();
            int[] nums = new int[size];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = scanner.nextInt();
            }
            int[] dp = new int[size];
            Arrays.fill(dp, -1);
            System.out.println(minCost(nums, size - 1, dp));
        } finally {
            scanner.close();
        }
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static int minCost(int[] h, int i, int[] dp) {

        if (i == 0) {
            return 0;
        }
        if (i == 1) {
            return Math.abs(h[0] - h[1]);
        }
        if(dp[i] !=-1){
            return dp[i];
        }


        return dp[i] = Math.min(minCost(h, i - 1,dp) + Math.abs(h[i] - h[i - 1]), minCost(h, i - 2,dp) + Math.abs(h[i] - h[i - 2]));
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try {
            int size = scanner.nextInt();
            int[] nums = new int[size];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = scanner.nextInt();
            }
            int[] dp = new int[size];
            Arrays.fill(dp, -1);
            System.out.println(minCost(nums, size - 1, dp));
        } finally {
            scanner.close();
        }
    }
}