stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define ll long long

#define endl "\n"

using namespace std;

inline int D()

{

    int t;

    scanf("%d",&t);

    return t;

}

inline ll llD()

{

    ll t;

    scanf("%lld",&t);

    return t;

}



const int Max=1e6+9;

const int OO=-1e6;

int st[4]= {1,0,0,-1};

int nt[4]= {0,1,-1,0};

int n,m;

bool valid(int x,int y)

{

    return x>-1 && y>-1 && x<n && y<m;

}

ll mem[Max];

void init()

{

    memset(mem,-1,sizeof mem);

}

//////////////////////////////////////////////////////////



ll a[Max];



ll solve (int i )

{

    if(i==n-1)return 0;

    if(i>=n)

        return Max;



    ll &ret=mem[i];

    if(~ret)return ret;



    ll take1 =solve(i+1)+abs(a[i]-a[i+1]);

    ll take2 =solve(i+2)+abs(a[i]-a[i+2]);



     return mem[i]=min(take2,take1);

}



void Fast()

{

    std::ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    cerr.tie(0);

}

int main()

{

   init();

   n =D();

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

   {

       a[i]=llD();

   }

   printf("%lld",solve(0));



}


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

#define ll long long

using namespace std;



int dp[100005], a[100005];

int n;



int main()

{

    cin>>n;

    for(int i=1; i<=n; i++)

        cin>>a[i];



    dp[1]=0;

    for(int i=2; i<=n; i++)

    {

        dp[i]=dp[i-1] + abs(a[i]-a[i-1]);

        if(i>2)

            dp[i]=min(dp[i], dp[i-2] + abs(a[i]-a[i-2]));

    }

    cout<< dp[n] <<endl;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

const double eps=1e-6,pi=acos(-1);

const int N=1e5+5,M=1e9+7,SEGM=4*N,OO=0x3f3f3f3f;

int n,m,a[N],b[N],c[N];

int mem[N];



int solve(int i=0){

    if(i>=n) return 1e9;

    if(i==n-1) return 0;

    int &ret=mem[i];

    if(~ret) return ret;

    ret=1e9;

    ret=min(ret,solve(i+1)+abs(a[i]-a[i+1]));

    ret=min(ret,solve(i+2)+abs(a[i]-a[i+2]));

    return ret;

}



int main(){

    //freopen("myfile.txt","w",stdout);

    scanf("%d",&n);

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

        scanf("%d",a+i);

    memset(mem,-1,sizeof mem);

    printf("%d",solve());

    return 0;

}


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

#define ll long long

using namespace std;



int dp[100005], a[100005];

int n;



int main()

{

    cin>>n;

    for(int i=1; i<=n; i++)

        cin>>a[i];



    dp[1]=0;

    for(int i=2; i<=n; i++)

    {

        dp[i]=dp[i-1] + abs(a[i]-a[i-1]);

        if(i>2)

            dp[i]=min(dp[i], dp[i-2] + abs(a[i]-a[i-2]));

    }

    cout<< dp[n] <<endl;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

 

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//#pragma GCC optimize("Ofast")

//1.0 * clock() / CLOCKS_PER_SEC

 

#define fi first

#define se second

#define ll long long int

#define dl double long

 

using namespace std;

 

const int N = 1e5 + 7;

const ll mod = 1e9 + 7;



vector<int> dp(N);



void solve1()

{

	int n;

	cin >> n;

	int ar[n];

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

		cin >> ar[i];

	dp[1] = 0;

	dp[2] = abs(ar[1] - ar[0]);

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

		dp[i] = min(abs(ar[i - 1] - ar[i - 2]) + dp[i - 1], abs(ar[i - 1] - ar[i - 3]) + dp[i - 2]);

	}

	cout << dp[n];

}

int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0); cout.tie(0); srand(time(0));

    //freopen( "input.txt" , "r" , stdin );

    //freopen( "output.txt" , "w" , stdout );

	//freopen( "blist.in" , "r" , stdin );

    //freopen( "blist.out" , "w" , stdout );

    

    int cghf = 1;//cin >> cghf;

    while( cghf-- ){

        solve1();

    }

}


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

