// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;



int b[100000];



ll haha(int a[], int n){

    if (b[n] != -1) return b[n];

    if(n == 2){

        if(abs(a[2]-a[0])> abs(a[2]-a[1]) + abs(a[1]- a[0])) return abs(a[2]-a[1]) + abs(a[1]- a[0]);

        return abs(a[2]-a[0]);

    }

    if(n==1) return abs ((a[0] - a[1]));

    b[n] = min ((abs(a[n]-a[n-1]) + haha(a, n-1)), (abs(a[n]-a[n-2]) + haha(a, n-2)));

    return b[n];





}



int main(){

    for(int i = 0; i<100000; i++){

        b[i] = -1;

    }

    int n; cin >> n;

    int a[n];

    for(int i =0; i<n; i++){

        cin >> a[i];

    }

    cout << haha(a, n-1);



}

// Optimized solution to the same problem (faster):
                #include <bits/stdc++.h>

                using namespace std;

                #define rep(i,k,n) for(int i = k; i < n; i++)  

                #define repp(i,k,n) for(int i = k; i <= n; i++) 

                #define per(i,k,n) for(int i = k; i >= n; i--)



                #define int long long

                #define all(a) a.begin(),a.end()       

                



                #define pb push_back

                typedef long long ll; 

                typedef pair<int, int> ii;

                typedef pair<int,ii > iii; 

                typedef vector<ii> vii;

                typedef vector<char> vchar;

                typedef vector<int> vi;

                #define ff first

                #define ss second



                #define mem(a, b) memset(a, b, sizeof(a));

                #define mem0(a) memset(a, 0, sizeof(a));



                #define INF 1000000000

                //#define mod 1000000007





                /*=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=*/





                #define endl "\n"

                #define make_graph(m) repp(i, 1, m){ll a, b; cin >> a >> b; gr[a].pb(b), gr[b].pb(a);}

                #define make(a,n) vector<long long> a; rep(i,0,n){ long long temp; cin >> temp; a.push_back(temp);}

                #define printall(c,n) for(int i=0; i< n;i++)cout << c[i] << " ";

                



                /*=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=\=/=*/

           

           

                //int parent[1000000];

                //int asize[1000000];



            /*    int lead (int n){

                    if(parent[n]==n)return n;

                    parent[n] = lead(parent[n]);

                    return parent[n];

                }



                void join (int a, int b){

                    a=lead(a);

                    b=lead(b);

                    

                    if(a!=b){

                        if(a<b)swap(a,b);

                        parent[b] = a;

                        asize[a]+=asize[b];

                    }

                    

                    return;

                }

            */



            /*  int mod;



                int modPow(int a, int b){

                    if(b%2==0){

                        int x = a*a;

                        x%=mod;

                        return modPow(x,b/2);

                    }

                    return (a*modPow(a,b-1))%mod;

                }

            */



                const int MAXN=1000005;

                int a[MAXN];



                int dp[MAXN];

                

                int fun(int n){

                    if(dp[n]!=-1)return dp[n];

                    if(n==2){

                        return min(abs(a[2]-a[0]), (abs(a[2]-a[1])+abs(a[1]-a[0])) );

                    }

                    if(n==1){

                        return(abs(a[1]-a[0]));

                    }

                    dp[n] = min(fun(n-1)+abs(a[n]-a[n-1]),fun(n-2)+abs(a[n]-a[n-2]));

                    return dp[n];

                }

           



                signed main(){

                    ios_base::sync_with_stdio(false);

                    cin.tie(0);

                    cout.tie(0);

                    //cout << fixed;

                    //cout <<setprecision(2);

                    

                    int test=1;



                    //cin >> test;



                    while(test--)

                    {

                        int n;

                        cin >> n;

                        rep(i,0,n){

                            cin >> a[i];

                            dp[i]=-1;

                        }

                        cout << fun(n-1)<<endl;

                        



                    

                    



                    }

                }

// Fastest known solution for this problem: