import java.io.*;
import java.util.*;

class Main {
  
  	public static int minCost(int h[], int N) {
      	int dp[] = new int[N];
      	dp[0] = 0;
      	dp[1] = Math.abs(h[1] - h[0]);
      	for (int i = 2 ; i < N ; ++i) {
         	 dp[i] = Math.min(dp[i-1] + Math.abs(h[i] - h[i-1]), dp[i-2] + Math.abs(h[i] - h[i-2]));
        }
      	return dp[N-1];
    }
      
	public static void main(String args[]) throws IOException {
     	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int N = Integer.parseInt(br.readLine());
      	String in[] = br.readLine().split(" ");
      	int h[] = new int[N];
      	int i = 0;
      	for (String s: in) {
        	h[i++] = Integer.parseInt(s);
        }
      
      	int cost = minCost(h, N);
      	System.out.println(cost);
    }
} import java.io.*; io.* java import java.util.*; util.* java class Main {
  
  	public static int minCost(int h[], int N) {
      	int dp[] = new int[N];
      	dp[0] = 0;
      	dp[1] = Math.abs(h[1] - h[0]);
      	for (int i = 2 ; i < N ; ++i) {
         	 dp[i] = Math.min(dp[i-1] + Math.abs(h[i] - h[i-1]), dp[i-2] + Math.abs(h[i] - h[i-2]));
        }
      	return dp[N-1];
    }
      
	public static void main(String args[]) throws IOException {
     	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int N = Integer.parseInt(br.readLine());
      	String in[] = br.readLine().split(" ");
      	int h[] = new int[N];
      	int i = 0;
      	for (String s: in) {
        	h[i++] = Integer.parseInt(s);
        }
      
      	int cost = minCost(h, N);
      	System.out.println(cost);
    }
} Main public static int minCost(int h[], int N) {
      	int dp[] = new int[N];
      	dp[0] = 0;
      	dp[1] = Math.abs(h[1] - h[0]);
      	for (int i = 2 ; i < N ; ++i) {
         	 dp[i] = Math.min(dp[i-1] + Math.abs(h[i] - h[i-1]), dp[i-2] + Math.abs(h[i] - h[i-2]));
        }
      	return dp[N-1];
    } minCost {
      	int dp[] = new int[N];
      	dp[0] = 0;
      	dp[1] = Math.abs(h[1] - h[0]);
      	for (int i = 2 ; i < N ; ++i) {
         	 dp[i] = Math.min(dp[i-1] + Math.abs(h[i] - h[i-1]), dp[i-2] + Math.abs(h[i] - h[i-2]));
        }
      	return dp[N-1];
    } int dp[] = new int[N]; dp new int[N] N dp[0] = 0 dp[0] dp 0 0 dp[1] = Math.abs(h[1] - h[0]) dp[1] dp 1 Math.abs(h[1] - h[0]) Math.abs Math h[1] - h[0] h[1] h 1 h[0] h 0 for (int i = 2 ; i < N ; ++i) {
         	 dp[i] = Math.min(dp[i-1] + Math.abs(h[i] - h[i-1]), dp[i-2] + Math.abs(h[i] - h[i-2]));
        } int i = 2 ; int i = 2 ; i 2 i < N i N ++i ++i i {
         	 dp[i] = Math.min(dp[i-1] + Math.abs(h[i] - h[i-1]), dp[i-2] + Math.abs(h[i] - h[i-2]));
        } {
         	 dp[i] = Math.min(dp[i-1] + Math.abs(h[i] - h[i-1]), dp[i-2] + Math.abs(h[i] - h[i-2]));
        } dp[i] = Math.min(dp[i-1] + Math.abs(h[i] - h[i-1]), dp[i-2] + Math.abs(h[i] - h[i-2])) dp[i] dp i Math.min(dp[i-1] + Math.abs(h[i] - h[i-1]), dp[i-2] + Math.abs(h[i] - h[i-2])) Math.min Math dp[i-1] + Math.abs(h[i] - h[i-1]) dp[i-1] dp i-1 i 1 Math.abs(h[i] - h[i-1]) Math.abs Math h[i] - h[i-1] h[i] h i h[i-1] h i-1 i 1 dp[i-2] + Math.abs(h[i] - h[i-2]) dp[i-2] dp i-2 i 2 Math.abs(h[i] - h[i-2]) Math.abs Math h[i] - h[i-2] h[i] h i h[i-2] h i-2 i 2 return dp[N-1]; dp[N-1] dp N-1 N 1 int h[] h int N N public static void main(String args[]) throws IOException {
     	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int N = Integer.parseInt(br.readLine());
      	String in[] = br.readLine().split(" ");
      	int h[] = new int[N];
      	int i = 0;
      	for (String s: in) {
        	h[i++] = Integer.parseInt(s);
        }
      
      	int cost = minCost(h, N);
      	System.out.println(cost);
    } main {
     	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int N = Integer.parseInt(br.readLine());
      	String in[] = br.readLine().split(" ");
      	int h[] = new int[N];
      	int i = 0;
      	for (String s: in) {
        	h[i++] = Integer.parseInt(s);
        }
      
      	int cost = minCost(h, N);
      	System.out.println(cost);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int N = Integer.parseInt(br.readLine()); N Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br String in[] = br.readLine().split(" "); in br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int h[] = new int[N]; h new int[N] N int i = 0; i 0 for (String s: in) {
        	h[i++] = Integer.parseInt(s);
        } String s in {
        	h[i++] = Integer.parseInt(s);
        } {
        	h[i++] = Integer.parseInt(s);
        } h[i++] = Integer.parseInt(s) h[i++] h i++ i Integer.parseInt(s) Integer.parseInt Integer s int cost = minCost(h, N); cost minCost(h, N) minCost h N System.out.println(cost) System.out.println System.out System System.out cost String args[] args
import java.io.*;
import java.util.*;

class Main {
  
  	public static int minCost(int h[], int N) {
      	int dp[] = new int[N];
      	dp[0] = 0;
      	dp[1] = Math.abs(h[1] - h[0]);
      	for (int i = 2 ; i < N ; ++i) {
         	 dp[i] = Math.min(dp[i-1] + Math.abs(h[i] - h[i-1]), dp[i-2] + Math.abs(h[i] - h[i-2]));
        }
      	return dp[N-1];
    }
      
	public static void main(String args[]) throws IOException {
     	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int N = Integer.parseInt(br.readLine());
      	String in[] = br.readLine().split(" ");
      	int h[] = new int[N];
      	int i = 0;
      	for (String s: in) {
        	h[i++] = Integer.parseInt(s);
        }
      
      	int cost = minCost(h, N);
      	System.out.println(cost);
    }
}