#define ll long long

using namespace std;



int dp[100005], a[100005];

int n;



int main()

{

    cin>>n;

    for(int i=1; i<=n; i++)

        cin>>a[i];



    dp[1]=0;

    for(int i=2; i<=n; i++)

    {

        dp[i]=dp[i-1] + abs(a[i]-a[i-1]);

        if(i>2)

            dp[i]=min(dp[i], dp[i-2] + abs(a[i]-a[i-2]));

    }

    cout<< dp[n] <<endl;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



typedef   long long  int ll;

typedef  long double ld;

typedef std::vector<ll> vi;

typedef std::vector<std::vector<ll> > vv;



#define MOD 1000000007

#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);

#define fo(i,a,b) for(i=a;i<b;i++)

#define mp make_pair

#define pb(x) push_back(x)

#define fi first

#define se second

#define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<" ";cout<<endl;

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

#define input(vec,a,b) for(ll i = a;i<b;i++) cin>>vec[i];

#define ms(a,val) memset(a,val,sizeof(a))

using namespace std;



const int N = 1e5 + 5;





void solve(){

            ll i,j,n,m;

            ll mincost[N];

            ms(mincost,0);

            cin>>n;

            ll a[n];

            input(a,0,n);

            mincost[1] = abs(a[0]-a[1]);//a[0];

            fo(i,2,n)

            {

				mincost[i] = min(mincost[i-1]+abs(a[i]-a[i-1]),mincost[i-2]+abs(a[i-2]-a[i]));

			}

             cout<<mincost[n-1]<<endl;

            

    

            

						            



















}



int main()

{

    IO;

      ll t=1;

      //cin>>t;





      while(t--)

      {



          solve();

      }

    return 0;

}


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

#define ll long long

using namespace std;



int dp[100005], a[100005];

int n;



int main()

{

    cin>>n;

    for(int i=1; i<=n; i++)

        cin>>a[i];



    dp[1]=0;

    for(int i=2; i<=n; i++)

    {

        dp[i]=dp[i-1] + abs(a[i]-a[i-1]);

        if(i>2)

            dp[i]=min(dp[i], dp[i-2] + abs(a[i]-a[i-2]));

    }

    cout<< dp[n] <<endl;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
/* In the name of Allah */



#include <bits/stdc++.h>

using namespace std;



#define ll long long

#define pii pair<int, int>

#define pll pair<long long, long long>

#define pb push_back

#define LL_INF 1LL << 62

#define INF 1 << 30

#define SetBit(x, k) (x |= (1LL << k))

#define ClearBit(x, k) (x &= ~(1LL << k))

#define CheckBit(x, k) (x & (1LL << k))

#define mod 1000000007



int n;

ll x[100005];

ll dp[100005];



ll solve(int pos){

  if(pos>=n-1) return 0;

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



  ll res = LL_INF;

  if(pos+1<n) res = min(res, abs(x[pos+1]-x[pos])+solve(pos+1));

  if(pos+2<n) res = min(res, abs(x[pos+2]-x[pos])+solve(pos+2));



  return dp[pos] = res;

}



int main()

{

  memset(dp, -1, sizeof dp);

  cin >> n;

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

    cin >> x[i];



  cout << solve(0) << "\n";



  return 0;

}

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

#define ll long long

using namespace std;



int dp[100005], a[100005];

int n;



int main()

{

    cin>>n;

    for(int i=1; i<=n; i++)

        cin>>a[i];



    dp[1]=0;

    for(int i=2; i<=n; i++)

    {

        dp[i]=dp[i-1] + abs(a[i]-a[i-1]);

        if(i>2)

            dp[i]=min(dp[i], dp[i-2] + abs(a[i]-a[i-2]));

    }

    cout<< dp[n] <<endl;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):


#include<bits/stdc++.h>

#define ll long long int

#define s(l) scanf("%lld",&l)

#define ss(lc) scanf("%s",lc)



#define ppp push_back

#define p(x) printf("%lld\n",x)

#define sr string

#define vr vector

/*int ff(int w)

{

    if(w==1){return 1;}

    else if(w==0){return 1;}

    else{return w*ff(w-1);}

}*/

/*int pr(int ww)

{

    int xs=ww/2;

    int sx=1;

    for(int i=2;i<=xs;i++)

    {

        if(ww%i==0){sx=0;break;}



    }

    return sx;

}*/

ll a[200005],b[200005];

using namespace std;

int main()

{

    vr<ll> mn;

    memset(a,0,sizeof(a));

    memset(b,0,sizeof(b));

  ll x=0,y,z=0,zz,i,j,k=0,l,m,n,o,p,q,r,ss;

  s(n);

vr<ll>dp(n,0);

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

{

    s(a[i]);

}

dp[1]=abs(a[1]-a[0]);

for(i=2;i<n;i++)

{

    dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);//cout<<dp[i]<<" "<<abs(a[i]-a[i-1])<<dp[i-1]<<abs(a[i]-a[i-2])<<dp[i-2]<<endl;

}

cout<<dp[n-1]<<endl;

}








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



#define  ll         long long

#define  llu        unsigned long long

#define  mod        1000000007

#define  pi         ((2.0)*acos(0.0))

#define  pb         push_back

#define  pf         push_front

#define  eb         emplace_back

#define  mp         make_pair

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

#define  X          first

#define  Y          second



/*loop*/

#define  fr(i,m,n)   for(ll i=m;i<n;++i)



/*output shortcuts*/

#define  nl         "\n"

#define  Yes        cout<<"Yes\n"

#define  yes        cout<<"yes\n"

#define  YES        cout<<"YES\n"

#define  No         cout<<"No\n"

#define  no         cout<<"no\n"

#define  NO         cout<<"NO\n"



ll a[10000000];



/*ll c(ll i,ll n)

{

    if(i>n)

        return 0;



    return abs(a[i]-a[i+1]);

}*/

using namespace std;

int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll n;

    cin>>n;



    ll a[n];

    fr(i,0,n)

    cin>>a[i];



    ll dp[n];

    dp[n-1]=0;



    for(ll i=n-2; i>=0; i--)

    {

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

       else

        dp[i] = dp[i+1] + abs(a[i] - a[i+1]);

    }



    cout<<dp[0]<<nl;



return 0;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
//                                      KiSmAt

#include "bits/stdc++.h"

using namespace std;

 

using ll = long long;

 

const ll inf = 1e18;

const int N = 2 * 1e5 + 10;



ll res;

ll a[N], dp[N];



ll go(ll idx, ll n){

	if(idx == n)	return 0;

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

	ll xx = inf, yy = inf;

	xx = go(idx + 1, n) + abs(a[idx + 1] - a[idx]);

	if(idx + 2 <= n)	yy = go(idx + 2, n) + abs(a[idx + 2] - a[idx]);

	return dp[idx] = min(xx, yy);

}



void solve(){

	ll n;

	cin >> n;

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

		cin >> a[i];

	}

	memset(dp, -1, sizeof dp);

	cout << go(1, n);

}

 

