stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



#define F first

#define S second



int N;

int H[100005];

int dp[100005][5];



int solve(int cost, int ind, int j) {

	if (ind > N) return INT32_MAX;

	if (ind == N) return cost;



	if (~dp[ind][j]) return dp[ind][j];

	

	dp[ind][j] = cost;

	dp[ind][j] += min(solve(abs(H[ind] - H[ind + 1]), ind + 1, 0), 

					solve(abs(H[ind] - H[ind + 2]), ind + 2, 1));

	return dp[ind][j];

}



int main() {

	cin >> N; 

	H[0] = INT32_MAX; // to avoid RTE

	for (int i = 1; i <= N; i++) cin >> H[i];

	int ans = 0;

	

	memset(dp, -1, sizeof dp);

	cout << solve(0, 1, 0) << endl;



	return 0;

}

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

using namespace std;

#define ll long long

#define ull unsigned long long

#define PII pair<int,int>

#define PSI pair<string,int>

#define PIII pair< int, pair<int,int> >

const int MXN = 1e5;

int a[MXN+5], dp[MXN+5];

int N,K;



int rec(int pos){



    if(pos==N) return 0;

    if(pos>=N) return 1<<30;

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

    return dp[pos] = min( rec(pos+1) + abs(a[pos+1]-a[pos]) , rec(pos+2) + abs(a[pos+2]-a[pos]) );

}



void solve(){



    cin>>N;

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

    for(int i=1; i<=N; i++) cin>>a[i];

    cout<< rec(1) << "\n";

}



int main(){



    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    solve();

}


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

using namespace std;



int n;

int h[100005];

int dp[100005];



int solve(int x){

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

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

    else if (x == n-2){

        return dp[x] = abs(h[x+1]-h[x]);

    }

    else {

        return dp[x] = min(abs(h[x+1]-h[x])+solve(x+1),abs(h[x+2]-h[x])+solve(x+2));

    }

}



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

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cin >> n;

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

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

        cin >> h[i];

    }

    cout << solve(0) << endl;

    return 0;

}

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

#define file freopen( "input.txt" , "r" , stdin) ; freopen( "output.txt" , "w" , stdout) ;

#define Gamed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define _3102_ main()

#define endl '\n'

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

using namespace std;

const int N = 1e5 + 100;

const ll MX = 1e9;

const ll mod = 1e9 + 7;

const double eps = 1e-9 ;



ll n, h[N], dp[N] ;

ll solve( int i ){

	if ( i < 0 ) return 0 ;

	ll &ret = dp[i] ;

	if ( ~ret ) return ret ;

	if ( i == 0 ) return ret = 0 ;

	if ( i == 1 ) return ret = abs( h[1] - h[0]) ; 

	return ret = min ( solve(i - 1 ) + abs(h[i] - h[i-1]) , solve ( i - 2 ) + abs ( h[i] - h[i-2])) ;

}



int _3102_{

	Gamed

	cin >> n ;

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

		cin >> h[i] ;

	}

	memset ( dp , -1 , sizeof dp ) ;

	cout << solve ( n - 1 ) ;



	return 0;

}


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

#define snd second

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

#define pb push_back

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

#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define SZ(s) int(s.size())

#define DBG(x) cerr <<#x << " = " << (x) << "\n"



#define SQR(x) ((x) * (x))



#define PI 3.1415926535897932385

#define INF 1000111222

#define eps 1e-7

#define maxN 11



using namespace std;



typedef long long ll;

typedef vector<ll> vll;

typedef pair<ll,ll> pll;

typedef pair<int,int> pii;

typedef vector<string> vstr;

typedef vector<vll> vvll;

typedef vector<bool> vbool;

typedef vector<pll> vpll;

typedef vector<vpll> vvpll;

typedef vector<vbool> vvbool;



vll ns,dp;

ll n;



ll solve(ll pos){

	ll & d = dp[pos];

	if(d != -1) return d;

	ll v=INF;

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

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

	if(pos == (n-1)) v = 0;

	return d = v;

}



