import java.util.*;
import java.io.*;
class Main{
	

	private static int getCost(int i,int arr[],int dp[]){
		if(i >= arr.length)
			return Integer.MAX_VALUE;

		if(i== arr.length - 1)
			return 0;
		if(dp[i] != -1)
			return dp[i];
		int oneStep =0;
		int twoStep = 0;
		if(i+1 < arr.length)
			oneStep = Math.abs(arr[i] - arr[i+1]);
		if(i+2 < arr.length)
			twoStep = Math.abs(arr[i]-arr[i+2]);
		dp[i]= Math.min(oneStep + getCost(i+1,arr,dp),twoStep + getCost(i+2,arr,dp));
		return dp[i];
	}
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int arr[]=new int[n];
		String in[]=br.readLine().split(" ");
		for(int i=0;i<n;i++){
			arr[i]=Integer.parseInt(in[i]);
		}
		int dp[]=new int[n];
		Arrays.fill(dp,-1);
		int minCost = getCost(0,arr,dp);
		System.out.println(minCost);
	}
} import java.util.*; util.* java import java.io.*; io.* java class Main{
	

	private static int getCost(int i,int arr[],int dp[]){
		if(i >= arr.length)
			return Integer.MAX_VALUE;

		if(i== arr.length - 1)
			return 0;
		if(dp[i] != -1)
			return dp[i];
		int oneStep =0;
		int twoStep = 0;
		if(i+1 < arr.length)
			oneStep = Math.abs(arr[i] - arr[i+1]);
		if(i+2 < arr.length)
			twoStep = Math.abs(arr[i]-arr[i+2]);
		dp[i]= Math.min(oneStep + getCost(i+1,arr,dp),twoStep + getCost(i+2,arr,dp));
		return dp[i];
	}
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int arr[]=new int[n];
		String in[]=br.readLine().split(" ");
		for(int i=0;i<n;i++){
			arr[i]=Integer.parseInt(in[i]);
		}
		int dp[]=new int[n];
		Arrays.fill(dp,-1);
		int minCost = getCost(0,arr,dp);
		System.out.println(minCost);
	}
} Main private static int getCost(int i,int arr[],int dp[]){
		if(i >= arr.length)
			return Integer.MAX_VALUE;

		if(i== arr.length - 1)
			return 0;
		if(dp[i] != -1)
			return dp[i];
		int oneStep =0;
		int twoStep = 0;
		if(i+1 < arr.length)
			oneStep = Math.abs(arr[i] - arr[i+1]);
		if(i+2 < arr.length)
			twoStep = Math.abs(arr[i]-arr[i+2]);
		dp[i]= Math.min(oneStep + getCost(i+1,arr,dp),twoStep + getCost(i+2,arr,dp));
		return dp[i];
	} getCost {
		if(i >= arr.length)
			return Integer.MAX_VALUE;

		if(i== arr.length - 1)
			return 0;
		if(dp[i] != -1)
			return dp[i];
		int oneStep =0;
		int twoStep = 0;
		if(i+1 < arr.length)
			oneStep = Math.abs(arr[i] - arr[i+1]);
		if(i+2 < arr.length)
			twoStep = Math.abs(arr[i]-arr[i+2]);
		dp[i]= Math.min(oneStep + getCost(i+1,arr,dp),twoStep + getCost(i+2,arr,dp));
		return dp[i];
	} if(i >= arr.length)
			return Integer.MAX_VALUE; i >= arr.length i arr.length arr arr.length return Integer.MAX_VALUE; Integer.MAX_VALUE Integer Integer.MAX_VALUE if(i== arr.length - 1)
			return 0; i== arr.length - 1 i arr.length - 1 arr.length arr arr.length 1 return 0; 0 if(dp[i] != -1)
			return dp[i]; dp[i] != -1 dp[i] dp i -1 1 return dp[i]; dp[i] dp i int oneStep =0; oneStep 0 int twoStep = 0; twoStep 0 if(i+1 < arr.length)
			oneStep = Math.abs(arr[i] - arr[i+1]); i+1 < arr.length i+1 i 1 arr.length arr arr.length oneStep = Math.abs(arr[i] - arr[i+1]) oneStep Math.abs(arr[i] - arr[i+1]) Math.abs Math arr[i] - arr[i+1] arr[i] arr i arr[i+1] arr i+1 i 1 if(i+2 < arr.length)
			twoStep = Math.abs(arr[i]-arr[i+2]); i+2 < arr.length i+2 i 2 arr.length arr arr.length twoStep = Math.abs(arr[i]-arr[i+2]) twoStep Math.abs(arr[i]-arr[i+2]) Math.abs Math arr[i]-arr[i+2] arr[i] arr i arr[i+2] arr i+2 i 2 dp[i]= Math.min(oneStep + getCost(i+1,arr,dp),twoStep + getCost(i+2,arr,dp)) dp[i] dp i Math.min(oneStep + getCost(i+1,arr,dp),twoStep + getCost(i+2,arr,dp)) Math.min Math oneStep + getCost(i+1,arr,dp) oneStep getCost(i+1,arr,dp) getCost i+1 i 1 arr dp twoStep + getCost(i+2,arr,dp) twoStep getCost(i+2,arr,dp) getCost i+2 i 2 arr dp return dp[i]; dp[i] dp i int i i int arr[] arr int dp[] dp public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int arr[]=new int[n];
		String in[]=br.readLine().split(" ");
		for(int i=0;i<n;i++){
			arr[i]=Integer.parseInt(in[i]);
		}
		int dp[]=new int[n];
		Arrays.fill(dp,-1);
		int minCost = getCost(0,arr,dp);
		System.out.println(minCost);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int arr[]=new int[n];
		String in[]=br.readLine().split(" ");
		for(int i=0;i<n;i++){
			arr[i]=Integer.parseInt(in[i]);
		}
		int dp[]=new int[n];
		Arrays.fill(dp,-1);
		int minCost = getCost(0,arr,dp);
		System.out.println(minCost);
	} 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 int arr[]=new int[n]; arr new int[n] n String in[]=br.readLine().split(" "); in br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int i=0;i<n;i++){
			arr[i]=Integer.parseInt(in[i]);
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			arr[i]=Integer.parseInt(in[i]);
		} {
			arr[i]=Integer.parseInt(in[i]);
		} arr[i]=Integer.parseInt(in[i]) arr[i] arr i Integer.parseInt(in[i]) Integer.parseInt Integer in[i] in i int dp[]=new int[n]; dp new int[n] n Arrays.fill(dp,-1) Arrays.fill Arrays dp -1 1 int minCost = getCost(0,arr,dp); minCost getCost(0,arr,dp) getCost 0 arr dp System.out.println(minCost) System.out.println System.out System System.out minCost String[] args args
import java.util.*;
import java.io.*;
class Main{
	

	private static int getCost(int i,int arr[],int dp[]){
		if(i >= arr.length)
			return Integer.MAX_VALUE;

		if(i== arr.length - 1)
			return 0;
		if(dp[i] != -1)
			return dp[i];
		int oneStep =0;
		int twoStep = 0;
		if(i+1 < arr.length)
			oneStep = Math.abs(arr[i] - arr[i+1]);
		if(i+2 < arr.length)
			twoStep = Math.abs(arr[i]-arr[i+2]);
		dp[i]= Math.min(oneStep + getCost(i+1,arr,dp),twoStep + getCost(i+2,arr,dp));
		return dp[i];
	}
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int arr[]=new int[n];
		String in[]=br.readLine().split(" ");
		for(int i=0;i<n;i++){
			arr[i]=Integer.parseInt(in[i]);
		}
		int dp[]=new int[n];
		Arrays.fill(dp,-1);
		int minCost = getCost(0,arr,dp);
		System.out.println(minCost);
	}
}
