import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int[] DP = new int[n+1];
    Arrays.fill(DP,Integer.MAX_VALUE);
    DP[0] = 0;

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }

    for(int i=0; i<n-2; i++){
      DP[i+1] = Math.min(DP[i+1],DP[i]+Math.abs(array[i+1]-array[i]));
      DP[i+2] = Math.min(DP[i+2],DP[i]+Math.abs(array[i+2]-array[i]));
    }

    DP[n-1] = Math.min(DP[n-1],DP[n-2]+Math.abs(array[n-1]-array[n-2]));

    System.out.println(DP[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[] array = new int[n];
    int[] DP = new int[n+1];
    Arrays.fill(DP,Integer.MAX_VALUE);
    DP[0] = 0;

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }

    for(int i=0; i<n-2; i++){
      DP[i+1] = Math.min(DP[i+1],DP[i]+Math.abs(array[i+1]-array[i]));
      DP[i+2] = Math.min(DP[i+2],DP[i]+Math.abs(array[i+2]-array[i]));
    }

    DP[n-1] = Math.min(DP[n-1],DP[n-2]+Math.abs(array[n-1]-array[n-2]));

    System.out.println(DP[n-1]);


  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int[] DP = new int[n+1];
    Arrays.fill(DP,Integer.MAX_VALUE);
    DP[0] = 0;

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }

    for(int i=0; i<n-2; i++){
      DP[i+1] = Math.min(DP[i+1],DP[i]+Math.abs(array[i+1]-array[i]));
      DP[i+2] = Math.min(DP[i+2],DP[i]+Math.abs(array[i+2]-array[i]));
    }

    DP[n-1] = Math.min(DP[n-1],DP[n-2]+Math.abs(array[n-1]-array[n-2]));

    System.out.println(DP[n-1]);


  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int[] DP = new int[n+1];
    Arrays.fill(DP,Integer.MAX_VALUE);
    DP[0] = 0;

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }

    for(int i=0; i<n-2; i++){
      DP[i+1] = Math.min(DP[i+1],DP[i]+Math.abs(array[i+1]-array[i]));
      DP[i+2] = Math.min(DP[i+2],DP[i]+Math.abs(array[i+2]-array[i]));
    }

    DP[n-1] = Math.min(DP[n-1],DP[n-2]+Math.abs(array[n-1]-array[n-2]));

    System.out.println(DP[n-1]);


  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] array = new int[n]; array new int[n] n int[] DP = new int[n+1]; DP new int[n+1] n+1 n 1 Arrays.fill(DP,Integer.MAX_VALUE) Arrays.fill Arrays DP Integer.MAX_VALUE Integer Integer.MAX_VALUE DP[0] = 0 DP[0] DP 0 0 for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      array[i] = sc.nextInt();
    } {
      array[i] = sc.nextInt();
    } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc for(int i=0; i<n-2; i++){
      DP[i+1] = Math.min(DP[i+1],DP[i]+Math.abs(array[i+1]-array[i]));
      DP[i+2] = Math.min(DP[i+2],DP[i]+Math.abs(array[i+2]-array[i]));
    } int i=0; int i=0; i 0 i<n-2 i n-2 n 2 i++ i++ i {
      DP[i+1] = Math.min(DP[i+1],DP[i]+Math.abs(array[i+1]-array[i]));
      DP[i+2] = Math.min(DP[i+2],DP[i]+Math.abs(array[i+2]-array[i]));
    } {
      DP[i+1] = Math.min(DP[i+1],DP[i]+Math.abs(array[i+1]-array[i]));
      DP[i+2] = Math.min(DP[i+2],DP[i]+Math.abs(array[i+2]-array[i]));
    } DP[i+1] = Math.min(DP[i+1],DP[i]+Math.abs(array[i+1]-array[i])) DP[i+1] DP i+1 i 1 Math.min(DP[i+1],DP[i]+Math.abs(array[i+1]-array[i])) Math.min Math DP[i+1] DP i+1 i 1 DP[i]+Math.abs(array[i+1]-array[i]) DP[i] DP i Math.abs(array[i+1]-array[i]) Math.abs Math array[i+1]-array[i] array[i+1] array i+1 i 1 array[i] array i DP[i+2] = Math.min(DP[i+2],DP[i]+Math.abs(array[i+2]-array[i])) DP[i+2] DP i+2 i 2 Math.min(DP[i+2],DP[i]+Math.abs(array[i+2]-array[i])) Math.min Math DP[i+2] DP i+2 i 2 DP[i]+Math.abs(array[i+2]-array[i]) DP[i] DP i Math.abs(array[i+2]-array[i]) Math.abs Math array[i+2]-array[i] array[i+2] array i+2 i 2 array[i] array i DP[n-1] = Math.min(DP[n-1],DP[n-2]+Math.abs(array[n-1]-array[n-2])) DP[n-1] DP n-1 n 1 Math.min(DP[n-1],DP[n-2]+Math.abs(array[n-1]-array[n-2])) Math.min Math DP[n-1] DP n-1 n 1 DP[n-2]+Math.abs(array[n-1]-array[n-2]) DP[n-2] DP n-2 n 2 Math.abs(array[n-1]-array[n-2]) Math.abs Math array[n-1]-array[n-2] array[n-1] array n-1 n 1 array[n-2] array n-2 n 2 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 public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int[] DP = new int[n+1];
    Arrays.fill(DP,Integer.MAX_VALUE);
    DP[0] = 0;

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }

    for(int i=0; i<n-2; i++){
      DP[i+1] = Math.min(DP[i+1],DP[i]+Math.abs(array[i+1]-array[i]));
      DP[i+2] = Math.min(DP[i+2],DP[i]+Math.abs(array[i+2]-array[i]));
    }

    DP[n-1] = Math.min(DP[n-1],DP[n-2]+Math.abs(array[n-1]-array[n-2]));

    System.out.println(DP[n-1]);


  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int[] DP = new int[n+1];
    Arrays.fill(DP,Integer.MAX_VALUE);
    DP[0] = 0;

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }

    for(int i=0; i<n-2; i++){
      DP[i+1] = Math.min(DP[i+1],DP[i]+Math.abs(array[i+1]-array[i]));
      DP[i+2] = Math.min(DP[i+2],DP[i]+Math.abs(array[i+2]-array[i]));
    }

    DP[n-1] = Math.min(DP[n-1],DP[n-2]+Math.abs(array[n-1]-array[n-2]));

    System.out.println(DP[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[] array = new int[n];
    int[] DP = new int[n+1];
    Arrays.fill(DP,Integer.MAX_VALUE);
    DP[0] = 0;

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }

    for(int i=0; i<n-2; i++){
      DP[i+1] = Math.min(DP[i+1],DP[i]+Math.abs(array[i+1]-array[i]));
      DP[i+2] = Math.min(DP[i+2],DP[i]+Math.abs(array[i+2]-array[i]));
    }

    DP[n-1] = Math.min(DP[n-1],DP[n-2]+Math.abs(array[n-1]-array[n-2]));

    System.out.println(DP[n-1]);


  }
}