import java.util.*;
import java.util.stream.IntStream;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = sc.nextInt();
    int[] dp = new int[N];
    dp[0] = 0;
    dp[1] = Math.abs(a[1]-a[0]);
    for (int i = 2; i < N; i++) {
      dp[i] = Math.min(dp[i-2] + Math.abs(a[i] - a[i-2]), 
                       dp[i-1] + Math.abs(a[i] - a[i-1]));
    }
    //System.out.println(Arrays.toString(dp));
    System.out.println(dp[N-1]);
  }
} import java.util.*; util.* java import java.util.stream.IntStream; IntStream java.util.stream class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = sc.nextInt();
    int[] dp = new int[N];
    dp[0] = 0;
    dp[1] = Math.abs(a[1]-a[0]);
    for (int i = 2; i < N; i++) {
      dp[i] = Math.min(dp[i-2] + Math.abs(a[i] - a[i-2]), 
                       dp[i-1] + Math.abs(a[i] - a[i-1]));
    }
    //System.out.println(Arrays.toString(dp));
    System.out.println(dp[N-1]);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = sc.nextInt();
    int[] dp = new int[N];
    dp[0] = 0;
    dp[1] = Math.abs(a[1]-a[0]);
    for (int i = 2; i < N; i++) {
      dp[i] = Math.min(dp[i-2] + Math.abs(a[i] - a[i-2]), 
                       dp[i-1] + Math.abs(a[i] - a[i-1]));
    }
    //System.out.println(Arrays.toString(dp));
    System.out.println(dp[N-1]);
  } main {
    Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = sc.nextInt();
    int[] dp = new int[N];
    dp[0] = 0;
    dp[1] = Math.abs(a[1]-a[0]);
    for (int i = 2; i < N; i++) {
      dp[i] = Math.min(dp[i-2] + Math.abs(a[i] - a[i-2]), 
                       dp[i-1] + Math.abs(a[i] - a[i-1]));
    }
    //System.out.println(Arrays.toString(dp));
    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[] a = new int[N]; a new int[N] N for (int i = 0; i < N; i++) a[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < N i N i++ i++ i a[i] = sc.nextInt(); a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int[] dp = new int[N]; dp new int[N] N dp[0] = 0 dp[0] dp 0 0 dp[1] = Math.abs(a[1]-a[0]) dp[1] dp 1 Math.abs(a[1]-a[0]) Math.abs Math a[1]-a[0] a[1] a 1 a[0] a 0 for (int i = 2; i < N; i++) {
      dp[i] = Math.min(dp[i-2] + Math.abs(a[i] - a[i-2]), 
                       dp[i-1] + Math.abs(a[i] - a[i-1]));
    } int i = 2; int i = 2; i 2 i < N i N i++ i++ i {
      dp[i] = Math.min(dp[i-2] + Math.abs(a[i] - a[i-2]), 
                       dp[i-1] + Math.abs(a[i] - a[i-1]));
    } {
      dp[i] = Math.min(dp[i-2] + Math.abs(a[i] - a[i-2]), 
                       dp[i-1] + Math.abs(a[i] - a[i-1]));
    } dp[i] = Math.min(dp[i-2] + Math.abs(a[i] - a[i-2]), 
                       dp[i-1] + Math.abs(a[i] - a[i-1])) dp[i] dp i Math.min(dp[i-2] + Math.abs(a[i] - a[i-2]), 
                       dp[i-1] + Math.abs(a[i] - a[i-1])) Math.min Math dp[i-2] + Math.abs(a[i] - a[i-2]) dp[i-2] dp i-2 i 2 Math.abs(a[i] - a[i-2]) Math.abs Math a[i] - a[i-2] a[i] a i a[i-2] a i-2 i 2 dp[i-1] + Math.abs(a[i] - a[i-1]) dp[i-1] dp i-1 i 1 Math.abs(a[i] - a[i-1]) Math.abs Math a[i] - a[i-1] a[i] a i a[i-1] a i-1 i 1 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.*;
import java.util.stream.IntStream;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = sc.nextInt();
    int[] dp = new int[N];
    dp[0] = 0;
    dp[1] = Math.abs(a[1]-a[0]);
    for (int i = 2; i < N; i++) {
      dp[i] = Math.min(dp[i-2] + Math.abs(a[i] - a[i-2]), 
                       dp[i-1] + Math.abs(a[i] - a[i-1]));
    }
    //System.out.println(Arrays.toString(dp));
    System.out.println(dp[N-1]);
  }
}