//greedy is not applicable here as even if select min "diff" at each step then
//also final ans will not be optimal min possible of all answers
//eg: 30 20 50 10 50 70
//greedy: 60
//bruteforce (mainly dp): 40
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 ans=0;
      //int dp[][]=new int[][];
      //ans=minRec(a,dp,0,0);

      //if define dp[i] as "the minimum total cost to reach nth (i.e. last) stone from ith stone"
      // long dp[]=new long[size];
      // dp[n-1]=0;
      // dp[n-2]=(long)Math.abs((long)arr[n-1]-(long)arr[n-2]);
      // for(int i=n-3;i>=0;i--)
      //   dp[i]=(long)Math.min( dp[i+1]+Math.abs((long)arr[i]-(long)arr[i+1]), dp[i+2]+Math.abs((long)arr[i]-(long)arr[i+2]) );
      // System.out.println(dp[0]);
      //correct


      //if define dp[i] as "the minimum total cost to reach ith stone"
      long dp[]=new long[size];
      dp[0]=0;
      dp[1]=(long)Math.abs((long)arr[1]-(long)arr[0]);
      for(int i=2;i<n;i++)
        dp[i]=(long)Math.min( dp[i-1]+Math.abs((long)arr[i]-(long)arr[i-1]), dp[i-2]+Math.abs((long)arr[i]-(long)arr[i-2]) );
      System.out.println(dp[n-1]);
      //correct
    }
} 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 ans=0;
      //int dp[][]=new int[][];
      //ans=minRec(a,dp,0,0);

      //if define dp[i] as "the minimum total cost to reach nth (i.e. last) stone from ith stone"
      // long dp[]=new long[size];
      // dp[n-1]=0;
      // dp[n-2]=(long)Math.abs((long)arr[n-1]-(long)arr[n-2]);
      // for(int i=n-3;i>=0;i--)
      //   dp[i]=(long)Math.min( dp[i+1]+Math.abs((long)arr[i]-(long)arr[i+1]), dp[i+2]+Math.abs((long)arr[i]-(long)arr[i+2]) );
      // System.out.println(dp[0]);
      //correct


      //if define dp[i] as "the minimum total cost to reach ith stone"
      long dp[]=new long[size];
      dp[0]=0;
      dp[1]=(long)Math.abs((long)arr[1]-(long)arr[0]);
      for(int i=2;i<n;i++)
        dp[i]=(long)Math.min( dp[i-1]+Math.abs((long)arr[i]-(long)arr[i-1]), dp[i-2]+Math.abs((long)arr[i]-(long)arr[i-2]) );
      System.out.println(dp[n-1]);
      //correct
    }
} 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 ans=0;
      //int dp[][]=new int[][];
      //ans=minRec(a,dp,0,0);

      //if define dp[i] as "the minimum total cost to reach nth (i.e. last) stone from ith stone"
      // long dp[]=new long[size];
      // dp[n-1]=0;
      // dp[n-2]=(long)Math.abs((long)arr[n-1]-(long)arr[n-2]);
      // for(int i=n-3;i>=0;i--)
      //   dp[i]=(long)Math.min( dp[i+1]+Math.abs((long)arr[i]-(long)arr[i+1]), dp[i+2]+Math.abs((long)arr[i]-(long)arr[i+2]) );
      // System.out.println(dp[0]);
      //correct


      //if define dp[i] as "the minimum total cost to reach ith stone"
      long dp[]=new long[size];
      dp[0]=0;
      dp[1]=(long)Math.abs((long)arr[1]-(long)arr[0]);
      for(int i=2;i<n;i++)
        dp[i]=(long)Math.min( dp[i-1]+Math.abs((long)arr[i]-(long)arr[i-1]), dp[i-2]+Math.abs((long)arr[i]-(long)arr[i-2]) );
      System.out.println(dp[n-1]);
      //correct
    } 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 ans=0;
      //int dp[][]=new int[][];
      //ans=minRec(a,dp,0,0);

      //if define dp[i] as "the minimum total cost to reach nth (i.e. last) stone from ith stone"
      // long dp[]=new long[size];
      // dp[n-1]=0;
      // dp[n-2]=(long)Math.abs((long)arr[n-1]-(long)arr[n-2]);
      // for(int i=n-3;i>=0;i--)
      //   dp[i]=(long)Math.min( dp[i+1]+Math.abs((long)arr[i]-(long)arr[i+1]), dp[i+2]+Math.abs((long)arr[i]-(long)arr[i+2]) );
      // System.out.println(dp[0]);
      //correct


      //if define dp[i] as "the minimum total cost to reach ith stone"
      long dp[]=new long[size];
      dp[0]=0;
      dp[1]=(long)Math.abs((long)arr[1]-(long)arr[0]);
      for(int i=2;i<n;i++)
        dp[i]=(long)Math.min( dp[i-1]+Math.abs((long)arr[i]-(long)arr[i-1]), dp[i-2]+Math.abs((long)arr[i]-(long)arr[i-2]) );
      System.out.println(dp[n-1]);
      //correct
    } 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 ans=0; ans 0 long dp[]=new long[size]; dp new long[size] size dp[0]=0 dp[0] dp 0 0 dp[1]=(long)Math.abs((long)arr[1]-(long)arr[0]) dp[1] dp 1 (long)Math.abs((long)arr[1]-(long)arr[0]) Math.abs Math (long)arr[1]-(long)arr[0] (long)arr[1] arr 1 (long)arr[0] arr 0 for(int i=2;i<n;i++)
        dp[i]=(long)Math.min( dp[i-1]+Math.abs((long)arr[i]-(long)arr[i-1]), dp[i-2]+Math.abs((long)arr[i]-(long)arr[i-2]) ); int i=2; int i=2; i 2 i<n i n i++ i++ i dp[i]=(long)Math.min( dp[i-1]+Math.abs((long)arr[i]-(long)arr[i-1]), dp[i-2]+Math.abs((long)arr[i]-(long)arr[i-2]) ); dp[i]=(long)Math.min( dp[i-1]+Math.abs((long)arr[i]-(long)arr[i-1]), dp[i-2]+Math.abs((long)arr[i]-(long)arr[i-2]) ) dp[i] dp i (long)Math.min( dp[i-1]+Math.abs((long)arr[i]-(long)arr[i-1]), dp[i-2]+Math.abs((long)arr[i]-(long)arr[i-2]) ) Math.min Math dp[i-1]+Math.abs((long)arr[i]-(long)arr[i-1]) dp[i-1] dp i-1 i 1 Math.abs((long)arr[i]-(long)arr[i-1]) Math.abs Math (long)arr[i]-(long)arr[i-1] (long)arr[i] arr i (long)arr[i-1] arr i-1 i 1 dp[i-2]+Math.abs((long)arr[i]-(long)arr[i-2]) dp[i-2] dp i-2 i 2 Math.abs((long)arr[i]-(long)arr[i-2]) Math.abs Math (long)arr[i]-(long)arr[i-2] (long)arr[i] arr i (long)arr[i-2] arr i-2 i 2 System.out.println(dp[n-1]) System.out.println System.out System System.out dp[n-1] dp n-1 n 1 String args[] args 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 ans=0;
      //int dp[][]=new int[][];
      //ans=minRec(a,dp,0,0);

      //if define dp[i] as "the minimum total cost to reach nth (i.e. last) stone from ith stone"
      // long dp[]=new long[size];
      // dp[n-1]=0;
      // dp[n-2]=(long)Math.abs((long)arr[n-1]-(long)arr[n-2]);
      // for(int i=n-3;i>=0;i--)
      //   dp[i]=(long)Math.min( dp[i+1]+Math.abs((long)arr[i]-(long)arr[i+1]), dp[i+2]+Math.abs((long)arr[i]-(long)arr[i+2]) );
      // System.out.println(dp[0]);
      //correct


      //if define dp[i] as "the minimum total cost to reach ith stone"
      long dp[]=new long[size];
      dp[0]=0;
      dp[1]=(long)Math.abs((long)arr[1]-(long)arr[0]);
      for(int i=2;i<n;i++)
        dp[i]=(long)Math.min( dp[i-1]+Math.abs((long)arr[i]-(long)arr[i-1]), dp[i-2]+Math.abs((long)arr[i]-(long)arr[i-2]) );
      System.out.println(dp[n-1]);
      //correct
    }
} 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 ans=0;
      //int dp[][]=new int[][];
      //ans=minRec(a,dp,0,0);

      //if define dp[i] as "the minimum total cost to reach nth (i.e. last) stone from ith stone"
      // long dp[]=new long[size];
      // dp[n-1]=0;
      // dp[n-2]=(long)Math.abs((long)arr[n-1]-(long)arr[n-2]);
      // for(int i=n-3;i>=0;i--)
      //   dp[i]=(long)Math.min( dp[i+1]+Math.abs((long)arr[i]-(long)arr[i+1]), dp[i+2]+Math.abs((long)arr[i]-(long)arr[i+2]) );
      // System.out.println(dp[0]);
      //correct


      //if define dp[i] as "the minimum total cost to reach ith stone"
      long dp[]=new long[size];
      dp[0]=0;
      dp[1]=(long)Math.abs((long)arr[1]-(long)arr[0]);
      for(int i=2;i<n;i++)
        dp[i]=(long)Math.min( dp[i-1]+Math.abs((long)arr[i]-(long)arr[i-1]), dp[i-2]+Math.abs((long)arr[i]-(long)arr[i-2]) );
      System.out.println(dp[n-1]);
      //correct
    }
} Main
//greedy is not applicable here as even if select min "diff" at each step then
//also final ans will not be optimal min possible of all answers
//eg: 30 20 50 10 50 70
//greedy: 60
//bruteforce (mainly dp): 40
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 ans=0;
      //int dp[][]=new int[][];
      //ans=minRec(a,dp,0,0);

      //if define dp[i] as "the minimum total cost to reach nth (i.e. last) stone from ith stone"
      // long dp[]=new long[size];
      // dp[n-1]=0;
      // dp[n-2]=(long)Math.abs((long)arr[n-1]-(long)arr[n-2]);
      // for(int i=n-3;i>=0;i--)
      //   dp[i]=(long)Math.min( dp[i+1]+Math.abs((long)arr[i]-(long)arr[i+1]), dp[i+2]+Math.abs((long)arr[i]-(long)arr[i+2]) );
      // System.out.println(dp[0]);
      //correct


      //if define dp[i] as "the minimum total cost to reach ith stone"
      long dp[]=new long[size];
      dp[0]=0;
      dp[1]=(long)Math.abs((long)arr[1]-(long)arr[0]);
      for(int i=2;i<n;i++)
        dp[i]=(long)Math.min( dp[i-1]+Math.abs((long)arr[i]-(long)arr[i-1]), dp[i-2]+Math.abs((long)arr[i]-(long)arr[i-2]) );
      System.out.println(dp[n-1]);
      //correct
    }
}