import java.util.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , 0);
                q[1] = Math.abs(h[1] - h[0]);
                for(int i = 2 ; i < n ; i++){
                        q[i] = Math.min(q[i - 1] + Math.abs(h[i - 1] - h[i]) , q[i - 2] + Math.abs(h[i - 2] - Math.abs(h[i])));
                }
                System.out.println(q[n - 1]);
        }
} import java.util.*; util.* java public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , 0);
                q[1] = Math.abs(h[1] - h[0]);
                for(int i = 2 ; i < n ; i++){
                        q[i] = Math.min(q[i - 1] + Math.abs(h[i - 1] - h[i]) , q[i - 2] + Math.abs(h[i - 2] - Math.abs(h[i])));
                }
                System.out.println(q[n - 1]);
        }
} Main public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , 0);
                q[1] = Math.abs(h[1] - h[0]);
                for(int i = 2 ; i < n ; i++){
                        q[i] = Math.min(q[i - 1] + Math.abs(h[i - 1] - h[i]) , q[i - 2] + Math.abs(h[i - 2] - Math.abs(h[i])));
                }
                System.out.println(q[n - 1]);
        } main {
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , 0);
                q[1] = Math.abs(h[1] - h[0]);
                for(int i = 2 ; i < n ; i++){
                        q[i] = Math.min(q[i - 1] + Math.abs(h[i - 1] - h[i]) , q[i - 2] + Math.abs(h[i - 2] - Math.abs(h[i])));
                }
                System.out.println(q[n - 1]);
        } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] h = new int[n]; h new int[n] n for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                } int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
                        h[i] = sc.nextInt();
                } {
                        h[i] = sc.nextInt();
                } h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc sc.close() sc.close sc int[] q = new int[n]; q new int[n] n Arrays.fill(q , 0) Arrays.fill Arrays q 0 q[1] = Math.abs(h[1] - h[0]) q[1] q 1 Math.abs(h[1] - h[0]) Math.abs Math h[1] - h[0] h[1] h 1 h[0] h 0 for(int i = 2 ; i < n ; i++){
                        q[i] = Math.min(q[i - 1] + Math.abs(h[i - 1] - h[i]) , q[i - 2] + Math.abs(h[i - 2] - Math.abs(h[i])));
                } int i = 2 ; int i = 2 ; i 2 i < n i n i++ i++ i {
                        q[i] = Math.min(q[i - 1] + Math.abs(h[i - 1] - h[i]) , q[i - 2] + Math.abs(h[i - 2] - Math.abs(h[i])));
                } {
                        q[i] = Math.min(q[i - 1] + Math.abs(h[i - 1] - h[i]) , q[i - 2] + Math.abs(h[i - 2] - Math.abs(h[i])));
                } q[i] = Math.min(q[i - 1] + Math.abs(h[i - 1] - h[i]) , q[i - 2] + Math.abs(h[i - 2] - Math.abs(h[i]))) q[i] q i Math.min(q[i - 1] + Math.abs(h[i - 1] - h[i]) , q[i - 2] + Math.abs(h[i - 2] - Math.abs(h[i]))) Math.min Math q[i - 1] + Math.abs(h[i - 1] - h[i]) q[i - 1] q i - 1 i 1 Math.abs(h[i - 1] - h[i]) Math.abs Math h[i - 1] - h[i] h[i - 1] h i - 1 i 1 h[i] h i q[i - 2] + Math.abs(h[i - 2] - Math.abs(h[i])) q[i - 2] q i - 2 i 2 Math.abs(h[i - 2] - Math.abs(h[i])) Math.abs Math h[i - 2] - Math.abs(h[i]) h[i - 2] h i - 2 i 2 Math.abs(h[i]) Math.abs Math h[i] h i System.out.println(q[n - 1]) System.out.println System.out System System.out q[n - 1] q n - 1 n 1 String[] args args public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , 0);
                q[1] = Math.abs(h[1] - h[0]);
                for(int i = 2 ; i < n ; i++){
                        q[i] = Math.min(q[i - 1] + Math.abs(h[i - 1] - h[i]) , q[i - 2] + Math.abs(h[i - 2] - Math.abs(h[i])));
                }
                System.out.println(q[n - 1]);
        }
} public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , 0);
                q[1] = Math.abs(h[1] - h[0]);
                for(int i = 2 ; i < n ; i++){
                        q[i] = Math.min(q[i - 1] + Math.abs(h[i - 1] - h[i]) , q[i - 2] + Math.abs(h[i - 2] - Math.abs(h[i])));
                }
                System.out.println(q[n - 1]);
        }
} Main
import java.util.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , 0);
                q[1] = Math.abs(h[1] - h[0]);
                for(int i = 2 ; i < n ; i++){
                        q[i] = Math.min(q[i - 1] + Math.abs(h[i - 1] - h[i]) , q[i - 2] + Math.abs(h[i - 2] - Math.abs(h[i])));
                }
                System.out.println(q[n - 1]);
        }
}