import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int h[]=new int[n+1];
        for(int i=1;i<=n;i++)
        h[i]=sc.nextInt();

        int dp[]=new int[n+1];
        dp[1]=0;
        for(int i=2;i<=n;i++)
        {
            int ans1=1000000000,ans2=1000000000;
            ans1=dp[i-1]+Math.abs(h[i]-h[i-1]);
            if(i-2>=1)
            ans2=dp[i-2]+Math.abs(h[i]-h[i-2]);

            dp[i]=Math.min(ans1,ans2);
        }
        System.out.println(dp[n]);

        
    }
} import java.util.*; util.* java public class Main {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int h[]=new int[n+1];
        for(int i=1;i<=n;i++)
        h[i]=sc.nextInt();

        int dp[]=new int[n+1];
        dp[1]=0;
        for(int i=2;i<=n;i++)
        {
            int ans1=1000000000,ans2=1000000000;
            ans1=dp[i-1]+Math.abs(h[i]-h[i-1]);
            if(i-2>=1)
            ans2=dp[i-2]+Math.abs(h[i]-h[i-2]);

            dp[i]=Math.min(ans1,ans2);
        }
        System.out.println(dp[n]);

        
    }
} Main public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int h[]=new int[n+1];
        for(int i=1;i<=n;i++)
        h[i]=sc.nextInt();

        int dp[]=new int[n+1];
        dp[1]=0;
        for(int i=2;i<=n;i++)
        {
            int ans1=1000000000,ans2=1000000000;
            ans1=dp[i-1]+Math.abs(h[i]-h[i-1]);
            if(i-2>=1)
            ans2=dp[i-2]+Math.abs(h[i]-h[i-2]);

            dp[i]=Math.min(ans1,ans2);
        }
        System.out.println(dp[n]);

        
    } main {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int h[]=new int[n+1];
        for(int i=1;i<=n;i++)
        h[i]=sc.nextInt();

        int dp[]=new int[n+1];
        dp[1]=0;
        for(int i=2;i<=n;i++)
        {
            int ans1=1000000000,ans2=1000000000;
            ans1=dp[i-1]+Math.abs(h[i]-h[i-1]);
            if(i-2>=1)
            ans2=dp[i-2]+Math.abs(h[i]-h[i-2]);

            dp[i]=Math.min(ans1,ans2);
        }
        System.out.println(dp[n]);

        
    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int h[]=new int[n+1]; h new int[n+1] n+1 n 1 for(int i=1;i<=n;i++)
        h[i]=sc.nextInt(); int i=1; int i=1; i 1 i<=n i n i++ i++ i h[i]=sc.nextInt(); h[i]=sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc int dp[]=new int[n+1]; dp new int[n+1] n+1 n 1 dp[1]=0 dp[1] dp 1 0 for(int i=2;i<=n;i++)
        {
            int ans1=1000000000,ans2=1000000000;
            ans1=dp[i-1]+Math.abs(h[i]-h[i-1]);
            if(i-2>=1)
            ans2=dp[i-2]+Math.abs(h[i]-h[i-2]);

            dp[i]=Math.min(ans1,ans2);
        } int i=2; int i=2; i 2 i<=n i n i++ i++ i {
            int ans1=1000000000,ans2=1000000000;
            ans1=dp[i-1]+Math.abs(h[i]-h[i-1]);
            if(i-2>=1)
            ans2=dp[i-2]+Math.abs(h[i]-h[i-2]);

            dp[i]=Math.min(ans1,ans2);
        } {
            int ans1=1000000000,ans2=1000000000;
            ans1=dp[i-1]+Math.abs(h[i]-h[i-1]);
            if(i-2>=1)
            ans2=dp[i-2]+Math.abs(h[i]-h[i-2]);

            dp[i]=Math.min(ans1,ans2);
        } int ans1=1000000000 ans1 1000000000 ans2=1000000000; ans2 1000000000 ans1=dp[i-1]+Math.abs(h[i]-h[i-1]) ans1 dp[i-1]+Math.abs(h[i]-h[i-1]) dp[i-1] dp i-1 i 1 Math.abs(h[i]-h[i-1]) Math.abs Math h[i]-h[i-1] h[i] h i h[i-1] h i-1 i 1 if(i-2>=1)
            ans2=dp[i-2]+Math.abs(h[i]-h[i-2]); i-2>=1 i-2 i 2 1 ans2=dp[i-2]+Math.abs(h[i]-h[i-2]) ans2 dp[i-2]+Math.abs(h[i]-h[i-2]) dp[i-2] dp i-2 i 2 Math.abs(h[i]-h[i-2]) Math.abs Math h[i]-h[i-2] h[i] h i h[i-2] h i-2 i 2 dp[i]=Math.min(ans1,ans2) dp[i] dp i Math.min(ans1,ans2) Math.min Math ans1 ans2 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 sc=new Scanner(System.in);
        int n=sc.nextInt();
        int h[]=new int[n+1];
        for(int i=1;i<=n;i++)
        h[i]=sc.nextInt();

        int dp[]=new int[n+1];
        dp[1]=0;
        for(int i=2;i<=n;i++)
        {
            int ans1=1000000000,ans2=1000000000;
            ans1=dp[i-1]+Math.abs(h[i]-h[i-1]);
            if(i-2>=1)
            ans2=dp[i-2]+Math.abs(h[i]-h[i-2]);

            dp[i]=Math.min(ans1,ans2);
        }
        System.out.println(dp[n]);

        
    }
} public class Main {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int h[]=new int[n+1];
        for(int i=1;i<=n;i++)
        h[i]=sc.nextInt();

        int dp[]=new int[n+1];
        dp[1]=0;
        for(int i=2;i<=n;i++)
        {
            int ans1=1000000000,ans2=1000000000;
            ans1=dp[i-1]+Math.abs(h[i]-h[i-1]);
            if(i-2>=1)
            ans2=dp[i-2]+Math.abs(h[i]-h[i-2]);

            dp[i]=Math.min(ans1,ans2);
        }
        System.out.println(dp[n]);

        
    }
} Main
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int h[]=new int[n+1];
        for(int i=1;i<=n;i++)
        h[i]=sc.nextInt();

        int dp[]=new int[n+1];
        dp[1]=0;
        for(int i=2;i<=n;i++)
        {
            int ans1=1000000000,ans2=1000000000;
            ans1=dp[i-1]+Math.abs(h[i]-h[i-1]);
            if(i-2>=1)
            ans2=dp[i-2]+Math.abs(h[i]-h[i-2]);

            dp[i]=Math.min(ans1,ans2);
        }
        System.out.println(dp[n]);

        
    }
}