int main(int argc, char const *argv[]){

	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

    ll t = 1;

    //cin >> t;

    while(t--){

    	solve();

    }

}

// nEro

// Optimized solution to the same problem (faster):
//                                      KiSmAt

#include "bits/stdc++.h"

using namespace std;

 

using ll = long long;

 

const ll inf = 1e18;

const int N = 2 * 1e5 + 10;



ll res;

ll a[N], dp[N];



void solve(){

	ll n;

	cin >> n;

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

		cin >> a[i];

	}

	dp[2] = abs(a[2] - a[1]);

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

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

	}

	cout << dp[n];

}

 

int main(int argc, char const *argv[]){

	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

    ll t = 1;

    //cin >> t;

    while(t--){

    	solve();

    }

}

// nEro

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define ll long long 

ll n ;

vector<ll> arr(100001), dp(100001);

void solve(){

	dp[2]=abs(arr[1]-arr[2]);

	for(ll i=3 ; i<= n ; i++){

		ll f1=abs(arr[i]-arr[i-1])+dp[i-1];

		ll f2=abs(arr[i]-arr[i-2])+dp[i-2];

		dp[i]=min(f1,f2);

	}

	cout<<dp[n]<<endl;

}

int main(){

	cin>>n;

	for(ll i=1; i<=n; i++)cin>>arr[i];

	solve();

}

