import java.util.Scanner;
public class Main{
	
	
	private static Scanner sc=new Scanner(System.in);
	private static int dp[];
	public static int findMinCost(int arr[],int n){
		if(n>=arr.length)
			return Integer.MAX_VALUE;
		if(n==arr.length-1)
			return 0;
		
		if(dp[n]!=Integer.MAX_VALUE)
			return dp[n];
		
		int n1=n+2<arr.length?findMinCost(arr,n+2)+Math.abs(arr[n]-arr[n+2]):Integer.MAX_VALUE;
		int n2=n+1<arr.length?findMinCost(arr,n+1)+Math.abs(arr[n]-arr[n+1]):Integer.MAX_VALUE;
		
		dp[n] = Math.min(n1,n2);
		return dp[n];
	}
	
	public static void main(String []args){
		int n=sc.nextInt();
		int arr[]=new int[n];
		dp=new int[arr.length];
		for(int i=0;i<n;i++){
			arr[i]=sc.nextInt();
			dp[i]=Integer.MAX_VALUE;
		}
		System.out.println(findMinCost(arr,0));
	}
} import java.util.Scanner; Scanner java.util public class Main{
	
	
	private static Scanner sc=new Scanner(System.in);
	private static int dp[];
	public static int findMinCost(int arr[],int n){
		if(n>=arr.length)
			return Integer.MAX_VALUE;
		if(n==arr.length-1)
			return 0;
		
		if(dp[n]!=Integer.MAX_VALUE)
			return dp[n];
		
		int n1=n+2<arr.length?findMinCost(arr,n+2)+Math.abs(arr[n]-arr[n+2]):Integer.MAX_VALUE;
		int n2=n+1<arr.length?findMinCost(arr,n+1)+Math.abs(arr[n]-arr[n+1]):Integer.MAX_VALUE;
		
		dp[n] = Math.min(n1,n2);
		return dp[n];
	}
	
	public static void main(String []args){
		int n=sc.nextInt();
		int arr[]=new int[n];
		dp=new int[arr.length];
		for(int i=0;i<n;i++){
			arr[i]=sc.nextInt();
			dp[i]=Integer.MAX_VALUE;
		}
		System.out.println(findMinCost(arr,0));
	}
} Main private static Scanner sc=new Scanner(System.in); sc new Scanner(System.in) private static int dp[]; dp public static int findMinCost(int arr[],int n){
		if(n>=arr.length)
			return Integer.MAX_VALUE;
		if(n==arr.length-1)
			return 0;
		
		if(dp[n]!=Integer.MAX_VALUE)
			return dp[n];
		
		int n1=n+2<arr.length?findMinCost(arr,n+2)+Math.abs(arr[n]-arr[n+2]):Integer.MAX_VALUE;
		int n2=n+1<arr.length?findMinCost(arr,n+1)+Math.abs(arr[n]-arr[n+1]):Integer.MAX_VALUE;
		
		dp[n] = Math.min(n1,n2);
		return dp[n];
	} findMinCost {
		if(n>=arr.length)
			return Integer.MAX_VALUE;
		if(n==arr.length-1)
			return 0;
		
		if(dp[n]!=Integer.MAX_VALUE)
			return dp[n];
		
		int n1=n+2<arr.length?findMinCost(arr,n+2)+Math.abs(arr[n]-arr[n+2]):Integer.MAX_VALUE;
		int n2=n+1<arr.length?findMinCost(arr,n+1)+Math.abs(arr[n]-arr[n+1]):Integer.MAX_VALUE;
		
		dp[n] = Math.min(n1,n2);
		return dp[n];
	} if(n>=arr.length)
			return Integer.MAX_VALUE; n>=arr.length n arr.length arr arr.length return Integer.MAX_VALUE; Integer.MAX_VALUE Integer Integer.MAX_VALUE if(n==arr.length-1)
			return 0; n==arr.length-1 n arr.length-1 arr.length arr arr.length 1 return 0; 0 if(dp[n]!=Integer.MAX_VALUE)
			return dp[n]; dp[n]!=Integer.MAX_VALUE dp[n] dp n Integer.MAX_VALUE Integer Integer.MAX_VALUE return dp[n]; dp[n] dp n int n1=n+2<arr.length?findMinCost(arr,n+2)+Math.abs(arr[n]-arr[n+2]):Integer.MAX_VALUE; n1 n+2<arr.length?findMinCost(arr,n+2)+Math.abs(arr[n]-arr[n+2]):Integer.MAX_VALUE n+2<arr.length n+2 n 2 arr.length arr arr.length findMinCost(arr,n+2)+Math.abs(arr[n]-arr[n+2]) findMinCost(arr,n+2) findMinCost arr n+2 n 2 Math.abs(arr[n]-arr[n+2]) Math.abs Math arr[n]-arr[n+2] arr[n] arr n arr[n+2] arr n+2 n 2 Integer.MAX_VALUE Integer Integer.MAX_VALUE int n2=n+1<arr.length?findMinCost(arr,n+1)+Math.abs(arr[n]-arr[n+1]):Integer.MAX_VALUE; n2 n+1<arr.length?findMinCost(arr,n+1)+Math.abs(arr[n]-arr[n+1]):Integer.MAX_VALUE n+1<arr.length n+1 n 1 arr.length arr arr.length findMinCost(arr,n+1)+Math.abs(arr[n]-arr[n+1]) findMinCost(arr,n+1) findMinCost arr n+1 n 1 Math.abs(arr[n]-arr[n+1]) Math.abs Math arr[n]-arr[n+1] arr[n] arr n arr[n+1] arr n+1 n 1 Integer.MAX_VALUE Integer Integer.MAX_VALUE dp[n] = Math.min(n1,n2) dp[n] dp n Math.min(n1,n2) Math.min Math n1 n2 return dp[n]; dp[n] dp n int arr[] arr int n n public static void main(String []args){
		int n=sc.nextInt();
		int arr[]=new int[n];
		dp=new int[arr.length];
		for(int i=0;i<n;i++){
			arr[i]=sc.nextInt();
			dp[i]=Integer.MAX_VALUE;
		}
		System.out.println(findMinCost(arr,0));
	} main {
		int n=sc.nextInt();
		int arr[]=new int[n];
		dp=new int[arr.length];
		for(int i=0;i<n;i++){
			arr[i]=sc.nextInt();
			dp[i]=Integer.MAX_VALUE;
		}
		System.out.println(findMinCost(arr,0));
	} int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int arr[]=new int[n]; arr new int[n] n dp=new int[arr.length] dp new int[arr.length] arr.length arr arr.length for(int i=0;i<n;i++){
			arr[i]=sc.nextInt();
			dp[i]=Integer.MAX_VALUE;
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			arr[i]=sc.nextInt();
			dp[i]=Integer.MAX_VALUE;
		} {
			arr[i]=sc.nextInt();
			dp[i]=Integer.MAX_VALUE;
		} arr[i]=sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc dp[i]=Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE System.out.println(findMinCost(arr,0)) System.out.println System.out System System.out findMinCost(arr,0) findMinCost arr 0 String []args args public class Main{
	
	
	private static Scanner sc=new Scanner(System.in);
	private static int dp[];
	public static int findMinCost(int arr[],int n){
		if(n>=arr.length)
			return Integer.MAX_VALUE;
		if(n==arr.length-1)
			return 0;
		
		if(dp[n]!=Integer.MAX_VALUE)
			return dp[n];
		
		int n1=n+2<arr.length?findMinCost(arr,n+2)+Math.abs(arr[n]-arr[n+2]):Integer.MAX_VALUE;
		int n2=n+1<arr.length?findMinCost(arr,n+1)+Math.abs(arr[n]-arr[n+1]):Integer.MAX_VALUE;
		
		dp[n] = Math.min(n1,n2);
		return dp[n];
	}
	
	public static void main(String []args){
		int n=sc.nextInt();
		int arr[]=new int[n];
		dp=new int[arr.length];
		for(int i=0;i<n;i++){
			arr[i]=sc.nextInt();
			dp[i]=Integer.MAX_VALUE;
		}
		System.out.println(findMinCost(arr,0));
	}
} public class Main{
	
	
	private static Scanner sc=new Scanner(System.in);
	private static int dp[];
	public static int findMinCost(int arr[],int n){
		if(n>=arr.length)
			return Integer.MAX_VALUE;
		if(n==arr.length-1)
			return 0;
		
		if(dp[n]!=Integer.MAX_VALUE)
			return dp[n];
		
		int n1=n+2<arr.length?findMinCost(arr,n+2)+Math.abs(arr[n]-arr[n+2]):Integer.MAX_VALUE;
		int n2=n+1<arr.length?findMinCost(arr,n+1)+Math.abs(arr[n]-arr[n+1]):Integer.MAX_VALUE;
		
		dp[n] = Math.min(n1,n2);
		return dp[n];
	}
	
	public static void main(String []args){
		int n=sc.nextInt();
		int arr[]=new int[n];
		dp=new int[arr.length];
		for(int i=0;i<n;i++){
			arr[i]=sc.nextInt();
			dp[i]=Integer.MAX_VALUE;
		}
		System.out.println(findMinCost(arr,0));
	}
} Main
import java.util.Scanner;
public class Main{
	
	
	private static Scanner sc=new Scanner(System.in);
	private static int dp[];
	public static int findMinCost(int arr[],int n){
		if(n>=arr.length)
			return Integer.MAX_VALUE;
		if(n==arr.length-1)
			return 0;
		
		if(dp[n]!=Integer.MAX_VALUE)
			return dp[n];
		
		int n1=n+2<arr.length?findMinCost(arr,n+2)+Math.abs(arr[n]-arr[n+2]):Integer.MAX_VALUE;
		int n2=n+1<arr.length?findMinCost(arr,n+1)+Math.abs(arr[n]-arr[n+1]):Integer.MAX_VALUE;
		
		dp[n] = Math.min(n1,n2);
		return dp[n];
	}
	
	public static void main(String []args){
		int n=sc.nextInt();
		int arr[]=new int[n];
		dp=new int[arr.length];
		for(int i=0;i<n;i++){
			arr[i]=sc.nextInt();
			dp[i]=Integer.MAX_VALUE;
		}
		System.out.println(findMinCost(arr,0));
	}
}