import java.util.*;
public class Main{
	static long[] aa;
  static long maxx(int[] arr,int ind){
  	if(ind>=arr.length){
      return Integer.MAX_VALUE;
    }
    if(ind==arr.length-1){ return 0; } 
    if(aa[ind]!=-1){return aa[ind];}
    if(ind+2<arr.length){
      return aa[ind]=Math.min(maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]),
                              maxx(arr,ind+2)+Math.abs(arr[ind]-arr[ind+2]) );
    } else{
    	return aa[ind]=maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]);
    }
    
    
  }
  
  public static void main(String[] args){
  	Scanner s=new Scanner(System.in);
    //int t=s.nextInt();
   // for(int j=0;j<t;j++){
    	int n=s.nextInt();
        int arr[]=new int[n];
      for(int i=0;i<n;i++){
      		arr[i]=s.nextInt();
      }
      aa=new long[n];
      Arrays.fill(aa,-1);
      System.out.println( maxx(arr,0)); 
   // }
    
    
  }

} import java.util.*; util.* java public class Main{
	static long[] aa;
  static long maxx(int[] arr,int ind){
  	if(ind>=arr.length){
      return Integer.MAX_VALUE;
    }
    if(ind==arr.length-1){ return 0; } 
    if(aa[ind]!=-1){return aa[ind];}
    if(ind+2<arr.length){
      return aa[ind]=Math.min(maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]),
                              maxx(arr,ind+2)+Math.abs(arr[ind]-arr[ind+2]) );
    } else{
    	return aa[ind]=maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]);
    }
    
    
  }
  
  public static void main(String[] args){
  	Scanner s=new Scanner(System.in);
    //int t=s.nextInt();
   // for(int j=0;j<t;j++){
    	int n=s.nextInt();
        int arr[]=new int[n];
      for(int i=0;i<n;i++){
      		arr[i]=s.nextInt();
      }
      aa=new long[n];
      Arrays.fill(aa,-1);
      System.out.println( maxx(arr,0)); 
   // }
    
    
  }

} Main static long[] aa; aa static long maxx(int[] arr,int ind){
  	if(ind>=arr.length){
      return Integer.MAX_VALUE;
    }
    if(ind==arr.length-1){ return 0; } 
    if(aa[ind]!=-1){return aa[ind];}
    if(ind+2<arr.length){
      return aa[ind]=Math.min(maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]),
                              maxx(arr,ind+2)+Math.abs(arr[ind]-arr[ind+2]) );
    } else{
    	return aa[ind]=maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]);
    }
    
    
  } maxx {
  	if(ind>=arr.length){
      return Integer.MAX_VALUE;
    }
    if(ind==arr.length-1){ return 0; } 
    if(aa[ind]!=-1){return aa[ind];}
    if(ind+2<arr.length){
      return aa[ind]=Math.min(maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]),
                              maxx(arr,ind+2)+Math.abs(arr[ind]-arr[ind+2]) );
    } else{
    	return aa[ind]=maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]);
    }
    
    
  } if(ind>=arr.length){
      return Integer.MAX_VALUE;
    } ind>=arr.length ind arr.length arr arr.length {
      return Integer.MAX_VALUE;
    } return Integer.MAX_VALUE; Integer.MAX_VALUE Integer Integer.MAX_VALUE if(ind==arr.length-1){ return 0; } ind==arr.length-1 ind arr.length-1 arr.length arr arr.length 1 { return 0; } return 0; 0 if(aa[ind]!=-1){return aa[ind];} aa[ind]!=-1 aa[ind] aa ind -1 1 {return aa[ind];} return aa[ind]; aa[ind] aa ind if(ind+2<arr.length){
      return aa[ind]=Math.min(maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]),
                              maxx(arr,ind+2)+Math.abs(arr[ind]-arr[ind+2]) );
    } else{
    	return aa[ind]=maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]);
    } ind+2<arr.length ind+2 ind 2 arr.length arr arr.length {
      return aa[ind]=Math.min(maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]),
                              maxx(arr,ind+2)+Math.abs(arr[ind]-arr[ind+2]) );
    } return aa[ind]=Math.min(maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]),
                              maxx(arr,ind+2)+Math.abs(arr[ind]-arr[ind+2]) ); aa[ind]=Math.min(maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]),
                              maxx(arr,ind+2)+Math.abs(arr[ind]-arr[ind+2]) ) aa[ind] aa ind Math.min(maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]),
                              maxx(arr,ind+2)+Math.abs(arr[ind]-arr[ind+2]) ) Math.min Math maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]) maxx(arr,ind+1) maxx arr ind+1 ind 1 Math.abs(arr[ind]-arr[ind+1]) Math.abs Math arr[ind]-arr[ind+1] arr[ind] arr ind arr[ind+1] arr ind+1 ind 1 maxx(arr,ind+2)+Math.abs(arr[ind]-arr[ind+2]) maxx(arr,ind+2) maxx arr ind+2 ind 2 Math.abs(arr[ind]-arr[ind+2]) Math.abs Math arr[ind]-arr[ind+2] arr[ind] arr ind arr[ind+2] arr ind+2 ind 2 {
    	return aa[ind]=maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]);
    } return aa[ind]=maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]); aa[ind]=maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]) aa[ind] aa ind maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]) maxx(arr,ind+1) maxx arr ind+1 ind 1 Math.abs(arr[ind]-arr[ind+1]) Math.abs Math arr[ind]-arr[ind+1] arr[ind] arr ind arr[ind+1] arr ind+1 ind 1 int[] arr arr int ind ind public static void main(String[] args){
  	Scanner s=new Scanner(System.in);
    //int t=s.nextInt();
   // for(int j=0;j<t;j++){
    	int n=s.nextInt();
        int arr[]=new int[n];
      for(int i=0;i<n;i++){
      		arr[i]=s.nextInt();
      }
      aa=new long[n];
      Arrays.fill(aa,-1);
      System.out.println( maxx(arr,0)); 
   // }
    
    
  } main {
  	Scanner s=new Scanner(System.in);
    //int t=s.nextInt();
   // for(int j=0;j<t;j++){
    	int n=s.nextInt();
        int arr[]=new int[n];
      for(int i=0;i<n;i++){
      		arr[i]=s.nextInt();
      }
      aa=new long[n];
      Arrays.fill(aa,-1);
      System.out.println( maxx(arr,0)); 
   // }
    
    
  } Scanner s=new Scanner(System.in); s new Scanner(System.in) int n=s.nextInt(); n s.nextInt() s.nextInt s int arr[]=new int[n]; arr new int[n] n for(int i=0;i<n;i++){
      		arr[i]=s.nextInt();
      } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      		arr[i]=s.nextInt();
      } {
      		arr[i]=s.nextInt();
      } arr[i]=s.nextInt() arr[i] arr i s.nextInt() s.nextInt s aa=new long[n] aa new long[n] n Arrays.fill(aa,-1) Arrays.fill Arrays aa -1 1 System.out.println( maxx(arr,0)) System.out.println System.out System System.out maxx(arr,0) maxx arr 0 String[] args args public class Main{
	static long[] aa;
  static long maxx(int[] arr,int ind){
  	if(ind>=arr.length){
      return Integer.MAX_VALUE;
    }
    if(ind==arr.length-1){ return 0; } 
    if(aa[ind]!=-1){return aa[ind];}
    if(ind+2<arr.length){
      return aa[ind]=Math.min(maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]),
                              maxx(arr,ind+2)+Math.abs(arr[ind]-arr[ind+2]) );
    } else{
    	return aa[ind]=maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]);
    }
    
    
  }
  
  public static void main(String[] args){
  	Scanner s=new Scanner(System.in);
    //int t=s.nextInt();
   // for(int j=0;j<t;j++){
    	int n=s.nextInt();
        int arr[]=new int[n];
      for(int i=0;i<n;i++){
      		arr[i]=s.nextInt();
      }
      aa=new long[n];
      Arrays.fill(aa,-1);
      System.out.println( maxx(arr,0)); 
   // }
    
    
  }

} public class Main{
	static long[] aa;
  static long maxx(int[] arr,int ind){
  	if(ind>=arr.length){
      return Integer.MAX_VALUE;
    }
    if(ind==arr.length-1){ return 0; } 
    if(aa[ind]!=-1){return aa[ind];}
    if(ind+2<arr.length){
      return aa[ind]=Math.min(maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]),
                              maxx(arr,ind+2)+Math.abs(arr[ind]-arr[ind+2]) );
    } else{
    	return aa[ind]=maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]);
    }
    
    
  }
  
  public static void main(String[] args){
  	Scanner s=new Scanner(System.in);
    //int t=s.nextInt();
   // for(int j=0;j<t;j++){
    	int n=s.nextInt();
        int arr[]=new int[n];
      for(int i=0;i<n;i++){
      		arr[i]=s.nextInt();
      }
      aa=new long[n];
      Arrays.fill(aa,-1);
      System.out.println( maxx(arr,0)); 
   // }
    
    
  }

} Main
import java.util.*;
public class Main{
	static long[] aa;
  static long maxx(int[] arr,int ind){
  	if(ind>=arr.length){
      return Integer.MAX_VALUE;
    }
    if(ind==arr.length-1){ return 0; } 
    if(aa[ind]!=-1){return aa[ind];}
    if(ind+2<arr.length){
      return aa[ind]=Math.min(maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]),
                              maxx(arr,ind+2)+Math.abs(arr[ind]-arr[ind+2]) );
    } else{
    	return aa[ind]=maxx(arr,ind+1)+Math.abs(arr[ind]-arr[ind+1]);
    }
    
    
  }
  
  public static void main(String[] args){
  	Scanner s=new Scanner(System.in);
    //int t=s.nextInt();
   // for(int j=0;j<t;j++){
    	int n=s.nextInt();
        int arr[]=new int[n];
      for(int i=0;i<n;i++){
      		arr[i]=s.nextInt();
      }
      aa=new long[n];
      Arrays.fill(aa,-1);
      System.out.println( maxx(arr,0)); 
   // }
    
    
  }

}