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

public class Main {
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);
                int N = scan.nextInt();
                int[] costs = new int[N];
                int[] cache = new int[N];
                for(int i = 0 ; i < N ; i++) {
                        costs[i] = scan.nextInt();
                        cache[i] = 2147483647;
                }
                cache[0] = 0;
                cache[1] = Math.abs(costs[1]-costs[0]);
                System.out.println(jump(costs, 2, cache));
                return;
        }

        private static int jump(int[] costs, int k, int[] cache) {
                for(int i = 2 ; i < costs.length ; i++) {
                    for(int j = k ; j > 0 ; j--){
                        cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j])));
                    }
                    //cache[i] = Math.min(cache[i-1]+Math.abs(costs[i-1]-costs[i]), cache[i-2]+Math.abs(costs[i-2]-costs[i]));
                }
                return cache[costs.length-1];
        }
} import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util public class Main {
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);
                int N = scan.nextInt();
                int[] costs = new int[N];
                int[] cache = new int[N];
                for(int i = 0 ; i < N ; i++) {
                        costs[i] = scan.nextInt();
                        cache[i] = 2147483647;
                }
                cache[0] = 0;
                cache[1] = Math.abs(costs[1]-costs[0]);
                System.out.println(jump(costs, 2, cache));
                return;
        }

        private static int jump(int[] costs, int k, int[] cache) {
                for(int i = 2 ; i < costs.length ; i++) {
                    for(int j = k ; j > 0 ; j--){
                        cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j])));
                    }
                    //cache[i] = Math.min(cache[i-1]+Math.abs(costs[i-1]-costs[i]), cache[i-2]+Math.abs(costs[i-2]-costs[i]));
                }
                return cache[costs.length-1];
        }
} Main public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);
                int N = scan.nextInt();
                int[] costs = new int[N];
                int[] cache = new int[N];
                for(int i = 0 ; i < N ; i++) {
                        costs[i] = scan.nextInt();
                        cache[i] = 2147483647;
                }
                cache[0] = 0;
                cache[1] = Math.abs(costs[1]-costs[0]);
                System.out.println(jump(costs, 2, cache));
                return;
        } main {
                Scanner scan = new Scanner(System.in);
                int N = scan.nextInt();
                int[] costs = new int[N];
                int[] cache = new int[N];
                for(int i = 0 ; i < N ; i++) {
                        costs[i] = scan.nextInt();
                        cache[i] = 2147483647;
                }
                cache[0] = 0;
                cache[1] = Math.abs(costs[1]-costs[0]);
                System.out.println(jump(costs, 2, cache));
                return;
        } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int[] costs = new int[N]; costs new int[N] N int[] cache = new int[N]; cache new int[N] N for(int i = 0 ; i < N ; i++) {
                        costs[i] = scan.nextInt();
                        cache[i] = 2147483647;
                } int i = 0 ; int i = 0 ; i 0 i < N i N i++ i++ i {
                        costs[i] = scan.nextInt();
                        cache[i] = 2147483647;
                } {
                        costs[i] = scan.nextInt();
                        cache[i] = 2147483647;
                } costs[i] = scan.nextInt() costs[i] costs i scan.nextInt() scan.nextInt scan cache[i] = 2147483647 cache[i] cache i 2147483647 cache[0] = 0 cache[0] cache 0 0 cache[1] = Math.abs(costs[1]-costs[0]) cache[1] cache 1 Math.abs(costs[1]-costs[0]) Math.abs Math costs[1]-costs[0] costs[1] costs 1 costs[0] costs 0 System.out.println(jump(costs, 2, cache)) System.out.println System.out System System.out jump(costs, 2, cache) jump costs 2 cache return; String[] args args private static int jump(int[] costs, int k, int[] cache) {
                for(int i = 2 ; i < costs.length ; i++) {
                    for(int j = k ; j > 0 ; j--){
                        cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j])));
                    }
                    //cache[i] = Math.min(cache[i-1]+Math.abs(costs[i-1]-costs[i]), cache[i-2]+Math.abs(costs[i-2]-costs[i]));
                }
                return cache[costs.length-1];
        } jump {
                for(int i = 2 ; i < costs.length ; i++) {
                    for(int j = k ; j > 0 ; j--){
                        cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j])));
                    }
                    //cache[i] = Math.min(cache[i-1]+Math.abs(costs[i-1]-costs[i]), cache[i-2]+Math.abs(costs[i-2]-costs[i]));
                }
                return cache[costs.length-1];
        } for(int i = 2 ; i < costs.length ; i++) {
                    for(int j = k ; j > 0 ; j--){
                        cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j])));
                    }
                    //cache[i] = Math.min(cache[i-1]+Math.abs(costs[i-1]-costs[i]), cache[i-2]+Math.abs(costs[i-2]-costs[i]));
                } int i = 2 ; int i = 2 ; i 2 i < costs.length i costs.length costs costs.length i++ i++ i {
                    for(int j = k ; j > 0 ; j--){
                        cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j])));
                    }
                    //cache[i] = Math.min(cache[i-1]+Math.abs(costs[i-1]-costs[i]), cache[i-2]+Math.abs(costs[i-2]-costs[i]));
                } {
                    for(int j = k ; j > 0 ; j--){
                        cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j])));
                    }
                    //cache[i] = Math.min(cache[i-1]+Math.abs(costs[i-1]-costs[i]), cache[i-2]+Math.abs(costs[i-2]-costs[i]));
                } for(int j = k ; j > 0 ; j--){
                        cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j])));
                    } int j = k ; int j = k ; j k j > 0 j 0 j-- j-- j {
                        cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j])));
                    } {
                        cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j])));
                    } cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j]))) cache[i] cache i Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j]))) Math.min Math cache[i] cache i cache[i-j]+(Math.abs(costs[i] - costs[i-j])) cache[i-j] cache i-j i j (Math.abs(costs[i] - costs[i-j])) Math.abs Math costs[i] - costs[i-j] costs[i] costs i costs[i-j] costs i-j i j return cache[costs.length-1]; cache[costs.length-1] cache costs.length-1 costs.length costs costs.length 1 int[] costs costs int k k int[] cache cache public class Main {
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);
                int N = scan.nextInt();
                int[] costs = new int[N];
                int[] cache = new int[N];
                for(int i = 0 ; i < N ; i++) {
                        costs[i] = scan.nextInt();
                        cache[i] = 2147483647;
                }
                cache[0] = 0;
                cache[1] = Math.abs(costs[1]-costs[0]);
                System.out.println(jump(costs, 2, cache));
                return;
        }

        private static int jump(int[] costs, int k, int[] cache) {
                for(int i = 2 ; i < costs.length ; i++) {
                    for(int j = k ; j > 0 ; j--){
                        cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j])));
                    }
                    //cache[i] = Math.min(cache[i-1]+Math.abs(costs[i-1]-costs[i]), cache[i-2]+Math.abs(costs[i-2]-costs[i]));
                }
                return cache[costs.length-1];
        }
} public class Main {
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);
                int N = scan.nextInt();
                int[] costs = new int[N];
                int[] cache = new int[N];
                for(int i = 0 ; i < N ; i++) {
                        costs[i] = scan.nextInt();
                        cache[i] = 2147483647;
                }
                cache[0] = 0;
                cache[1] = Math.abs(costs[1]-costs[0]);
                System.out.println(jump(costs, 2, cache));
                return;
        }

        private static int jump(int[] costs, int k, int[] cache) {
                for(int i = 2 ; i < costs.length ; i++) {
                    for(int j = k ; j > 0 ; j--){
                        cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j])));
                    }
                    //cache[i] = Math.min(cache[i-1]+Math.abs(costs[i-1]-costs[i]), cache[i-2]+Math.abs(costs[i-2]-costs[i]));
                }
                return cache[costs.length-1];
        }
} Main
import java.util.Scanner;
import java.util.Arrays;

public class Main {
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);
                int N = scan.nextInt();
                int[] costs = new int[N];
                int[] cache = new int[N];
                for(int i = 0 ; i < N ; i++) {
                        costs[i] = scan.nextInt();
                        cache[i] = 2147483647;
                }
                cache[0] = 0;
                cache[1] = Math.abs(costs[1]-costs[0]);
                System.out.println(jump(costs, 2, cache));
                return;
        }

        private static int jump(int[] costs, int k, int[] cache) {
                for(int i = 2 ; i < costs.length ; i++) {
                    for(int j = k ; j > 0 ; j--){
                        cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j])));
                    }
                    //cache[i] = Math.min(cache[i-1]+Math.abs(costs[i-1]-costs[i]), cache[i-2]+Math.abs(costs[i-2]-costs[i]));
                }
                return cache[costs.length-1];
        }
}