import java.util.Scanner;

public class Main{
    public static int minCostDp(int a[],int n){
        int dp[] = new int[n+1];
        dp[1] = 0;
        dp[2] = Math.abs(a[2]-a[1]);
        for(int i=3;i<=n;i++){
            dp[i] = Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2]));
        }
        return dp[n];
    }
    public static int minCostRecursive(int a[],int n,int i,int j,int minSum){
        if(j==n)
            return minSum+Math.abs(a[j]-a[i]);

        if(j>n)
            return Integer.MAX_VALUE;

        minSum = minSum+Math.abs(a[i]-a[j]);
        i=j;
        int ans1 = minCostRecursive(a,n,i,j+1,minSum);
        int ans2 = minCostRecursive(a,n,i,j+2,minSum);
        return Math.min(ans1,ans2);
    }
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n+1];
        for(int i=1;i<=n;i++){
            a[i] = sc.nextInt();
        }
        System.out.println(minCostDp(a,n));

    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static int minCostDp(int a[],int n){
        int dp[] = new int[n+1];
        dp[1] = 0;
        dp[2] = Math.abs(a[2]-a[1]);
        for(int i=3;i<=n;i++){
            dp[i] = Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2]));
        }
        return dp[n];
    }
    public static int minCostRecursive(int a[],int n,int i,int j,int minSum){
        if(j==n)
            return minSum+Math.abs(a[j]-a[i]);

        if(j>n)
            return Integer.MAX_VALUE;

        minSum = minSum+Math.abs(a[i]-a[j]);
        i=j;
        int ans1 = minCostRecursive(a,n,i,j+1,minSum);
        int ans2 = minCostRecursive(a,n,i,j+2,minSum);
        return Math.min(ans1,ans2);
    }
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n+1];
        for(int i=1;i<=n;i++){
            a[i] = sc.nextInt();
        }
        System.out.println(minCostDp(a,n));

    }
} Main public static int minCostDp(int a[],int n){
        int dp[] = new int[n+1];
        dp[1] = 0;
        dp[2] = Math.abs(a[2]-a[1]);
        for(int i=3;i<=n;i++){
            dp[i] = Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2]));
        }
        return dp[n];
    } minCostDp {
        int dp[] = new int[n+1];
        dp[1] = 0;
        dp[2] = Math.abs(a[2]-a[1]);
        for(int i=3;i<=n;i++){
            dp[i] = Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2]));
        }
        return dp[n];
    } 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[2]-a[1]) dp[2] dp 2 Math.abs(a[2]-a[1]) Math.abs Math a[2]-a[1] a[2] a 2 a[1] a 1 for(int i=3;i<=n;i++){
            dp[i] = Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2]));
        } int i=3; int i=3; i 3 i<=n i n i++ i++ i {
            dp[i] = Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2]));
        } {
            dp[i] = Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2]));
        } dp[i] = Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2])) dp[i] dp i Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2])) Math.min Math dp[i-1]+Math.abs(a[i]-a[i-1]) dp[i-1] dp i-1 i 1 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 dp[i-2]+Math.abs(a[i]-a[i-2]) dp[i-2] dp i-2 i 2 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 return dp[n]; dp[n] dp n int a[] a int n n public static int minCostRecursive(int a[],int n,int i,int j,int minSum){
        if(j==n)
            return minSum+Math.abs(a[j]-a[i]);

        if(j>n)
            return Integer.MAX_VALUE;

        minSum = minSum+Math.abs(a[i]-a[j]);
        i=j;
        int ans1 = minCostRecursive(a,n,i,j+1,minSum);
        int ans2 = minCostRecursive(a,n,i,j+2,minSum);
        return Math.min(ans1,ans2);
    } minCostRecursive {
        if(j==n)
            return minSum+Math.abs(a[j]-a[i]);

        if(j>n)
            return Integer.MAX_VALUE;

        minSum = minSum+Math.abs(a[i]-a[j]);
        i=j;
        int ans1 = minCostRecursive(a,n,i,j+1,minSum);
        int ans2 = minCostRecursive(a,n,i,j+2,minSum);
        return Math.min(ans1,ans2);
    } if(j==n)
            return minSum+Math.abs(a[j]-a[i]); j==n j n return minSum+Math.abs(a[j]-a[i]); minSum+Math.abs(a[j]-a[i]) minSum Math.abs(a[j]-a[i]) Math.abs Math a[j]-a[i] a[j] a j a[i] a i if(j>n)
            return Integer.MAX_VALUE; j>n j n return Integer.MAX_VALUE; Integer.MAX_VALUE Integer Integer.MAX_VALUE minSum = minSum+Math.abs(a[i]-a[j]) minSum minSum+Math.abs(a[i]-a[j]) minSum Math.abs(a[i]-a[j]) Math.abs Math a[i]-a[j] a[i] a i a[j] a j i=j i j int ans1 = minCostRecursive(a,n,i,j+1,minSum); ans1 minCostRecursive(a,n,i,j+1,minSum) minCostRecursive a n i j+1 j 1 minSum int ans2 = minCostRecursive(a,n,i,j+2,minSum); ans2 minCostRecursive(a,n,i,j+2,minSum) minCostRecursive a n i j+2 j 2 minSum return Math.min(ans1,ans2); Math.min(ans1,ans2) Math.min Math ans1 ans2 int a[] a int n n int i i int j j int minSum minSum public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n+1];
        for(int i=1;i<=n;i++){
            a[i] = sc.nextInt();
        }
        System.out.println(minCostDp(a,n));

    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n+1];
        for(int i=1;i<=n;i++){
            a[i] = sc.nextInt();
        }
        System.out.println(minCostDp(a,n));

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int a[] = new int[n+1]; a new int[n+1] n+1 n 1 for(int i=1;i<=n;i++){
            a[i] = sc.nextInt();
        } int i=1; int i=1; i 1 i<=n i n i++ i++ i {
            a[i] = sc.nextInt();
        } {
            a[i] = sc.nextInt();
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc System.out.println(minCostDp(a,n)) System.out.println System.out System System.out minCostDp(a,n) minCostDp a n String args[] args public class Main{
    public static int minCostDp(int a[],int n){
        int dp[] = new int[n+1];
        dp[1] = 0;
        dp[2] = Math.abs(a[2]-a[1]);
        for(int i=3;i<=n;i++){
            dp[i] = Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2]));
        }
        return dp[n];
    }
    public static int minCostRecursive(int a[],int n,int i,int j,int minSum){
        if(j==n)
            return minSum+Math.abs(a[j]-a[i]);

        if(j>n)
            return Integer.MAX_VALUE;

        minSum = minSum+Math.abs(a[i]-a[j]);
        i=j;
        int ans1 = minCostRecursive(a,n,i,j+1,minSum);
        int ans2 = minCostRecursive(a,n,i,j+2,minSum);
        return Math.min(ans1,ans2);
    }
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n+1];
        for(int i=1;i<=n;i++){
            a[i] = sc.nextInt();
        }
        System.out.println(minCostDp(a,n));

    }
} public class Main{
    public static int minCostDp(int a[],int n){
        int dp[] = new int[n+1];
        dp[1] = 0;
        dp[2] = Math.abs(a[2]-a[1]);
        for(int i=3;i<=n;i++){
            dp[i] = Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2]));
        }
        return dp[n];
    }
    public static int minCostRecursive(int a[],int n,int i,int j,int minSum){
        if(j==n)
            return minSum+Math.abs(a[j]-a[i]);

        if(j>n)
            return Integer.MAX_VALUE;

        minSum = minSum+Math.abs(a[i]-a[j]);
        i=j;
        int ans1 = minCostRecursive(a,n,i,j+1,minSum);
        int ans2 = minCostRecursive(a,n,i,j+2,minSum);
        return Math.min(ans1,ans2);
    }
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n+1];
        for(int i=1;i<=n;i++){
            a[i] = sc.nextInt();
        }
        System.out.println(minCostDp(a,n));

    }
} Main
import java.util.Scanner;

public class Main{
    public static int minCostDp(int a[],int n){
        int dp[] = new int[n+1];
        dp[1] = 0;
        dp[2] = Math.abs(a[2]-a[1]);
        for(int i=3;i<=n;i++){
            dp[i] = Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2]));
        }
        return dp[n];
    }
    public static int minCostRecursive(int a[],int n,int i,int j,int minSum){
        if(j==n)
            return minSum+Math.abs(a[j]-a[i]);

        if(j>n)
            return Integer.MAX_VALUE;

        minSum = minSum+Math.abs(a[i]-a[j]);
        i=j;
        int ans1 = minCostRecursive(a,n,i,j+1,minSum);
        int ans2 = minCostRecursive(a,n,i,j+2,minSum);
        return Math.min(ans1,ans2);
    }
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n+1];
        for(int i=1;i<=n;i++){
            a[i] = sc.nextInt();
        }
        System.out.println(minCostDp(a,n));

    }
}