// Optimized solution to the same problem (faster):
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂

                   

                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            

 

 */ 

#include<bits/stdc++.h>

using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long 

#define mod 1000000007

#define inf 100000000000000

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define _it iterator

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

#define f first

#define s second

#define pb push_back

void mahakal(){

	#ifndef ONLINE_JUDGE

	freopen("input.txt","r",stdin);

	freopen("output.txt","w",stdout);

	freopen("error.txt","w",stderr);

	#endif

}

#define ar array

const ll maxN=1e5+5 , N=1e3+5;

ll n ,m ;

ll a[maxN];

ll dp[maxN];

void solve(){

	cin>> n ;

	for(ll i=0;i<n ;i++)cin>>a[i];

	dp[0]=0,dp[1]=abs(a[1]-a[0]);

	for(ll i=2;i<n ;i++){

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

	}

	// for(ll i=0;i<n;i++)cerr<<dp[i]<<" ";

	cout<<dp[n-1]<<endl;

}

int main(){

	//mahakal(),fast;

	ll t=1;

	// cin>> t ;

	while(t--)solve();



	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define REP(i,a) for(int i = 0; i < (a); i++)

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

typedef long long ll;

typedef pair<int, int> P;

const ll INF = 1e12;

const int MOD = 1e9 + 7;



int N;

ll h[100001];

ll dp[100001];



ll rec(int n){

    if(dp[n] != -1){

        return dp[n];

    }

    if(n == 0){

        return 0;

    }

    ll res = INF;

    res = min(res, rec(n - 1) + abs(h[n] - h[n - 1]));

    if(n > 1){

        res = min(res, rec(n - 2) + abs(h[n] - h[n - 2]));

    }

    return dp[n] = res;

}



signed main(){

    cin >> N;

    REP(i,N){

        cin >> h[i];

    }

    memset(dp, -1, sizeof(dp));

    cout << rec(N - 1) << endl;

}

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

using namespace std;

#define REP(i,a) for(int i = 0; i < (a); i++)

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

typedef long long ll;

typedef pair<int, int> P;

const int INF = 1e9;

const int MOD = 1e9 + 7;



#define MAX_N 100000



int dp[MAX_N];



signed main(){

	int n;

	cin >> n;

	int h[n];

	REP(i,n){

		cin >> h[i];

	}

	dp[0] = 0;

	dp[1] = abs(h[0] - h[1]);

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

		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));

	}

	cout << dp[n - 1] << endl;

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

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

using namespace std;

using ll = long long;

using P = pair<int, int>;

#include <algorithm>

template<class T> inline bool chmax(T& a, T b) { if (a<b) { a = b; return 1; } return 0;}

template<class T> inline bool chmin(T& a, T b) { if (a>b) { a = b; return 1; } return 0;}



const ll INF = 1LL <<  60;



ll h[100010];



ll dp[100010];



int main()

{

        int n;

        cin >> n;

        vector<int> a[n];

        rep(i,n) cin >> h[i];

        rep(i,100010) dp[i] = INF;



        dp[0] = 0;



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

                chmin(dp[i], dp[i-1] + abs(h[i] - h[i -1]));

                if (i > 1)

                        chmin(dp[i], dp[i-2] + abs(h[i] - h[i -2]));

        }



        cout << dp[n-1] << endl;;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <string>

#include <algorithm>

#include <cmath>

#include <deque>

#include <queue>

#include <stack>

#include <vector>

#include <utility>

#include <iomanip>

#include <bitset>

#include <set>

