import java.io.*;
import java.util.*;
public class Main{
  	/*public int minRec(int a[],int dp[],int i,int j)
    {
      if(i==n && j==n)
        	return dp[n][n];
      if(
        return Math.min( Math.abs(a[]
    }*/
	public static void main(String args[]) throws IOException{
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      int n=Integer.parseInt(br.readLine().trim());
      String s[]=br.readLine().trim().split("\\s+");
      int size=s.length;
      int arr[]=new int[size];
      for(int i=0;i<size;i++)
        arr[i]=Integer.parseInt(s[i]);
      
      int dp[] =  new int[size];
      Arrays.fill(dp, -1);
      
      System.out.println(minCost(arr, 0, dp));
      
    }
  
  public static int minCost(int arr[], int pos, int dp[]){
  	if(pos >= arr.length)
      return Integer.MAX_VALUE;
    
     if(pos == arr.length -1)
      return 0;
    
    if(dp[pos] != -1)
      	return dp[pos];
    
    if(pos+1 < arr.length)
      dp[pos] = Math.abs(arr[pos] - arr[pos+1]) + minCost(arr, pos+1,dp);
    
    if(pos+2 < arr.length)
     dp[pos] = Math.min(dp[pos], Math.abs(arr[pos] - arr[pos+2]) + minCost(arr, pos+2,dp));
    
      return dp[pos];
    
  }
} import java.io.*; io.* java import java.util.*; util.* java public class Main{
  	/*public int minRec(int a[],int dp[],int i,int j)
    {
      if(i==n && j==n)
        	return dp[n][n];
      if(
        return Math.min( Math.abs(a[]
    }*/
	public static void main(String args[]) throws IOException{
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      int n=Integer.parseInt(br.readLine().trim());
      String s[]=br.readLine().trim().split("\\s+");
      int size=s.length;
      int arr[]=new int[size];
      for(int i=0;i<size;i++)
        arr[i]=Integer.parseInt(s[i]);
      
      int dp[] =  new int[size];
      Arrays.fill(dp, -1);
      
      System.out.println(minCost(arr, 0, dp));
      
    }
  
  public static int minCost(int arr[], int pos, int dp[]){
  	if(pos >= arr.length)
      return Integer.MAX_VALUE;
    
     if(pos == arr.length -1)
      return 0;
    
    if(dp[pos] != -1)
      	return dp[pos];
    
    if(pos+1 < arr.length)
      dp[pos] = Math.abs(arr[pos] - arr[pos+1]) + minCost(arr, pos+1,dp);
    
    if(pos+2 < arr.length)
     dp[pos] = Math.min(dp[pos], Math.abs(arr[pos] - arr[pos+2]) + minCost(arr, pos+2,dp));
    
      return dp[pos];
    
  }
} Main /*public int minRec(int a[],int dp[],int i,int j)
    {
      if(i==n && j==n)
        	return dp[n][n];
      if(
        return Math.min( Math.abs(a[]
    }*/
	public static void main(String args[]) throws IOException{
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      int n=Integer.parseInt(br.readLine().trim());
      String s[]=br.readLine().trim().split("\\s+");
      int size=s.length;
      int arr[]=new int[size];
      for(int i=0;i<size;i++)
        arr[i]=Integer.parseInt(s[i]);
      
      int dp[] =  new int[size];
      Arrays.fill(dp, -1);
      
      System.out.println(minCost(arr, 0, dp));
      
    } main {
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      int n=Integer.parseInt(br.readLine().trim());
      String s[]=br.readLine().trim().split("\\s+");
      int size=s.length;
      int arr[]=new int[size];
      for(int i=0;i<size;i++)
        arr[i]=Integer.parseInt(s[i]);
      
      int dp[] =  new int[size];
      Arrays.fill(dp, -1);
      
      System.out.println(minCost(arr, 0, dp));
      
    } BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n=Integer.parseInt(br.readLine().trim()); n Integer.parseInt(br.readLine().trim()) Integer.parseInt Integer br.readLine().trim() br.readLine().trim br.readLine() br.readLine br String s[]=br.readLine().trim().split("\\s+"); s br.readLine().trim().split("\\s+") br.readLine().trim().split br.readLine().trim() br.readLine().trim br.readLine() br.readLine br "\\s+" int size=s.length; size s.length s s.length int arr[]=new int[size]; arr new int[size] size for(int i=0;i<size;i++)
        arr[i]=Integer.parseInt(s[i]); int i=0; int i=0; i 0 i<size i size i++ i++ i arr[i]=Integer.parseInt(s[i]); arr[i]=Integer.parseInt(s[i]) arr[i] arr i Integer.parseInt(s[i]) Integer.parseInt Integer s[i] s i int dp[] =  new int[size]; dp new int[size] size Arrays.fill(dp, -1) Arrays.fill Arrays dp -1 1 System.out.println(minCost(arr, 0, dp)) System.out.println System.out System System.out minCost(arr, 0, dp) minCost arr 0 dp String args[] args public static int minCost(int arr[], int pos, int dp[]){
  	if(pos >= arr.length)
      return Integer.MAX_VALUE;
    
     if(pos == arr.length -1)
      return 0;
    
    if(dp[pos] != -1)
      	return dp[pos];
    
    if(pos+1 < arr.length)
      dp[pos] = Math.abs(arr[pos] - arr[pos+1]) + minCost(arr, pos+1,dp);
    
    if(pos+2 < arr.length)
     dp[pos] = Math.min(dp[pos], Math.abs(arr[pos] - arr[pos+2]) + minCost(arr, pos+2,dp));
    
      return dp[pos];
    
  } minCost {
  	if(pos >= arr.length)
      return Integer.MAX_VALUE;
    
     if(pos == arr.length -1)
      return 0;
    
    if(dp[pos] != -1)
      	return dp[pos];
    
    if(pos+1 < arr.length)
      dp[pos] = Math.abs(arr[pos] - arr[pos+1]) + minCost(arr, pos+1,dp);
    
    if(pos+2 < arr.length)
     dp[pos] = Math.min(dp[pos], Math.abs(arr[pos] - arr[pos+2]) + minCost(arr, pos+2,dp));
    
      return dp[pos];
    
  } if(pos >= arr.length)
      return Integer.MAX_VALUE; pos >= arr.length pos arr.length arr arr.length return Integer.MAX_VALUE; Integer.MAX_VALUE Integer Integer.MAX_VALUE if(pos == arr.length -1)
      return 0; pos == arr.length -1 pos arr.length -1 arr.length arr arr.length 1 return 0; 0 if(dp[pos] != -1)
      	return dp[pos]; dp[pos] != -1 dp[pos] dp pos -1 1 return dp[pos]; dp[pos] dp pos if(pos+1 < arr.length)
      dp[pos] = Math.abs(arr[pos] - arr[pos+1]) + minCost(arr, pos+1,dp); pos+1 < arr.length pos+1 pos 1 arr.length arr arr.length dp[pos] = Math.abs(arr[pos] - arr[pos+1]) + minCost(arr, pos+1,dp) dp[pos] dp pos Math.abs(arr[pos] - arr[pos+1]) + minCost(arr, pos+1,dp) Math.abs(arr[pos] - arr[pos+1]) Math.abs Math arr[pos] - arr[pos+1] arr[pos] arr pos arr[pos+1] arr pos+1 pos 1 minCost(arr, pos+1,dp) minCost arr pos+1 pos 1 dp if(pos+2 < arr.length)
     dp[pos] = Math.min(dp[pos], Math.abs(arr[pos] - arr[pos+2]) + minCost(arr, pos+2,dp)); pos+2 < arr.length pos+2 pos 2 arr.length arr arr.length dp[pos] = Math.min(dp[pos], Math.abs(arr[pos] - arr[pos+2]) + minCost(arr, pos+2,dp)) dp[pos] dp pos Math.min(dp[pos], Math.abs(arr[pos] - arr[pos+2]) + minCost(arr, pos+2,dp)) Math.min Math dp[pos] dp pos Math.abs(arr[pos] - arr[pos+2]) + minCost(arr, pos+2,dp) Math.abs(arr[pos] - arr[pos+2]) Math.abs Math arr[pos] - arr[pos+2] arr[pos] arr pos arr[pos+2] arr pos+2 pos 2 minCost(arr, pos+2,dp) minCost arr pos+2 pos 2 dp return dp[pos]; dp[pos] dp pos int arr[] arr int pos pos int dp[] dp public class Main{
  	/*public int minRec(int a[],int dp[],int i,int j)
    {
      if(i==n && j==n)
        	return dp[n][n];
      if(
        return Math.min( Math.abs(a[]
    }*/
	public static void main(String args[]) throws IOException{
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      int n=Integer.parseInt(br.readLine().trim());
      String s[]=br.readLine().trim().split("\\s+");
      int size=s.length;
      int arr[]=new int[size];
      for(int i=0;i<size;i++)
        arr[i]=Integer.parseInt(s[i]);
      
      int dp[] =  new int[size];
      Arrays.fill(dp, -1);
      
      System.out.println(minCost(arr, 0, dp));
      
    }
  
  public static int minCost(int arr[], int pos, int dp[]){
  	if(pos >= arr.length)
      return Integer.MAX_VALUE;
    
     if(pos == arr.length -1)
      return 0;
    
    if(dp[pos] != -1)
      	return dp[pos];
    
    if(pos+1 < arr.length)
      dp[pos] = Math.abs(arr[pos] - arr[pos+1]) + minCost(arr, pos+1,dp);
    
    if(pos+2 < arr.length)
     dp[pos] = Math.min(dp[pos], Math.abs(arr[pos] - arr[pos+2]) + minCost(arr, pos+2,dp));
    
      return dp[pos];
    
  }
} public class Main{
  	/*public int minRec(int a[],int dp[],int i,int j)
    {
      if(i==n && j==n)
        	return dp[n][n];
      if(
        return Math.min( Math.abs(a[]
    }*/
	public static void main(String args[]) throws IOException{
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      int n=Integer.parseInt(br.readLine().trim());
      String s[]=br.readLine().trim().split("\\s+");
      int size=s.length;
      int arr[]=new int[size];
      for(int i=0;i<size;i++)
        arr[i]=Integer.parseInt(s[i]);
      
      int dp[] =  new int[size];
      Arrays.fill(dp, -1);
      
      System.out.println(minCost(arr, 0, dp));
      
    }
  
  public static int minCost(int arr[], int pos, int dp[]){
  	if(pos >= arr.length)
      return Integer.MAX_VALUE;
    
     if(pos == arr.length -1)
      return 0;
    
    if(dp[pos] != -1)
      	return dp[pos];
    
    if(pos+1 < arr.length)
      dp[pos] = Math.abs(arr[pos] - arr[pos+1]) + minCost(arr, pos+1,dp);
    
    if(pos+2 < arr.length)
     dp[pos] = Math.min(dp[pos], Math.abs(arr[pos] - arr[pos+2]) + minCost(arr, pos+2,dp));
    
      return dp[pos];
    
  }
} Main
import java.io.*;
import java.util.*;
public class Main{
  	/*public int minRec(int a[],int dp[],int i,int j)
    {
      if(i==n && j==n)
        	return dp[n][n];
      if(
        return Math.min( Math.abs(a[]
    }*/
	public static void main(String args[]) throws IOException{
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      int n=Integer.parseInt(br.readLine().trim());
      String s[]=br.readLine().trim().split("\\s+");
      int size=s.length;
      int arr[]=new int[size];
      for(int i=0;i<size;i++)
        arr[i]=Integer.parseInt(s[i]);
      
      int dp[] =  new int[size];
      Arrays.fill(dp, -1);
      
      System.out.println(minCost(arr, 0, dp));
      
    }
  
  public static int minCost(int arr[], int pos, int dp[]){
  	if(pos >= arr.length)
      return Integer.MAX_VALUE;
    
     if(pos == arr.length -1)
      return 0;
    
    if(dp[pos] != -1)
      	return dp[pos];
    
    if(pos+1 < arr.length)
      dp[pos] = Math.abs(arr[pos] - arr[pos+1]) + minCost(arr, pos+1,dp);
    
    if(pos+2 < arr.length)
     dp[pos] = Math.min(dp[pos], Math.abs(arr[pos] - arr[pos+2]) + minCost(arr, pos+2,dp));
    
      return dp[pos];
    
  }
}