int main(){FIN

	

	cin >> n;

	ns.resize(n);

	dp.assign(100010,-1);

	fore(i,0,n)cin >> ns[i];

	

	solve(0);

	

	cout << dp[0] << "\n";



	return 0;

}


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

using namespace std;



#define fi first

#define se second

#define pb push_back

#define dbg(x) cout << #x << " = " << x << endl

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



typedef long long ll;

typedef long double ld;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<pii> vii;



const int MAX = 1e5;

const int INF = 1e9;

vi stone(MAX + 5);

vi dp(MAX + 5, -1);

int n;



int sol(int i){

    if(i >= n) return INF;

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

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

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

    if(i + 2 < n){

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

    }

    return dp[i];

}



int main(){

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    #ifdef LOCAL

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

    #else

        #define endl '\n'

    #endif

    cin >> n;

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

        cin >> stone[i];

    cout << sol(0) << endl;

    return 0;

}

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

using namespace std;

//-------------------------------------------MACROS---------------------------------------------

#define 	TIEMPO_CORRIDA		cerr << "tiempo: "<<1.0*clock()/CLOCKS_PER_SEC <<" seg.\n";

#define 	FILES				freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);

#define 	FORIT(it,e)			for(it = e.begin() ; it != e.end() ; it++)

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

#define 	RFOR(i,a,b)			for(i = a ; i >= b ;i--)

#define 	FORSW(i,a,b,sw)		for(i = a ; i < b && sw ; i++)

#define 	RFORSW(i,a,b,sw)	for(i = a ; i >= b && sw ; i--)

#define 	fast 				ios::sync_with_stdio(false),cin.tie(),cout.tie();

#define 	to_int(x) 			atoi(x.data())

#define 	to_long(x) 			atoll(x.data())

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

#define 	RALL(x) 			x.rbegin(),x.rend()

typedef 	long long 			ll;

typedef 	pair<int,int> 		pi;

typedef 	pair<ll,ll> 		pl;

const		int 				modN = 1e9+7;

const		double 				PI = 3.1415926535897932384626433832795028841;

//---------------------------------------------------------------------------------------------

const int tam = 6e5;

const int oo=1e9;

int ar[tam],memo[tam];

int n;



int f(int x){

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

	if(x == n-1) return memo[x]=0;

	int a=oo , b=oo;

	if(x+1 <n) a = f(x+1) + abs(ar[x+1]-ar[x]); 

	if(x+2 <n) b = f(x+2) + abs(ar[x+2]-ar[x]);

	return memo[x]=min(a,b);

}



int main(){

	int i;

	while(scanf("%d",&n)==1){

		memset(memo,-1,sizeof memo);

		FOR(i,0,n) scanf("%d",&ar[i]);

		printf("%d\n",f(0));

	}

	return 0;

}

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

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

const int maxn=100000+10;

int n,h[maxn],dp[maxn];

int main()

{

	cin>>n;

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

	memset(dp,0x3f3f3f3f,sizeof(dp));

	dp[1]=0;

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

	{

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

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

	}

	cout<<dp[n]<<endl;

	return 0;

}

//Phoenix-ZH

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





using namespace std;

int n;

vector<int> vec;



int meme[100007];



int solve(int index){



    if(index==n-1){

        return 0;

    }

    if(meme[index]!=-1){

        return meme[index];

    }

    

    int ret1 = 100000000;

    int ret2 = 100000000;

    if(index+1<n){

         ret1 = abs (vec[index]- vec[index+1]) + solve(index+1); 

    }

    if(index+2<n){

         ret2 = abs (vec[index]- vec[index+2]) + solve(index+2); 

    }





    return meme[index] = min(ret1,ret2);

}



int main(){

    cin>>n;

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

    int num;

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

        cin>>num;

        vec.push_back(num);

    }

    cout<<solve(0)<<endl;

    return 0;

}

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

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



}


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

}