import java.io.*;
public class Main{
 
  public static int findCost(int arr[],int i,int dp[])
  {
	int n=arr.length;
 
    if(i>=n-1)
      return 0;
    int ans1=Integer.MAX_VALUE,ans2=Integer.MAX_VALUE;
    if(dp[i]==Integer.MAX_VALUE) {
    if((i+1)<n)
    ans1=Math.abs(arr[i]-arr[i+1])+findCost(arr,i+1,dp);
    if((i+2)<n)
    ans2=Math.abs(arr[i]-arr[i+2])+findCost(arr,i+2,dp);
    dp[i]=Math.min(ans1, ans2);}
    return dp[i];
    
  }
  
  public static void main(String[] args) throws IOException
  {
     
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int n=Integer.parseInt(br.readLine());
    String line=br.readLine();
    String str[]=line.trim().split("\\s+");
    int arr[]=new int[n];
    for(int i=0;i<n;i++)
    {
      arr[i]=Integer.parseInt(str[i]);
     // System.out.println(arr[i]);
    }
    int dp[]=new int[n];
    for(int i=0;i<n;i++)
    	dp[i]=Integer.MAX_VALUE;
    System.out.print(findCost(arr,0,dp));
    
  }
} import java.io.*; io.* java public class Main{
 
  public static int findCost(int arr[],int i,int dp[])
  {
	int n=arr.length;
 
    if(i>=n-1)
      return 0;
    int ans1=Integer.MAX_VALUE,ans2=Integer.MAX_VALUE;
    if(dp[i]==Integer.MAX_VALUE) {
    if((i+1)<n)
    ans1=Math.abs(arr[i]-arr[i+1])+findCost(arr,i+1,dp);
    if((i+2)<n)
    ans2=Math.abs(arr[i]-arr[i+2])+findCost(arr,i+2,dp);
    dp[i]=Math.min(ans1, ans2);}
    return dp[i];
    
  }
  
  public static void main(String[] args) throws IOException
  {
     
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int n=Integer.parseInt(br.readLine());
    String line=br.readLine();
    String str[]=line.trim().split("\\s+");
    int arr[]=new int[n];
    for(int i=0;i<n;i++)
    {
      arr[i]=Integer.parseInt(str[i]);
     // System.out.println(arr[i]);
    }
    int dp[]=new int[n];
    for(int i=0;i<n;i++)
    	dp[i]=Integer.MAX_VALUE;
    System.out.print(findCost(arr,0,dp));
    
  }
} Main public static int findCost(int arr[],int i,int dp[])
  {
	int n=arr.length;
 
    if(i>=n-1)
      return 0;
    int ans1=Integer.MAX_VALUE,ans2=Integer.MAX_VALUE;
    if(dp[i]==Integer.MAX_VALUE) {
    if((i+1)<n)
    ans1=Math.abs(arr[i]-arr[i+1])+findCost(arr,i+1,dp);
    if((i+2)<n)
    ans2=Math.abs(arr[i]-arr[i+2])+findCost(arr,i+2,dp);
    dp[i]=Math.min(ans1, ans2);}
    return dp[i];
    
  } findCost {
	int n=arr.length;
 
    if(i>=n-1)
      return 0;
    int ans1=Integer.MAX_VALUE,ans2=Integer.MAX_VALUE;
    if(dp[i]==Integer.MAX_VALUE) {
    if((i+1)<n)
    ans1=Math.abs(arr[i]-arr[i+1])+findCost(arr,i+1,dp);
    if((i+2)<n)
    ans2=Math.abs(arr[i]-arr[i+2])+findCost(arr,i+2,dp);
    dp[i]=Math.min(ans1, ans2);}
    return dp[i];
    
  } int n=arr.length; n arr.length arr arr.length if(i>=n-1)
      return 0; i>=n-1 i n-1 n 1 return 0; 0 int ans1=Integer.MAX_VALUE ans1 Integer.MAX_VALUE Integer Integer.MAX_VALUE ans2=Integer.MAX_VALUE; ans2 Integer.MAX_VALUE Integer Integer.MAX_VALUE if(dp[i]==Integer.MAX_VALUE) {
    if((i+1)<n)
    ans1=Math.abs(arr[i]-arr[i+1])+findCost(arr,i+1,dp);
    if((i+2)<n)
    ans2=Math.abs(arr[i]-arr[i+2])+findCost(arr,i+2,dp);
    dp[i]=Math.min(ans1, ans2);} dp[i]==Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE {
    if((i+1)<n)
    ans1=Math.abs(arr[i]-arr[i+1])+findCost(arr,i+1,dp);
    if((i+2)<n)
    ans2=Math.abs(arr[i]-arr[i+2])+findCost(arr,i+2,dp);
    dp[i]=Math.min(ans1, ans2);} if((i+1)<n)
    ans1=Math.abs(arr[i]-arr[i+1])+findCost(arr,i+1,dp); (i+1)<n (i+1) i 1 n ans1=Math.abs(arr[i]-arr[i+1])+findCost(arr,i+1,dp) ans1 Math.abs(arr[i]-arr[i+1])+findCost(arr,i+1,dp) Math.abs(arr[i]-arr[i+1]) Math.abs Math arr[i]-arr[i+1] arr[i] arr i arr[i+1] arr i+1 i 1 findCost(arr,i+1,dp) findCost arr i+1 i 1 dp if((i+2)<n)
    ans2=Math.abs(arr[i]-arr[i+2])+findCost(arr,i+2,dp); (i+2)<n (i+2) i 2 n ans2=Math.abs(arr[i]-arr[i+2])+findCost(arr,i+2,dp) ans2 Math.abs(arr[i]-arr[i+2])+findCost(arr,i+2,dp) Math.abs(arr[i]-arr[i+2]) Math.abs Math arr[i]-arr[i+2] arr[i] arr i arr[i+2] arr i+2 i 2 findCost(arr,i+2,dp) findCost arr i+2 i 2 dp dp[i]=Math.min(ans1, ans2) dp[i] dp i Math.min(ans1, ans2) Math.min Math ans1 ans2 return dp[i]; dp[i] dp i int arr[] arr int i i int dp[] dp public static void main(String[] args) throws IOException
  {
     
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int n=Integer.parseInt(br.readLine());
    String line=br.readLine();
    String str[]=line.trim().split("\\s+");
    int arr[]=new int[n];
    for(int i=0;i<n;i++)
    {
      arr[i]=Integer.parseInt(str[i]);
     // System.out.println(arr[i]);
    }
    int dp[]=new int[n];
    for(int i=0;i<n;i++)
    	dp[i]=Integer.MAX_VALUE;
    System.out.print(findCost(arr,0,dp));
    
  } main {
     
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int n=Integer.parseInt(br.readLine());
    String line=br.readLine();
    String str[]=line.trim().split("\\s+");
    int arr[]=new int[n];
    for(int i=0;i<n;i++)
    {
      arr[i]=Integer.parseInt(str[i]);
     // System.out.println(arr[i]);
    }
    int dp[]=new int[n];
    for(int i=0;i<n;i++)
    	dp[i]=Integer.MAX_VALUE;
    System.out.print(findCost(arr,0,dp));
    
  } BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n=Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br String line=br.readLine(); line br.readLine() br.readLine br String str[]=line.trim().split("\\s+"); str line.trim().split("\\s+") line.trim().split line.trim() line.trim line "\\s+" int arr[]=new int[n]; arr new int[n] n for(int i=0;i<n;i++)
    {
      arr[i]=Integer.parseInt(str[i]);
     // System.out.println(arr[i]);
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      arr[i]=Integer.parseInt(str[i]);
     // System.out.println(arr[i]);
    } {
      arr[i]=Integer.parseInt(str[i]);
     // System.out.println(arr[i]);
    } arr[i]=Integer.parseInt(str[i]) arr[i] arr i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i int dp[]=new int[n]; dp new int[n] n for(int i=0;i<n;i++)
    	dp[i]=Integer.MAX_VALUE; int i=0; int i=0; i 0 i<n i n i++ i++ i dp[i]=Integer.MAX_VALUE; dp[i]=Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE System.out.print(findCost(arr,0,dp)) System.out.print System.out System System.out findCost(arr,0,dp) findCost arr 0 dp String[] args args public class Main{
 
  public static int findCost(int arr[],int i,int dp[])
  {
	int n=arr.length;
 
    if(i>=n-1)
      return 0;
    int ans1=Integer.MAX_VALUE,ans2=Integer.MAX_VALUE;
    if(dp[i]==Integer.MAX_VALUE) {
    if((i+1)<n)
    ans1=Math.abs(arr[i]-arr[i+1])+findCost(arr,i+1,dp);
    if((i+2)<n)
    ans2=Math.abs(arr[i]-arr[i+2])+findCost(arr,i+2,dp);
    dp[i]=Math.min(ans1, ans2);}
    return dp[i];
    
  }
  
  public static void main(String[] args) throws IOException
  {
     
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int n=Integer.parseInt(br.readLine());
    String line=br.readLine();
    String str[]=line.trim().split("\\s+");
    int arr[]=new int[n];
    for(int i=0;i<n;i++)
    {
      arr[i]=Integer.parseInt(str[i]);
     // System.out.println(arr[i]);
    }
    int dp[]=new int[n];
    for(int i=0;i<n;i++)
    	dp[i]=Integer.MAX_VALUE;
    System.out.print(findCost(arr,0,dp));
    
  }
} public class Main{
 
  public static int findCost(int arr[],int i,int dp[])
  {
	int n=arr.length;
 
    if(i>=n-1)
      return 0;
    int ans1=Integer.MAX_VALUE,ans2=Integer.MAX_VALUE;
    if(dp[i]==Integer.MAX_VALUE) {
    if((i+1)<n)
    ans1=Math.abs(arr[i]-arr[i+1])+findCost(arr,i+1,dp);
    if((i+2)<n)
    ans2=Math.abs(arr[i]-arr[i+2])+findCost(arr,i+2,dp);
    dp[i]=Math.min(ans1, ans2);}
    return dp[i];
    
  }
  
  public static void main(String[] args) throws IOException
  {
     
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int n=Integer.parseInt(br.readLine());
    String line=br.readLine();
    String str[]=line.trim().split("\\s+");
    int arr[]=new int[n];
    for(int i=0;i<n;i++)
    {
      arr[i]=Integer.parseInt(str[i]);
     // System.out.println(arr[i]);
    }
    int dp[]=new int[n];
    for(int i=0;i<n;i++)
    	dp[i]=Integer.MAX_VALUE;
    System.out.print(findCost(arr,0,dp));
    
  }
} Main
import java.io.*;
public class Main{
 
  public static int findCost(int arr[],int i,int dp[])
  {
	int n=arr.length;
 
    if(i>=n-1)
      return 0;
    int ans1=Integer.MAX_VALUE,ans2=Integer.MAX_VALUE;
    if(dp[i]==Integer.MAX_VALUE) {
    if((i+1)<n)
    ans1=Math.abs(arr[i]-arr[i+1])+findCost(arr,i+1,dp);
    if((i+2)<n)
    ans2=Math.abs(arr[i]-arr[i+2])+findCost(arr,i+2,dp);
    dp[i]=Math.min(ans1, ans2);}
    return dp[i];
    
  }
  
  public static void main(String[] args) throws IOException
  {
     
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int n=Integer.parseInt(br.readLine());
    String line=br.readLine();
    String str[]=line.trim().split("\\s+");
    int arr[]=new int[n];
    for(int i=0;i<n;i++)
    {
      arr[i]=Integer.parseInt(str[i]);
     // System.out.println(arr[i]);
    }
    int dp[]=new int[n];
    for(int i=0;i<n;i++)
    	dp[i]=Integer.MAX_VALUE;
    System.out.print(findCost(arr,0,dp));
    
  }
}