#include <map>

#include <stdio.h>

#include <numeric>

#include <cstring>



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

#define rep1(i,n) for (int i = 1; i < (n); i++)

#define FOR(i,a,b) for (int i=(a); i < (b); i++)

#define MOD 1000000007 //10^9+7

using namespace std;

using ll = long long;

using PII = pair<int, int>;

const int INF = numeric_limits<int>::max();



// 負の数にも対応した % 演算

long long mod(long long val, long long m) {

    long long res = val % m;

    if (res < 0) res += m;

    return res;

}



//greatest common divisor

long long gcd(ll a, ll b) 

{

    if (a % b == 0) {

        return b;

    } else {

        return gcd(b, a % b);

    }

}



//least common multiple

long long lcm(ll a, ll b)

{

    return a / gcd(a, b) * b ;

}



int main()

{

    int n; cin >> n;

    vector<int> h(n);

    rep(i,n) cin >> h[i];

    int dp[n];



    dp[0] = 0;

    dp[1] = abs(h[1] - h[0]);



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

        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1])

                  , dp[i-2] + abs(h[i]-h[i-2]));

    }



    cout << dp[n-1] << endl;

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
////////////////////////////////////

//          ,.                    //

//         (_|,.                  //

//        ,' /, )_______   _      //

//     __j o``-'        `.'-)'    //

//    (")                 \'      //

//     `-j                |       //

//        `-._(           /       //

//           |_\  |--^.  /        //

//          /_]'|_| /_)_/         //

//             /_]'  /_]'         //

//                                //

//           PIGMEISTER™          //

//                                //

////////////////////////////////////



#include <bits/stdc++.h>

using namespace std;



#define ll long long

#define ull unsigned long long

#define mod (ll)1000000007

#define sidha(i, x, n) for(ll i=(ll)(x);i<(ll)(n);i++)

#define ulta(i, x, n) for(ll i=(ll)(x);i>=(ll)(n);i--)

#define mii map<ll, ll>

#define vi vector<ll>

#define pii pair<ll, ll>

#define pb push_back

#define mp make_pair

#define modInv(x) powah(x, mod-2)

#define test ll t;cin>>t;while(t--)

#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define endl '\n'

//ll powah(ll, ll);



vi dp(100005, -1), h;



ll minCost(ll n) {

    if (dp[n] > -1) return dp[n];



    if (n == 1)

        dp[n] = 0;

    else if (n == 2)

        dp[n] = abs(h[2] - h[1]);

    else 

        dp[n] = min(minCost(n-1) + abs(h[n]-h[n-1]), minCost(n-2) + abs(h[n]-h[n-2]));

    return dp[n];

}



int main()

{

    jaldi;

    

    ll n;

    cin >> n;

    h.resize(n+1);

    sidha (i, 0, n)

        cin >> h[i+1];

    cout << minCost(n) << endl;

    

    return 0;

}



// ll powah(ll x, ll y) { 

//     ll res = 1;

//     x = x % mod;

//     while (y > 0) { 

//         if (y & 1) 

//             res = (res*x) % mod; 

//         y = y>>1;

//         x = (x*x) % mod; 

//     } 

//     return res; 

// }

// Optimized solution to the same problem (faster):
//   PIGMEISTER™   //



#include <bits/stdc++.h>

using namespace std;



#define ll long long

#define ld long double

#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)

#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)

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

#define bas(a) a.rbegin(),a.rend()

#define test ll _;cin>>_;while(_--)

#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define MOD (ll)1000000007

//#define MOD (ll)998244353

#define PI (ld)3.141592653589793238

#define MAX 100005



int main()

{

    jaldi;

    

    ll n;

    cin >> n;

    ll h[n];

    sidha (i, 0, n) cin >> h[i];



    ll dp[n] = {0};

    dp[1] = abs(h[1]-h[0]);

    sidha (i, 2, n) {

        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));

    }



    cout << dp[n-1] << '\n';

    

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



const long long INF = 1LL << 60;



long long h[100010];



long long dp[100010];



