import java.util.*;
public class Main{

     public static void main(String []args){
        Scanner in=new Scanner(System.in);
        
        int n=in.nextInt();
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=in.nextInt();
        }
        int dp[]=new int[n+1];
        dp[1]=0;
        dp[2]=Math.abs(A[1]-A[0]);
        for(int i=3;i<=n;i++)
        {
            dp[i]=Math.min(dp[i-2]+Math.abs(A[i-1]-A[i-3]),dp[i-1]+Math.abs(A[i-1]-A[i-2]));
        }
        System.out.println(dp[n]);
     }
} import java.util.*; util.* java public class Main{

     public static void main(String []args){
        Scanner in=new Scanner(System.in);
        
        int n=in.nextInt();
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=in.nextInt();
        }
        int dp[]=new int[n+1];
        dp[1]=0;
        dp[2]=Math.abs(A[1]-A[0]);
        for(int i=3;i<=n;i++)
        {
            dp[i]=Math.min(dp[i-2]+Math.abs(A[i-1]-A[i-3]),dp[i-1]+Math.abs(A[i-1]-A[i-2]));
        }
        System.out.println(dp[n]);
     }
} Main public static void main(String []args){
        Scanner in=new Scanner(System.in);
        
        int n=in.nextInt();
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=in.nextInt();
        }
        int dp[]=new int[n+1];
        dp[1]=0;
        dp[2]=Math.abs(A[1]-A[0]);
        for(int i=3;i<=n;i++)
        {
            dp[i]=Math.min(dp[i-2]+Math.abs(A[i-1]-A[i-3]),dp[i-1]+Math.abs(A[i-1]-A[i-2]));
        }
        System.out.println(dp[n]);
     } main {
        Scanner in=new Scanner(System.in);
        
        int n=in.nextInt();
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=in.nextInt();
        }
        int dp[]=new int[n+1];
        dp[1]=0;
        dp[2]=Math.abs(A[1]-A[0]);
        for(int i=3;i<=n;i++)
        {
            dp[i]=Math.min(dp[i-2]+Math.abs(A[i-1]-A[i-3]),dp[i-1]+Math.abs(A[i-1]-A[i-2]));
        }
        System.out.println(dp[n]);
     } Scanner in=new Scanner(System.in); in new Scanner(System.in) int n=in.nextInt(); n in.nextInt() in.nextInt in int A[]=new int[n]; A new int[n] n for(int i=0;i<n;i++)
        {
            A[i]=in.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            A[i]=in.nextInt();
        } {
            A[i]=in.nextInt();
        } A[i]=in.nextInt() A[i] A i in.nextInt() in.nextInt in int dp[]=new int[n+1]; dp new int[n+1] n+1 n 1 dp[1]=0 dp[1] dp 1 0 dp[2]=Math.abs(A[1]-A[0]) dp[2] dp 2 Math.abs(A[1]-A[0]) Math.abs Math A[1]-A[0] A[1] A 1 A[0] A 0 for(int i=3;i<=n;i++)
        {
            dp[i]=Math.min(dp[i-2]+Math.abs(A[i-1]-A[i-3]),dp[i-1]+Math.abs(A[i-1]-A[i-2]));
        } int i=3; int i=3; i 3 i<=n i n i++ i++ i {
            dp[i]=Math.min(dp[i-2]+Math.abs(A[i-1]-A[i-3]),dp[i-1]+Math.abs(A[i-1]-A[i-2]));
        } {
            dp[i]=Math.min(dp[i-2]+Math.abs(A[i-1]-A[i-3]),dp[i-1]+Math.abs(A[i-1]-A[i-2]));
        } dp[i]=Math.min(dp[i-2]+Math.abs(A[i-1]-A[i-3]),dp[i-1]+Math.abs(A[i-1]-A[i-2])) dp[i] dp i Math.min(dp[i-2]+Math.abs(A[i-1]-A[i-3]),dp[i-1]+Math.abs(A[i-1]-A[i-2])) Math.min Math dp[i-2]+Math.abs(A[i-1]-A[i-3]) dp[i-2] dp i-2 i 2 Math.abs(A[i-1]-A[i-3]) Math.abs Math A[i-1]-A[i-3] A[i-1] A i-1 i 1 A[i-3] A i-3 i 3 dp[i-1]+Math.abs(A[i-1]-A[i-2]) dp[i-1] dp i-1 i 1 Math.abs(A[i-1]-A[i-2]) Math.abs Math A[i-1]-A[i-2] A[i-1] A i-1 i 1 A[i-2] A i-2 i 2 System.out.println(dp[n]) System.out.println System.out System System.out dp[n] dp n String []args args public class Main{

     public static void main(String []args){
        Scanner in=new Scanner(System.in);
        
        int n=in.nextInt();
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=in.nextInt();
        }
        int dp[]=new int[n+1];
        dp[1]=0;
        dp[2]=Math.abs(A[1]-A[0]);
        for(int i=3;i<=n;i++)
        {
            dp[i]=Math.min(dp[i-2]+Math.abs(A[i-1]-A[i-3]),dp[i-1]+Math.abs(A[i-1]-A[i-2]));
        }
        System.out.println(dp[n]);
     }
} public class Main{

     public static void main(String []args){
        Scanner in=new Scanner(System.in);
        
        int n=in.nextInt();
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=in.nextInt();
        }
        int dp[]=new int[n+1];
        dp[1]=0;
        dp[2]=Math.abs(A[1]-A[0]);
        for(int i=3;i<=n;i++)
        {
            dp[i]=Math.min(dp[i-2]+Math.abs(A[i-1]-A[i-3]),dp[i-1]+Math.abs(A[i-1]-A[i-2]));
        }
        System.out.println(dp[n]);
     }
} Main
import java.util.*;
public class Main{

     public static void main(String []args){
        Scanner in=new Scanner(System.in);
        
        int n=in.nextInt();
        int A[]=new int[n];
        for(int i=0;i<n;i++)
        {
            A[i]=in.nextInt();
        }
        int dp[]=new int[n+1];
        dp[1]=0;
        dp[2]=Math.abs(A[1]-A[0]);
        for(int i=3;i<=n;i++)
        {
            dp[i]=Math.min(dp[i-2]+Math.abs(A[i-1]-A[i-3]),dp[i-1]+Math.abs(A[i-1]-A[i-2]));
        }
        System.out.println(dp[n]);
     }
}