import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();
      
        int[] dp = new int[n + 1];
        dp[n - 2] = Math.abs(arr[n - 2] - arr[n - 1]);
        for (int i = n - 3; i >= 0; i--) {
            int op1 = Math.abs(arr[i] - arr[i + 1]) + dp[i + 1];
            int op2 = Math.abs(arr[i] - arr[i + 2]) + dp[i + 2];

            dp[i] = Math.min(op1, op2);
          
        }
      
        System.out.println(dp[0]);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();
      
        int[] dp = new int[n + 1];
        dp[n - 2] = Math.abs(arr[n - 2] - arr[n - 1]);
        for (int i = n - 3; i >= 0; i--) {
            int op1 = Math.abs(arr[i] - arr[i + 1]) + dp[i + 1];
            int op2 = Math.abs(arr[i] - arr[i + 2]) + dp[i + 2];

            dp[i] = Math.min(op1, op2);
          
        }
      
        System.out.println(dp[0]);
    }
} Main public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();
      
        int[] dp = new int[n + 1];
        dp[n - 2] = Math.abs(arr[n - 2] - arr[n - 1]);
        for (int i = n - 3; i >= 0; i--) {
            int op1 = Math.abs(arr[i] - arr[i + 1]) + dp[i + 1];
            int op2 = Math.abs(arr[i] - arr[i + 2]) + dp[i + 2];

            dp[i] = Math.min(op1, op2);
          
        }
      
        System.out.println(dp[0]);
    } main {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();
      
        int[] dp = new int[n + 1];
        dp[n - 2] = Math.abs(arr[n - 2] - arr[n - 1]);
        for (int i = n - 3; i >= 0; i--) {
            int op1 = Math.abs(arr[i] - arr[i + 1]) + dp[i + 1];
            int op2 = Math.abs(arr[i] - arr[i + 2]) + dp[i + 2];

            dp[i] = Math.min(op1, op2);
          
        }
      
        System.out.println(dp[0]);
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int n = s.nextInt(); n s.nextInt() s.nextInt s int[] arr = new int[n]; arr new int[n] n for(int i=0;i<n;i++)
        	arr[i]=s.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i arr[i]=s.nextInt(); arr[i]=s.nextInt() arr[i] arr i s.nextInt() s.nextInt s int[] dp = new int[n + 1]; dp new int[n + 1] n + 1 n 1 dp[n - 2] = Math.abs(arr[n - 2] - arr[n - 1]) dp[n - 2] dp n - 2 n 2 Math.abs(arr[n - 2] - arr[n - 1]) Math.abs Math arr[n - 2] - arr[n - 1] arr[n - 2] arr n - 2 n 2 arr[n - 1] arr n - 1 n 1 for (int i = n - 3; i >= 0; i--) {
            int op1 = Math.abs(arr[i] - arr[i + 1]) + dp[i + 1];
            int op2 = Math.abs(arr[i] - arr[i + 2]) + dp[i + 2];

            dp[i] = Math.min(op1, op2);
          
        } int i = n - 3; int i = n - 3; i n - 3 n 3 i >= 0 i 0 i-- i-- i {
            int op1 = Math.abs(arr[i] - arr[i + 1]) + dp[i + 1];
            int op2 = Math.abs(arr[i] - arr[i + 2]) + dp[i + 2];

            dp[i] = Math.min(op1, op2);
          
        } {
            int op1 = Math.abs(arr[i] - arr[i + 1]) + dp[i + 1];
            int op2 = Math.abs(arr[i] - arr[i + 2]) + dp[i + 2];

            dp[i] = Math.min(op1, op2);
          
        } int op1 = Math.abs(arr[i] - arr[i + 1]) + dp[i + 1]; op1 Math.abs(arr[i] - arr[i + 1]) + dp[i + 1] Math.abs(arr[i] - arr[i + 1]) Math.abs Math arr[i] - arr[i + 1] arr[i] arr i arr[i + 1] arr i + 1 i 1 dp[i + 1] dp i + 1 i 1 int op2 = Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]; op2 Math.abs(arr[i] - arr[i + 2]) + dp[i + 2] Math.abs(arr[i] - arr[i + 2]) Math.abs Math arr[i] - arr[i + 2] arr[i] arr i arr[i + 2] arr i + 2 i 2 dp[i + 2] dp i + 2 i 2 dp[i] = Math.min(op1, op2) dp[i] dp i Math.min(op1, op2) Math.min Math op1 op2 System.out.println(dp[0]) System.out.println System.out System System.out dp[0] dp 0 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();
      
        int[] dp = new int[n + 1];
        dp[n - 2] = Math.abs(arr[n - 2] - arr[n - 1]);
        for (int i = n - 3; i >= 0; i--) {
            int op1 = Math.abs(arr[i] - arr[i + 1]) + dp[i + 1];
            int op2 = Math.abs(arr[i] - arr[i + 2]) + dp[i + 2];

            dp[i] = Math.min(op1, op2);
          
        }
      
        System.out.println(dp[0]);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();
      
        int[] dp = new int[n + 1];
        dp[n - 2] = Math.abs(arr[n - 2] - arr[n - 1]);
        for (int i = n - 3; i >= 0; i--) {
            int op1 = Math.abs(arr[i] - arr[i + 1]) + dp[i + 1];
            int op2 = Math.abs(arr[i] - arr[i + 2]) + dp[i + 2];

            dp[i] = Math.min(op1, op2);
          
        }
      
        System.out.println(dp[0]);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();
      
        int[] dp = new int[n + 1];
        dp[n - 2] = Math.abs(arr[n - 2] - arr[n - 1]);
        for (int i = n - 3; i >= 0; i--) {
            int op1 = Math.abs(arr[i] - arr[i + 1]) + dp[i + 1];
            int op2 = Math.abs(arr[i] - arr[i + 2]) + dp[i + 2];

            dp[i] = Math.min(op1, op2);
          
        }
      
        System.out.println(dp[0]);
    }
}