import java.util.*;
public class Main {
  
  public static void main(String args[]) {
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    
    for(int ind = 0; ind < n; ind++) {
      arr[ind] = sc.nextInt();
    }
    if(n == 1)
    {
      System.out.println(0);
      return;
    }
    if(n == 2) {
      System.out.println(Math.abs(arr[1] - arr[0]));
      return;
    }
    int[] dp = new int[n];
    dp[1] = Math.abs(arr[1] - arr[0]);
    for(int ind = 2; ind < n;ind++) {
      int cost1 = Math.abs(arr[ind] - arr[ind - 1]) + dp[ind - 1];
      int cost2 = Math.abs(arr[ind] - arr[ind - 2]) + dp[ind - 2];
      if(cost1 < cost2)
        dp[ind] = cost1;
      else
        dp[ind] = cost2;
    }

    System.out.println(dp[arr.length - 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[] arr = new int[n];
    
    for(int ind = 0; ind < n; ind++) {
      arr[ind] = sc.nextInt();
    }
    if(n == 1)
    {
      System.out.println(0);
      return;
    }
    if(n == 2) {
      System.out.println(Math.abs(arr[1] - arr[0]));
      return;
    }
    int[] dp = new int[n];
    dp[1] = Math.abs(arr[1] - arr[0]);
    for(int ind = 2; ind < n;ind++) {
      int cost1 = Math.abs(arr[ind] - arr[ind - 1]) + dp[ind - 1];
      int cost2 = Math.abs(arr[ind] - arr[ind - 2]) + dp[ind - 2];
      if(cost1 < cost2)
        dp[ind] = cost1;
      else
        dp[ind] = cost2;
    }

    System.out.println(dp[arr.length - 1]);
  }
} Main public static void main(String args[]) {
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    
    for(int ind = 0; ind < n; ind++) {
      arr[ind] = sc.nextInt();
    }
    if(n == 1)
    {
      System.out.println(0);
      return;
    }
    if(n == 2) {
      System.out.println(Math.abs(arr[1] - arr[0]));
      return;
    }
    int[] dp = new int[n];
    dp[1] = Math.abs(arr[1] - arr[0]);
    for(int ind = 2; ind < n;ind++) {
      int cost1 = Math.abs(arr[ind] - arr[ind - 1]) + dp[ind - 1];
      int cost2 = Math.abs(arr[ind] - arr[ind - 2]) + dp[ind - 2];
      if(cost1 < cost2)
        dp[ind] = cost1;
      else
        dp[ind] = cost2;
    }

    System.out.println(dp[arr.length - 1]);
  } main {
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    
    for(int ind = 0; ind < n; ind++) {
      arr[ind] = sc.nextInt();
    }
    if(n == 1)
    {
      System.out.println(0);
      return;
    }
    if(n == 2) {
      System.out.println(Math.abs(arr[1] - arr[0]));
      return;
    }
    int[] dp = new int[n];
    dp[1] = Math.abs(arr[1] - arr[0]);
    for(int ind = 2; ind < n;ind++) {
      int cost1 = Math.abs(arr[ind] - arr[ind - 1]) + dp[ind - 1];
      int cost2 = Math.abs(arr[ind] - arr[ind - 2]) + dp[ind - 2];
      if(cost1 < cost2)
        dp[ind] = cost1;
      else
        dp[ind] = cost2;
    }

    System.out.println(dp[arr.length - 1]);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] arr = new int[n]; arr new int[n] n for(int ind = 0; ind < n; ind++) {
      arr[ind] = sc.nextInt();
    } int ind = 0; int ind = 0; ind 0 ind < n ind n ind++ ind++ ind {
      arr[ind] = sc.nextInt();
    } {
      arr[ind] = sc.nextInt();
    } arr[ind] = sc.nextInt() arr[ind] arr ind sc.nextInt() sc.nextInt sc if(n == 1)
    {
      System.out.println(0);
      return;
    } n == 1 n 1 {
      System.out.println(0);
      return;
    } System.out.println(0) System.out.println System.out System System.out 0 return; if(n == 2) {
      System.out.println(Math.abs(arr[1] - arr[0]));
      return;
    } n == 2 n 2 {
      System.out.println(Math.abs(arr[1] - arr[0]));
      return;
    } System.out.println(Math.abs(arr[1] - arr[0])) System.out.println System.out System System.out Math.abs(arr[1] - arr[0]) Math.abs Math arr[1] - arr[0] arr[1] arr 1 arr[0] arr 0 return; int[] dp = new int[n]; dp new int[n] n dp[1] = Math.abs(arr[1] - arr[0]) dp[1] dp 1 Math.abs(arr[1] - arr[0]) Math.abs Math arr[1] - arr[0] arr[1] arr 1 arr[0] arr 0 for(int ind = 2; ind < n;ind++) {
      int cost1 = Math.abs(arr[ind] - arr[ind - 1]) + dp[ind - 1];
      int cost2 = Math.abs(arr[ind] - arr[ind - 2]) + dp[ind - 2];
      if(cost1 < cost2)
        dp[ind] = cost1;
      else
        dp[ind] = cost2;
    } int ind = 2; int ind = 2; ind 2 ind < n ind n ind++ ind++ ind {
      int cost1 = Math.abs(arr[ind] - arr[ind - 1]) + dp[ind - 1];
      int cost2 = Math.abs(arr[ind] - arr[ind - 2]) + dp[ind - 2];
      if(cost1 < cost2)
        dp[ind] = cost1;
      else
        dp[ind] = cost2;
    } {
      int cost1 = Math.abs(arr[ind] - arr[ind - 1]) + dp[ind - 1];
      int cost2 = Math.abs(arr[ind] - arr[ind - 2]) + dp[ind - 2];
      if(cost1 < cost2)
        dp[ind] = cost1;
      else
        dp[ind] = cost2;
    } int cost1 = Math.abs(arr[ind] - arr[ind - 1]) + dp[ind - 1]; cost1 Math.abs(arr[ind] - arr[ind - 1]) + dp[ind - 1] Math.abs(arr[ind] - arr[ind - 1]) Math.abs Math arr[ind] - arr[ind - 1] arr[ind] arr ind arr[ind - 1] arr ind - 1 ind 1 dp[ind - 1] dp ind - 1 ind 1 int cost2 = Math.abs(arr[ind] - arr[ind - 2]) + dp[ind - 2]; cost2 Math.abs(arr[ind] - arr[ind - 2]) + dp[ind - 2] Math.abs(arr[ind] - arr[ind - 2]) Math.abs Math arr[ind] - arr[ind - 2] arr[ind] arr ind arr[ind - 2] arr ind - 2 ind 2 dp[ind - 2] dp ind - 2 ind 2 if(cost1 < cost2)
        dp[ind] = cost1;
      else
        dp[ind] = cost2; cost1 < cost2 cost1 cost2 dp[ind] = cost1 dp[ind] dp ind cost1 dp[ind] = cost2 dp[ind] dp ind cost2 System.out.println(dp[arr.length - 1]) System.out.println System.out System System.out dp[arr.length - 1] dp arr.length - 1 arr.length arr arr.length 1 String args[] args public class Main {
  
  public static void main(String args[]) {
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    
    for(int ind = 0; ind < n; ind++) {
      arr[ind] = sc.nextInt();
    }
    if(n == 1)
    {
      System.out.println(0);
      return;
    }
    if(n == 2) {
      System.out.println(Math.abs(arr[1] - arr[0]));
      return;
    }
    int[] dp = new int[n];
    dp[1] = Math.abs(arr[1] - arr[0]);
    for(int ind = 2; ind < n;ind++) {
      int cost1 = Math.abs(arr[ind] - arr[ind - 1]) + dp[ind - 1];
      int cost2 = Math.abs(arr[ind] - arr[ind - 2]) + dp[ind - 2];
      if(cost1 < cost2)
        dp[ind] = cost1;
      else
        dp[ind] = cost2;
    }

    System.out.println(dp[arr.length - 1]);
  }
} public class Main {
  
  public static void main(String args[]) {
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    
    for(int ind = 0; ind < n; ind++) {
      arr[ind] = sc.nextInt();
    }
    if(n == 1)
    {
      System.out.println(0);
      return;
    }
    if(n == 2) {
      System.out.println(Math.abs(arr[1] - arr[0]));
      return;
    }
    int[] dp = new int[n];
    dp[1] = Math.abs(arr[1] - arr[0]);
    for(int ind = 2; ind < n;ind++) {
      int cost1 = Math.abs(arr[ind] - arr[ind - 1]) + dp[ind - 1];
      int cost2 = Math.abs(arr[ind] - arr[ind - 2]) + dp[ind - 2];
      if(cost1 < cost2)
        dp[ind] = cost1;
      else
        dp[ind] = cost2;
    }

    System.out.println(dp[arr.length - 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[] arr = new int[n];
    
    for(int ind = 0; ind < n; ind++) {
      arr[ind] = sc.nextInt();
    }
    if(n == 1)
    {
      System.out.println(0);
      return;
    }
    if(n == 2) {
      System.out.println(Math.abs(arr[1] - arr[0]));
      return;
    }
    int[] dp = new int[n];
    dp[1] = Math.abs(arr[1] - arr[0]);
    for(int ind = 2; ind < n;ind++) {
      int cost1 = Math.abs(arr[ind] - arr[ind - 1]) + dp[ind - 1];
      int cost2 = Math.abs(arr[ind] - arr[ind - 2]) + dp[ind - 2];
      if(cost1 < cost2)
        dp[ind] = cost1;
      else
        dp[ind] = cost2;
    }

    System.out.println(dp[arr.length - 1]);
  }
}
