import java.util.*;
import java.io.*;
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+1];
    for(int i = 2; i<=n; i++) {
        dp[i] = dp[i-1]+Math.abs(a[i-1]-a[i-2]);
        if(i>=3)
            dp[i] = Math.min(dp[i], dp[i-2]+Math.abs(a[i-3]-a[i-1]));
    }
    System.out.println(dp[n]);
  }
} import java.util.*; util.* java import java.io.*; io.* java 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+1];
    for(int i = 2; i<=n; i++) {
        dp[i] = dp[i-1]+Math.abs(a[i-1]-a[i-2]);
        if(i>=3)
            dp[i] = Math.min(dp[i], dp[i-2]+Math.abs(a[i-3]-a[i-1]));
    }
    System.out.println(dp[n]);
  }
} 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+1];
    for(int i = 2; i<=n; i++) {
        dp[i] = dp[i-1]+Math.abs(a[i-1]-a[i-2]);
        if(i>=3)
            dp[i] = Math.min(dp[i], dp[i-2]+Math.abs(a[i-3]-a[i-1]));
    }
    System.out.println(dp[n]);
  } 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+1];
    for(int i = 2; i<=n; i++) {
        dp[i] = dp[i-1]+Math.abs(a[i-1]-a[i-2]);
        if(i>=3)
            dp[i] = Math.min(dp[i], dp[i-2]+Math.abs(a[i-3]-a[i-1]));
    }
    System.out.println(dp[n]);
  } 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+1]; dp new int[n+1] n+1 n 1 for(int i = 2; i<=n; i++) {
        dp[i] = dp[i-1]+Math.abs(a[i-1]-a[i-2]);
        if(i>=3)
            dp[i] = Math.min(dp[i], dp[i-2]+Math.abs(a[i-3]-a[i-1]));
    } int i = 2; int i = 2; i 2 i<=n i n i++ i++ i {
        dp[i] = dp[i-1]+Math.abs(a[i-1]-a[i-2]);
        if(i>=3)
            dp[i] = Math.min(dp[i], dp[i-2]+Math.abs(a[i-3]-a[i-1]));
    } {
        dp[i] = dp[i-1]+Math.abs(a[i-1]-a[i-2]);
        if(i>=3)
            dp[i] = Math.min(dp[i], dp[i-2]+Math.abs(a[i-3]-a[i-1]));
    } dp[i] = dp[i-1]+Math.abs(a[i-1]-a[i-2]) dp[i] dp i dp[i-1]+Math.abs(a[i-1]-a[i-2]) dp[i-1] dp i-1 i 1 Math.abs(a[i-1]-a[i-2]) Math.abs Math a[i-1]-a[i-2] a[i-1] a i-1 i 1 a[i-2] a i-2 i 2 if(i>=3)
            dp[i] = Math.min(dp[i], dp[i-2]+Math.abs(a[i-3]-a[i-1])); i>=3 i 3 dp[i] = Math.min(dp[i], dp[i-2]+Math.abs(a[i-3]-a[i-1])) dp[i] dp i Math.min(dp[i], dp[i-2]+Math.abs(a[i-3]-a[i-1])) Math.min Math dp[i] dp i dp[i-2]+Math.abs(a[i-3]-a[i-1]) dp[i-2] dp i-2 i 2 Math.abs(a[i-3]-a[i-1]) Math.abs Math a[i-3]-a[i-1] a[i-3] a i-3 i 3 a[i-1] a i-1 i 1 System.out.println(dp[n]) System.out.println System.out System System.out dp[n] dp n String[] args args
import java.util.*;
import java.io.*;
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+1];
    for(int i = 2; i<=n; i++) {
        dp[i] = dp[i-1]+Math.abs(a[i-1]-a[i-2]);
        if(i>=3)
            dp[i] = Math.min(dp[i], dp[i-2]+Math.abs(a[i-3]-a[i-1]));
    }
    System.out.println(dp[n]);
  }
}