import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++)arr[i] = scan.nextInt();
        scan.close();
        int[] dp = new int[n+1];
        Arrays.fill(dp,1000000005);
        dp[0] = 0;
        for(int i= 0;i<n;i++){
            int n1 = i+1;
            int n2 = i+2;
            if(n1 < n){
                dp[n1] = Math.min(dp[n1],dp[i] + Math.abs(arr[i] - arr[n1]));
            }
            if(n2 < n){
                dp[n2] = Math.min(dp[n2],dp[i] + Math.abs(arr[i] - arr[n2]));
            }
        }
        System.out.println(dp[n-1]);
        }
} import java.util.*; util.* java class Main{
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++)arr[i] = scan.nextInt();
        scan.close();
        int[] dp = new int[n+1];
        Arrays.fill(dp,1000000005);
        dp[0] = 0;
        for(int i= 0;i<n;i++){
            int n1 = i+1;
            int n2 = i+2;
            if(n1 < n){
                dp[n1] = Math.min(dp[n1],dp[i] + Math.abs(arr[i] - arr[n1]));
            }
            if(n2 < n){
                dp[n2] = Math.min(dp[n2],dp[i] + Math.abs(arr[i] - arr[n2]));
            }
        }
        System.out.println(dp[n-1]);
        }
} Main public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++)arr[i] = scan.nextInt();
        scan.close();
        int[] dp = new int[n+1];
        Arrays.fill(dp,1000000005);
        dp[0] = 0;
        for(int i= 0;i<n;i++){
            int n1 = i+1;
            int n2 = i+2;
            if(n1 < n){
                dp[n1] = Math.min(dp[n1],dp[i] + Math.abs(arr[i] - arr[n1]));
            }
            if(n2 < n){
                dp[n2] = Math.min(dp[n2],dp[i] + Math.abs(arr[i] - arr[n2]));
            }
        }
        System.out.println(dp[n-1]);
        } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++)arr[i] = scan.nextInt();
        scan.close();
        int[] dp = new int[n+1];
        Arrays.fill(dp,1000000005);
        dp[0] = 0;
        for(int i= 0;i<n;i++){
            int n1 = i+1;
            int n2 = i+2;
            if(n1 < n){
                dp[n1] = Math.min(dp[n1],dp[i] + Math.abs(arr[i] - arr[n1]));
            }
            if(n2 < n){
                dp[n2] = Math.min(dp[n2],dp[i] + Math.abs(arr[i] - arr[n2]));
            }
        }
        System.out.println(dp[n-1]);
        } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] arr = new int[n]; arr new int[n] n for(int i=0;i<n;i++)arr[i] = scan.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i arr[i] = scan.nextInt(); arr[i] = scan.nextInt() arr[i] arr i scan.nextInt() scan.nextInt scan scan.close() scan.close scan int[] dp = new int[n+1]; dp new int[n+1] n+1 n 1 Arrays.fill(dp,1000000005) Arrays.fill Arrays dp 1000000005 dp[0] = 0 dp[0] dp 0 0 for(int i= 0;i<n;i++){
            int n1 = i+1;
            int n2 = i+2;
            if(n1 < n){
                dp[n1] = Math.min(dp[n1],dp[i] + Math.abs(arr[i] - arr[n1]));
            }
            if(n2 < n){
                dp[n2] = Math.min(dp[n2],dp[i] + Math.abs(arr[i] - arr[n2]));
            }
        } int i= 0; int i= 0; i 0 i<n i n i++ i++ i {
            int n1 = i+1;
            int n2 = i+2;
            if(n1 < n){
                dp[n1] = Math.min(dp[n1],dp[i] + Math.abs(arr[i] - arr[n1]));
            }
            if(n2 < n){
                dp[n2] = Math.min(dp[n2],dp[i] + Math.abs(arr[i] - arr[n2]));
            }
        } {
            int n1 = i+1;
            int n2 = i+2;
            if(n1 < n){
                dp[n1] = Math.min(dp[n1],dp[i] + Math.abs(arr[i] - arr[n1]));
            }
            if(n2 < n){
                dp[n2] = Math.min(dp[n2],dp[i] + Math.abs(arr[i] - arr[n2]));
            }
        } int n1 = i+1; n1 i+1 i 1 int n2 = i+2; n2 i+2 i 2 if(n1 < n){
                dp[n1] = Math.min(dp[n1],dp[i] + Math.abs(arr[i] - arr[n1]));
            } n1 < n n1 n {
                dp[n1] = Math.min(dp[n1],dp[i] + Math.abs(arr[i] - arr[n1]));
            } dp[n1] = Math.min(dp[n1],dp[i] + Math.abs(arr[i] - arr[n1])) dp[n1] dp n1 Math.min(dp[n1],dp[i] + Math.abs(arr[i] - arr[n1])) Math.min Math dp[n1] dp n1 dp[i] + Math.abs(arr[i] - arr[n1]) dp[i] dp i Math.abs(arr[i] - arr[n1]) Math.abs Math arr[i] - arr[n1] arr[i] arr i arr[n1] arr n1 if(n2 < n){
                dp[n2] = Math.min(dp[n2],dp[i] + Math.abs(arr[i] - arr[n2]));
            } n2 < n n2 n {
                dp[n2] = Math.min(dp[n2],dp[i] + Math.abs(arr[i] - arr[n2]));
            } dp[n2] = Math.min(dp[n2],dp[i] + Math.abs(arr[i] - arr[n2])) dp[n2] dp n2 Math.min(dp[n2],dp[i] + Math.abs(arr[i] - arr[n2])) Math.min Math dp[n2] dp n2 dp[i] + Math.abs(arr[i] - arr[n2]) dp[i] dp i Math.abs(arr[i] - arr[n2]) Math.abs Math arr[i] - arr[n2] arr[i] arr i arr[n2] arr n2 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
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++)arr[i] = scan.nextInt();
        scan.close();
        int[] dp = new int[n+1];
        Arrays.fill(dp,1000000005);
        dp[0] = 0;
        for(int i= 0;i<n;i++){
            int n1 = i+1;
            int n2 = i+2;
            if(n1 < n){
                dp[n1] = Math.min(dp[n1],dp[i] + Math.abs(arr[i] - arr[n1]));
            }
            if(n2 < n){
                dp[n2] = Math.min(dp[n2],dp[i] + Math.abs(arr[i] - arr[n2]));
            }
        }
        System.out.println(dp[n-1]);
        }
}
