import java.util.*;
import java.util.Arrays;
public class Main{
  public static int[] A;
  
  public static int[]dp;
  
  public static int solve(int i, int N){
   	 if(i == N) return 0;
     if(dp[i]!=-1) return dp[i];
     int cost =0;
     if( (i+1)<=N){
     	cost= Math.abs(A[i]-A[i+1]) + solve(i+1,N);
     }
     if( (i+2)<=N){
      	cost= Math.min(cost, Math.abs(A[i]-A[i+2])  + solve(i+2,N)); 
     }
    dp[i] = cost;
    return cost;
  }
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    
    int N = s.nextInt();
    A = new int[N];
    dp = new int[N];
    Arrays.fill(dp, -1);
    
    for(int i=0;i<N;i++){
     	A[i]=s.nextInt(); 
    }
    
    System.out.println(solve(0,N-1));
  }
} import java.util.*; util.* java import java.util.Arrays; Arrays java.util public class Main{
  public static int[] A;
  
  public static int[]dp;
  
  public static int solve(int i, int N){
   	 if(i == N) return 0;
     if(dp[i]!=-1) return dp[i];
     int cost =0;
     if( (i+1)<=N){
     	cost= Math.abs(A[i]-A[i+1]) + solve(i+1,N);
     }
     if( (i+2)<=N){
      	cost= Math.min(cost, Math.abs(A[i]-A[i+2])  + solve(i+2,N)); 
     }
    dp[i] = cost;
    return cost;
  }
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    
    int N = s.nextInt();
    A = new int[N];
    dp = new int[N];
    Arrays.fill(dp, -1);
    
    for(int i=0;i<N;i++){
     	A[i]=s.nextInt(); 
    }
    
    System.out.println(solve(0,N-1));
  }
} Main public static int[] A; A public static int[]dp; dp public static int solve(int i, int N){
   	 if(i == N) return 0;
     if(dp[i]!=-1) return dp[i];
     int cost =0;
     if( (i+1)<=N){
     	cost= Math.abs(A[i]-A[i+1]) + solve(i+1,N);
     }
     if( (i+2)<=N){
      	cost= Math.min(cost, Math.abs(A[i]-A[i+2])  + solve(i+2,N)); 
     }
    dp[i] = cost;
    return cost;
  } solve {
   	 if(i == N) return 0;
     if(dp[i]!=-1) return dp[i];
     int cost =0;
     if( (i+1)<=N){
     	cost= Math.abs(A[i]-A[i+1]) + solve(i+1,N);
     }
     if( (i+2)<=N){
      	cost= Math.min(cost, Math.abs(A[i]-A[i+2])  + solve(i+2,N)); 
     }
    dp[i] = cost;
    return cost;
  } if(i == N) return 0; i == N i N 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 cost =0; cost 0 if( (i+1)<=N){
     	cost= Math.abs(A[i]-A[i+1]) + solve(i+1,N);
     } (i+1)<=N (i+1) i 1 N {
     	cost= Math.abs(A[i]-A[i+1]) + solve(i+1,N);
     } cost= Math.abs(A[i]-A[i+1]) + solve(i+1,N) cost Math.abs(A[i]-A[i+1]) + solve(i+1,N) Math.abs(A[i]-A[i+1]) Math.abs Math A[i]-A[i+1] A[i] A i A[i+1] A i+1 i 1 solve(i+1,N) solve i+1 i 1 N if( (i+2)<=N){
      	cost= Math.min(cost, Math.abs(A[i]-A[i+2])  + solve(i+2,N)); 
     } (i+2)<=N (i+2) i 2 N {
      	cost= Math.min(cost, Math.abs(A[i]-A[i+2])  + solve(i+2,N)); 
     } cost= Math.min(cost, Math.abs(A[i]-A[i+2])  + solve(i+2,N)) cost Math.min(cost, Math.abs(A[i]-A[i+2])  + solve(i+2,N)) Math.min Math cost Math.abs(A[i]-A[i+2])  + solve(i+2,N) Math.abs(A[i]-A[i+2]) Math.abs Math A[i]-A[i+2] A[i] A i A[i+2] A i+2 i 2 solve(i+2,N) solve i+2 i 2 N dp[i] = cost dp[i] dp i cost return cost; cost int i i int N N public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    
    int N = s.nextInt();
    A = new int[N];
    dp = new int[N];
    Arrays.fill(dp, -1);
    
    for(int i=0;i<N;i++){
     	A[i]=s.nextInt(); 
    }
    
    System.out.println(solve(0,N-1));
  } main {
    Scanner s = new Scanner(System.in);
    
    int N = s.nextInt();
    A = new int[N];
    dp = new int[N];
    Arrays.fill(dp, -1);
    
    for(int i=0;i<N;i++){
     	A[i]=s.nextInt(); 
    }
    
    System.out.println(solve(0,N-1));
  } Scanner s = new Scanner(System.in); s new Scanner(System.in) int N = s.nextInt(); N s.nextInt() s.nextInt s A = new int[N] A new int[N] N dp = new int[N] dp new int[N] N Arrays.fill(dp, -1) Arrays.fill Arrays dp -1 1 for(int i=0;i<N;i++){
     	A[i]=s.nextInt(); 
    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
     	A[i]=s.nextInt(); 
    } {
     	A[i]=s.nextInt(); 
    } A[i]=s.nextInt() A[i] A i s.nextInt() s.nextInt s System.out.println(solve(0,N-1)) System.out.println System.out System System.out solve(0,N-1) solve 0 N-1 N 1 String[] args args public class Main{
  public static int[] A;
  
  public static int[]dp;
  
  public static int solve(int i, int N){
   	 if(i == N) return 0;
     if(dp[i]!=-1) return dp[i];
     int cost =0;
     if( (i+1)<=N){
     	cost= Math.abs(A[i]-A[i+1]) + solve(i+1,N);
     }
     if( (i+2)<=N){
      	cost= Math.min(cost, Math.abs(A[i]-A[i+2])  + solve(i+2,N)); 
     }
    dp[i] = cost;
    return cost;
  }
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    
    int N = s.nextInt();
    A = new int[N];
    dp = new int[N];
    Arrays.fill(dp, -1);
    
    for(int i=0;i<N;i++){
     	A[i]=s.nextInt(); 
    }
    
    System.out.println(solve(0,N-1));
  }
} public class Main{
  public static int[] A;
  
  public static int[]dp;
  
  public static int solve(int i, int N){
   	 if(i == N) return 0;
     if(dp[i]!=-1) return dp[i];
     int cost =0;
     if( (i+1)<=N){
     	cost= Math.abs(A[i]-A[i+1]) + solve(i+1,N);
     }
     if( (i+2)<=N){
      	cost= Math.min(cost, Math.abs(A[i]-A[i+2])  + solve(i+2,N)); 
     }
    dp[i] = cost;
    return cost;
  }
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    
    int N = s.nextInt();
    A = new int[N];
    dp = new int[N];
    Arrays.fill(dp, -1);
    
    for(int i=0;i<N;i++){
     	A[i]=s.nextInt(); 
    }
    
    System.out.println(solve(0,N-1));
  }
} Main
import java.util.*;
import java.util.Arrays;
public class Main{
  public static int[] A;
  
  public static int[]dp;
  
  public static int solve(int i, int N){
   	 if(i == N) return 0;
     if(dp[i]!=-1) return dp[i];
     int cost =0;
     if( (i+1)<=N){
     	cost= Math.abs(A[i]-A[i+1]) + solve(i+1,N);
     }
     if( (i+2)<=N){
      	cost= Math.min(cost, Math.abs(A[i]-A[i+2])  + solve(i+2,N)); 
     }
    dp[i] = cost;
    return cost;
  }
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    
    int N = s.nextInt();
    A = new int[N];
    dp = new int[N];
    Arrays.fill(dp, -1);
    
    for(int i=0;i<N;i++){
     	A[i]=s.nextInt(); 
    }
    
    System.out.println(solve(0,N-1));
  }
}