/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     public static int minCost(int []h , int curr_ind , int n , int []dp , int curr_cost){
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        
	        int a = (Math.abs(h[curr_ind] - h[curr_ind + 1]) + minCost(h , curr_ind + 1 , n ,dp , 0)) ;
	        
	        int b = Integer.MAX_VALUE;
	        
	        if(curr_ind+2<=n){
	        b =   (Math.abs(h[curr_ind] - h[curr_ind + 2]) + minCost(h , curr_ind + 2 , n ,dp , 0)) ;
	        }
	        
	        return dp[curr_ind] =  Math.min(  a, b );
	        
	        
	    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , 0));
	}
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java public class Main
{
     public static int minCost(int []h , int curr_ind , int n , int []dp , int curr_cost){
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        
	        int a = (Math.abs(h[curr_ind] - h[curr_ind + 1]) + minCost(h , curr_ind + 1 , n ,dp , 0)) ;
	        
	        int b = Integer.MAX_VALUE;
	        
	        if(curr_ind+2<=n){
	        b =   (Math.abs(h[curr_ind] - h[curr_ind + 2]) + minCost(h , curr_ind + 2 , n ,dp , 0)) ;
	        }
	        
	        return dp[curr_ind] =  Math.min(  a, b );
	        
	        
	    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , 0));
	}
} Main public static int minCost(int []h , int curr_ind , int n , int []dp , int curr_cost){
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        
	        int a = (Math.abs(h[curr_ind] - h[curr_ind + 1]) + minCost(h , curr_ind + 1 , n ,dp , 0)) ;
	        
	        int b = Integer.MAX_VALUE;
	        
	        if(curr_ind+2<=n){
	        b =   (Math.abs(h[curr_ind] - h[curr_ind + 2]) + minCost(h , curr_ind + 2 , n ,dp , 0)) ;
	        }
	        
	        return dp[curr_ind] =  Math.min(  a, b );
	        
	        
	    } minCost {
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        
	        int a = (Math.abs(h[curr_ind] - h[curr_ind + 1]) + minCost(h , curr_ind + 1 , n ,dp , 0)) ;
	        
	        int b = Integer.MAX_VALUE;
	        
	        if(curr_ind+2<=n){
	        b =   (Math.abs(h[curr_ind] - h[curr_ind + 2]) + minCost(h , curr_ind + 2 , n ,dp , 0)) ;
	        }
	        
	        return dp[curr_ind] =  Math.min(  a, b );
	        
	        
	    } if(curr_ind > n-1  )
	        return 0; curr_ind > n-1 curr_ind n-1 n 1 return 0; 0 if(dp[curr_ind]!=-1) return dp[curr_ind]; dp[curr_ind]!=-1 dp[curr_ind] dp curr_ind -1 1 return dp[curr_ind]; dp[curr_ind] dp curr_ind int a = (Math.abs(h[curr_ind] - h[curr_ind + 1]) + minCost(h , curr_ind + 1 , n ,dp , 0)) ; a (Math.abs(h[curr_ind] - h[curr_ind + 1]) + minCost(h , curr_ind + 1 , n ,dp , 0)) Math.abs(h[curr_ind] - h[curr_ind + 1]) Math.abs Math h[curr_ind] - h[curr_ind + 1] h[curr_ind] h curr_ind h[curr_ind + 1] h curr_ind + 1 curr_ind 1 minCost(h , curr_ind + 1 , n ,dp , 0) minCost h curr_ind + 1 curr_ind 1 n dp 0 int b = Integer.MAX_VALUE; b Integer.MAX_VALUE Integer Integer.MAX_VALUE if(curr_ind+2<=n){
	        b =   (Math.abs(h[curr_ind] - h[curr_ind + 2]) + minCost(h , curr_ind + 2 , n ,dp , 0)) ;
	        } curr_ind+2<=n curr_ind+2 curr_ind 2 n {
	        b =   (Math.abs(h[curr_ind] - h[curr_ind + 2]) + minCost(h , curr_ind + 2 , n ,dp , 0)) ;
	        } b =   (Math.abs(h[curr_ind] - h[curr_ind + 2]) + minCost(h , curr_ind + 2 , n ,dp , 0)) b (Math.abs(h[curr_ind] - h[curr_ind + 2]) + minCost(h , curr_ind + 2 , n ,dp , 0)) Math.abs(h[curr_ind] - h[curr_ind + 2]) Math.abs Math h[curr_ind] - h[curr_ind + 2] h[curr_ind] h curr_ind h[curr_ind + 2] h curr_ind + 2 curr_ind 2 minCost(h , curr_ind + 2 , n ,dp , 0) minCost h curr_ind + 2 curr_ind 2 n dp 0 return dp[curr_ind] =  Math.min(  a, b ); dp[curr_ind] =  Math.min(  a, b ) dp[curr_ind] dp curr_ind Math.min(  a, b ) Math.min Math a b int []h h int curr_ind curr_ind int n n int []dp dp int curr_cost curr_cost public static void main (String[] args) throws java.lang.Exception
	{
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , 0));
	} main {
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , 0));
	} Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in))); sc new Scanner(new BufferedReader(new InputStreamReader(System.in))) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int h[] = new int[n+1]; h new int[n+1] n+1 n 1 for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			} int i =1; int i =1; i 1 i<=n i n i++ i++ i {
		    h[i] = sc.nextInt();
			} {
		    h[i] = sc.nextInt();
			} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc int dp[]=new int[n+1]; dp new int[n+1] n+1 n 1 for(int j =0;j<n+1;j++)
			dp[j] = -1; int j =0; int j =0; j 0 j<n+1 j n+1 n 1 j++ j++ j dp[j] = -1; dp[j] = -1 dp[j] dp j -1 1 System.out.println(minCost(h , 1 , n , dp , 0)) System.out.println System.out System System.out minCost(h , 1 , n , dp , 0) minCost h 1 n dp 0 String[] args args public class Main
{
     public static int minCost(int []h , int curr_ind , int n , int []dp , int curr_cost){
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        
	        int a = (Math.abs(h[curr_ind] - h[curr_ind + 1]) + minCost(h , curr_ind + 1 , n ,dp , 0)) ;
	        
	        int b = Integer.MAX_VALUE;
	        
	        if(curr_ind+2<=n){
	        b =   (Math.abs(h[curr_ind] - h[curr_ind + 2]) + minCost(h , curr_ind + 2 , n ,dp , 0)) ;
	        }
	        
	        return dp[curr_ind] =  Math.min(  a, b );
	        
	        
	    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , 0));
	}
} public class Main
{
     public static int minCost(int []h , int curr_ind , int n , int []dp , int curr_cost){
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        
	        int a = (Math.abs(h[curr_ind] - h[curr_ind + 1]) + minCost(h , curr_ind + 1 , n ,dp , 0)) ;
	        
	        int b = Integer.MAX_VALUE;
	        
	        if(curr_ind+2<=n){
	        b =   (Math.abs(h[curr_ind] - h[curr_ind + 2]) + minCost(h , curr_ind + 2 , n ,dp , 0)) ;
	        }
	        
	        return dp[curr_ind] =  Math.min(  a, b );
	        
	        
	    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , 0));
	}
} Main
/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     public static int minCost(int []h , int curr_ind , int n , int []dp , int curr_cost){
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        
	        int a = (Math.abs(h[curr_ind] - h[curr_ind + 1]) + minCost(h , curr_ind + 1 , n ,dp , 0)) ;
	        
	        int b = Integer.MAX_VALUE;
	        
	        if(curr_ind+2<=n){
	        b =   (Math.abs(h[curr_ind] - h[curr_ind + 2]) + minCost(h , curr_ind + 2 , n ,dp , 0)) ;
	        }
	        
	        return dp[curr_ind] =  Math.min(  a, b );
	        
	        
	    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , 0));
	}
}
