stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.3691754187857845x):
#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;

}
// Slower C++ solution:
#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();

    }

}


// Faster C++ solution for the same problem (measured speedup: 1.3983831725204359x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.7974747476996134x):
#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;

}
// Slower C++ solution:
/* 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;

}

// Faster C++ solution for the same problem (measured speedup: 1.7817056760528158x):
#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;

}
// Slower C++ solution:


#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;

}








// Faster C++ solution for the same problem (measured speedup: 4.168608809027517x):
#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;

}
// Slower C++ solution:
//                                      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

// Faster C++ solution for the same problem (measured speedup: 2.5885758311965317x):
//                                      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
// Slower C++ solution:
#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();

}

// Faster C++ solution for the same problem (measured speedup: 2.625119657682016x):
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂

                   

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

 

 */ 

#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;

}
// Slower C++ solution:
#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();

}

// Faster C++ solution for the same problem (measured speedup: 2.571297486900781x):
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂

                   

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

 

 */ 

#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 MOD 998244353

#define inf 100000000000000000

#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

#define ar array

#define ld long double

void mahakal(){

	#ifndef ONLINE_JUDGE

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

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

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

	#endif

}

ll dx[4]={1,0,-1,0};

ll dy[4]={0,1,0,-1};

char c[4]={'D' , 'R' , 'U' , 'L'};

const ll maxN=2e5+5;

ll n  , a[maxN] , dp[maxN];

void solve(){

	cin>> n ;

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

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

		dp[i]=inf;

		for(ll j=1;j<=2; j++){

			if(i-j>=0)

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

		}

	}	

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

}

int main(){

	//mahakal();

	fast;

	ll t =1 ;

	//cin>> t ; 

	while(t--)solve();

	//cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 

	return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.8048922910690872x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.8016260859685223x):
#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 long long LINF = 1e18;

const long long MOD = 1e9 + 7;



#define MAX_N 100000



signed main(){

	int n;

	cin >> n;

	int h[n + 2];

	REP(i,n){

		cin >> h[i];

	}

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

	dp[0] = 0;

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

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

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

	}

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

	return 0;

}
// Slower C++ solution:
#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;;

}


// Faster C++ solution for the same problem (measured speedup: 1.8017155023950988x):
#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;

}