int main() {

  int n; cin>>n;

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

    cin>>h[i];

  }

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

    dp[i]=INF;

  }

  

  dp[0]=0;

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

    chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));

    if(i>1) chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));

  }

  cout<<dp[n-1]<<endl;

}


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

#define rep(i,n)for(long long i=0;i<(n);i++)

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int,int> P;

 

const int MOD=1000000007;

const int INF=0x3f3f3f3f;

const ll INFL=0x3f3f3f3f3f3f3f3f;

ll gcd(ll x, ll y){

  if(y==0) return x;

  else return gcd(y, x%y);

}

ll lcm(ll x,ll y){

  ll g=gcd(x,y);

  return x/g*y;

}



using Graph=vector<vector<int>>;

Graph G;



int main(){

  //input

  int n;

  cin >> n;

  vector<int>h(n);

  rep(i,n) cin >> h[i];

  

  int dp[n+10]={};

  dp[0]=0;

  dp[1]=abs(h[1]-h[0]);

  rep(i,n){

    if(i>=2)dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));

  }

  cout << dp[n-1] << endl;

  

  

}

    


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

const int INF = numeric_limits<int>::max();

int n;

int dp[100005];

int arr[100005];

int f(int curr){

	int&ret = dp[curr];

	if(~ret) return ret;

	if(curr>n) return ret = INF;

	if(curr==n) return ret = 0;

	ret = abs(arr[curr+1]-arr[curr])+f(curr+1);

	if(curr<n-1) ret = min(ret,abs(arr[curr]-arr[curr+2])+f(curr+2));

	return ret;

}

int main(){

	memset(dp,-1,sizeof(dp));

	cin>>n;

	for(int i=1; i<=n; i++) cin>>arr[i];

	cout<<f(1);

}

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

using namespace std;

const int INF = numeric_limits<int>::max();

int n;

int arr[100005];

int main(){

	cin>>n;

	vector<int>dp(n+5,INF);

	for(int i=1; i<=n; i++) cin>>arr[i];

	dp[1] = 0;

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

		dp[i+1] = min(dp[i+1],abs(arr[i]-arr[i+1])+dp[i]);

		dp[i+2] = min(dp[i+2],abs(arr[i]-arr[i+2])+dp[i]);

	}

	cout<<dp[n];

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <string>

#include <algorithm>

#include <cmath>

#include <stack>

#include <queue>

#include <map>

#include <numeric>

#include <type_traits>

#include <limits>

#include <random>

#include <iomanip>



using namespace std;



using ll = long long;



typedef pair<int, int> P;



#define rep(i,N) for(long long i = 0;i < (long long)N; ++i)



static int mod = 1000000007;

static int large = 1000000000;



int dx[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };

int dy[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };





int N;

int h[100000];



int note[1000000];



int f(int x) {

	if (note[x] != -1) return note[x];

	if (x == 1) {

		return 0;

	}

	if (x == 2) {

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

	}

	return note[x] = min(f(x - 1) + abs(h[x - 1]- h[x - 2]), f(x - 2) + abs(h[x - 1] - h[x - 3]));

}



int main() {

	cin >> N;

	rep(i, N) {

		cin >> h[i];

	}

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

		note[i] = -1;

	}

	cout << f(N) << endl;

	return 0;

}




// Optimized solution to the same problem (faster):
#include <iostream>

#include <algorithm>

#include <string>

#include <queue>

#include <cmath>

#include <map>

#include <iomanip>

#include <unordered_map>

#include <stack>



using namespace std;

typedef long long  ll;



const ll mod = 1000000007;





int main()

{

	ll N;

	cin >> N;

	vector<ll> h(N);

	for (ll i = 0; i < N; i++)

	{

		cin >> h[i];

	}

	ll dp[100000];

	dp[0] = 0;

	dp[1] = abs(h[0] - h[1]);

	for (ll i = 2; i < N; i++)

	{

		dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));

	}

	cout << dp[N - 1] << endl;

	return 0;



}

// Fastest known solution for this problem: