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

#pragma GCC optimize "03"

using namespace std;



#define int long long int

#define pb push_back

#define pii pair<int,int>

#define fi first

#define se second

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

#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }

#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }

#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

#ifndef LOCAL

#define endl '\n'

#endif

const int inf = INT_MAX;

const double eps = 0.0000001;

const double PI = acos(-1.0);

const int MOD = 1e9+7;

const int N  = 1e5+5;



int a[N], dp[N], n;



int solve (int i) {

	if (i > n) return inf;

	if (i == n) return 0;

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

	if (dp[i] >= 0) return dp[i];

	int ans = inf;

	for (auto j: {i+1, i+2}) {

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

	}

	dp[i] = ans;

	return ans;

}



signed main(){

    #ifdef LOCAL

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

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

    #endif  

    IOS;



    cin >> n;

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

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

    	cin >> a[i];

    cout << solve(1);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.7925603825306962x):
#include "bits/stdc++.h"

#pragma GCC optimize "03"

using namespace std;



#define int long long int

#define pb push_back

#define pii pair<int,int>

#define fi first

#define se second

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

#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }

#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }

#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

#ifndef LOCAL

#define endl '\n'

#endif



const int inf = INT_MAX;

const int MOD = 1e9 + 7;

const int N = 1e5 + 5;



int a[N], dp[N];



signed main(){

    IOS;

    int n;

    cin >> n;

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

        cin >> a[i];

    dp[1] = 0;

    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]-a[i-2]));

    cout << dp[n] << endl;

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define INF 0x3f3f3f3f

int n, k, v[100005], tab[100005];

int knap(int obj){

    if(tab[obj]!=INF){

        return tab[obj];

    }

    if(obj==n){

        return tab[obj]=0;

    }

    if(obj>n){

        return tab[obj]=INF;

    }

    return tab[obj]=min(abs(v[obj]-v[obj+1])+knap(obj+1), abs(v[obj]-v[obj+2])+knap(obj+2));

}

int main()

{

    memset(tab, INF, sizeof(tab));

    cin >> n;

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

        cin >> v[i];

    }

    cout << knap(1) << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3958519753983205x):
#include <bits/stdc++.h>

using namespace std;

#define INF 0x3f3f3f3f

int n, val[100005], dp[100005];

int main()

{

    cin >> n;

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

        cin >> val[i];

    }

    dp[1]=0;

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

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

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

    }

    cout << dp[n] << endl;

    return 0;

}
// Slower C++ solution:


/**

 *    Coded by : lucky_21

 *               --------Lokesh Singh

**/



#include<bits/stdc++.h>

using namespace std;



#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



#define     F           first

#define     S           second

#define     pb          push_back

#define     lb          lower_bound

#define     ub          upper_bound

#define     pii         pair<int,int>

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

#define     fix         fixed<<setprecision(10)

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

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

#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)



typedef double db;

typedef long long ll;



const int N=1e5+5;

const int mod=1e9+7;



int n,h[N],dp[N][2];

int rec(int i,int last){

    if(i>n) return 1e9;

    if(i==n) return abs(h[i]-(last?h[i-2]:h[i-1]));

    int &cache=dp[i][last];

    if(cache!=-1) return cache;

    return cache=abs(h[i]-(last?h[i-2]:h[i-1]))+min(rec(i+1,0),rec(i+2,1));

}

signed main(){

    FastIO;

    cin>>n;

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

    memset(dp,-1,sizeof dp);

    h[0]=h[1];

    cout<<rec(1,0);

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.7931287960008364x):


/**

 *    Coded by : lucky_21

 *               --------Lokesh Singh

**/



#include<bits/stdc++.h>

using namespace std;



#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



#define     F           first

#define     S           second

#define     pb          push_back

#define     lb          lower_bound

#define     ub          upper_bound

#define     pii         pair<int,int>

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

#define     fix         fixed<<setprecision(10)

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

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

#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)



typedef double db;

typedef long long ll;



const int N=1e5+5;

const int mod=1e9+7;



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

signed main(){

    FastIO;

    cin>>n;

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

    rep(i,2,n){

        dp[i]=2e9;

        rep(j,1,2){

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

        }

    }

    cout<<dp[n];

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#include<stdio.h>

 

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

#define rep(i,n) FOR(i,0,n)

#define f first

#define s second

#define pb push_back

#define mp make_pair

#define INF 1000000000000000

#define MAXN (int)(1e6)+1

#define MOD 1000000007

 

using namespace std;

 

typedef long long int lli;

typedef pair<int,int> pii;

typedef pair<lli,int> pwi;

typedef pair<lli,lli> plli;

typedef vector<int> vi;

typedef vector<lli> vlli;

typedef vector< vector<pair<int,lli > > > wGraph;

typedef vector<vector<int> > graph;

//typedef vector<vector<int> > matrix;



int n;

int dp[MAXN];

vi ar;



int knap(int ind){

    

    if(ind>=n){

        return 0;

    }

    

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

    

    int takeIt = INT_MAX,leaveIt = INT_MAX;

    if(ind+2 < n){

        takeIt = abs(ar[ind]-ar[ind+2]);

    }

    if(ind+1<n)

        leaveIt = abs(ar[ind]-ar[ind+1]);

    

    if(ind+1>=n) return dp[ind] = 0;

    else{

        return dp[ind] = min(takeIt+knap(ind+2),leaveIt+knap(ind+1));

    }

    

}





int main(){

 

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    cout<<std::fixed;

    cout<<std::setprecision(4);

    

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

        dp[i] = -1;

    }

    

    cin>>n;

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

        int v;

        cin>>v;

        ar.pb(v);

    }   

    

    cout<<knap(0)<<endl;

    

    return 0;

 

}

// Faster C++ solution for the same problem (measured speedup: 5.032521909055276x):
#include<bits/stdc++.h>

#include<stdio.h>

 

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

#define rep(i,n) FOR(i,0,n)

#define f first

#define s second

#define pb push_back

#define mp make_pair

#define INF 1000000000000000

#define MAXN (int)(1e6)+1

#define MOD 1000000007

 

using namespace std;

 

typedef long long int lli;

typedef pair<int,int> pii;

typedef pair<lli,int> pwi;

typedef pair<lli,lli> plli;

typedef vector<int> vi;

typedef vector<lli> vlli;

typedef vector< vector<pair<int,lli > > > wGraph;

typedef vector<vector<int> > graph;

//typedef vector<vector<int> > matrix;



int main(){

 

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    cout<<std::fixed;

    cout<<std::setprecision(4);

    

    int n;

    cin>>n;

    

    vi ar;

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

        int v;

        cin>>v;

        ar.pb(v);

    }   

    

    int dp[n+1];

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

        

        if(i == 0){

            dp[i] = 0;

        }else if(i == 1){

            dp[i] = abs(ar[i]-ar[i-1]);    

        }else{

            

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

                        dp[i-2]+abs(ar[i]-ar[i-2]));    

            

        }

        

    }

    

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

       

    return 0;

 

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

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

#define ld long double

#define ll long long

#define pb push_back

#define pi acos(-1)

#define eps 1e-7

#define F first

#define S second

#define X real()

#define Y imag()

#define cross(a,b) (conj(a)*(b)).X

#define dot(a,b) (conj(a)*(b)).Y

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

#define allr(f) (f).rbegin(),(f).rend()

const int mod = 1e9+7 , A = 1e5 ;

typedef complex <ld> point ;

typedef vector <point> polygon ;

typedef tuple <int , int , int> line ;

//====================================

ll n , ans[100005] , h[100005] ;

ll solve(ll ind)

{

	if (ind >= n)

		return 1e10 ;

	if (ind == n-1)

		return 0 ;

	if (ans[ind] != -1)

		return ans[ind] ;

	ll val = 1e10 ;

	val = min(val , abs(h[ind] - h[ind+1]) + solve(ind+1)) ;

	val = min(val , abs(h[ind] - h[ind+2]) + solve(ind+2)) ;

	ans[ind] = val ;

	return val ;

}

int main()

{

	_K

	cin >> n ;

	memset(ans , -1 , sizeof ans) ;

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

	cout << solve(0) ;

	return 0 ;

}

// Faster C++ solution for the same problem (measured speedup: 1.793811976667492x):
#include <bits/stdc++.h>

using namespace std;

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

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

#define BiEdge(v,a,b) (v)[(a)].pb((b)),(v)[(b)].pb((a))

#define ll long long

#define ld long double

#define pb push_back

#define Pb pop_back

#define F first

#define S second

#define X real()

#define Y imag()

#define pi acos(-1)

#define eps 1e-7

#define bpc __builtin_popcount

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

#define allr(f) (f).rbegin(),(f).rend()

#define cross(a,b) (conj(a)*(b)).real()

#define dot(a,b) (conj(a)*(b)).imag()

typedef complex <ld> point ;

typedef vector <point> polygon ;

typedef tuple <ll,ll,ll> line ;

const int mod = 1e9+7 , A = 1e9+1 ;



int main()

{

	ios

	ll n ; cin >> n ;

	ll a[n] , dp[n] ;

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

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

	for (int 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])) ;

	cout << dp[n-1] ;

	return 0 ;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int h[100500],n,mem[100500];

#define INF 1000000000

int dp(int i){

    if(i==1) return 0;

    if(i<1) return INF;

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

    int a1= dp(i-1)+abs(h[i-1]-h[i]);

    int a2 =dp(i-2)+abs(h[i-2]-h[i]);

    return  mem[i]=min(a1,a2);

}

int main(){

    int n;

    cin >> n;

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

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

        cin >> h[i];

    }

    cout << dp(n) << '\n';

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.371868185179057x):
// "header" {{{

#include <iostream>

#include <vector>

#include <algorithm>

#include <string>

#include <deque>

#include <list>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <cstring>

#include <iomanip>

#include <tuple>



using namespace std;

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

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

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

#define pii pair<int,int> 

#define int long long

#define setout(n,x) setw(n) << setfill(x)

#define Fixed fixed << setprecision(10)

const int INF = 0x3f3f3f3f;

const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

const long long mod = 1e9+7;



int gcd(int a,int b){ return b ? gcd(b,a % b) : a; }

int lcm(int a,int b){ return a / gcd(a,b) * b; }



inline double sqrt( const double &x) 

{

	double         xHalf = 0.5 * x;

	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);

	double         xRes  = * (double*)&tmp;



	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );

	return xRes * x;

}

// }}}



signed main(){

	cin.tie(0);

	ios::sync_with_stdio(false);

	int n;

	cin >> n;

	vector<int> h(n),dp(n);

	rep(i,n){

		cin >> h[i];

	}

	reps(i,n-1){

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

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

	}

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

	return 0;	

}
// Slower C++ solution:
#include <iostream>

#include <cmath>

#include <cstring>



using namespace std;



const long int INF=1L<<60;

int N;

long int h[100001];

long int memo[100001];



void swap(long int* a, long int* b) {

    long int tmp;

    tmp = *a;

    *a = *b;

    *b = tmp;

}



void swmin(long int* origin, long int comp) {

    if(*origin > comp) {

        swap(origin, &comp);

    }

}



long int rec(int i) {

    if(i==0) return 0;

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

    

    long int res=INF;

    swmin(&res, rec(i-1)+abs(h[i]-h[i-1]));

    if(i>1) swmin(&res, rec(i-2)+abs(h[i]-h[i-2]));

    memo[i] = res;

    return res;

}



int main() {

    cin >> N;

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

        cin >> h[i];

    }



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

    

    long int ans;

    ans = rec(N-1);

    cout << ans << endl;



    return 0;

    

}

// Faster C++ solution for the same problem (measured speedup: 1.8039197859094807x):
#include <iostream>

#include <cmath>

#include <algorithm>



using namespace std;



int N;

long int dp[100001]={};



int main() {

    cin >> N;

    

    int h[N];

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

        cin >> h[i];

    }

    

    dp[0] = 0;

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

    

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

        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-1] << endl;



    return 0;

    

}
// Slower C++ solution:
#include <iostream>

#include <cmath>

#include <cstring>



using namespace std;



const long int INF=1L<<60;

int N;

long int h[100001];

long int memo[100001];



void swap(long int* a, long int* b) {

    long int tmp;

    tmp = *a;

    *a = *b;

    *b = tmp;

}



void swmin(long int* origin, long int comp) {

    if(*origin > comp) {

        swap(origin, &comp);

    }

}



long int rec(int i) {

    if(i==0) return 0;

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

    

    long int res=INF;

    swmin(&res, rec(i-1)+abs(h[i]-h[i-1]));

    if(i>1) swmin(&res, rec(i-2)+abs(h[i]-h[i-2]));

    memo[i] = res;

    return res;

}



int main() {

    cin >> N;

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

        cin >> h[i];

    }



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

    

    long int ans;

    ans = rec(N-1);

    cout << ans << endl;



    return 0;

    

}

// Faster C++ solution for the same problem (measured speedup: 1.803975117062519x):
#include <iostream>

#include <cmath>

#include <algorithm>



using namespace std;



int main() {

    int N;

    cin >> N;

    

    int h[N];

    long int dp[N];

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

        cin >> h[i];

        dp[i]=0;

    }

    

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

    

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

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

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

    }

    

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



    return 0;

    

}
// Slower C++ solution:
#include <iostream>

#include <cmath>

#include <cstring>



using namespace std;



const long int INF=1L<<60;

int N;

long int h[100001];

long int memo[100001];



void swap(long int* a, long int* b) {

    long int tmp;

    tmp = *a;

    *a = *b;

    *b = tmp;

}



void swmin(long int* origin, long int comp) {

    if(*origin > comp) {

        swap(origin, &comp);

    }

}



long int rec(int i) {

    if(i==0) return 0;

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

    

    long int res=INF;

    swmin(&res, rec(i-1)+abs(h[i]-h[i-1]));

    if(i>1) swmin(&res, rec(i-2)+abs(h[i]-h[i-2]));

    memo[i] = res;

    return res;

}



int main() {

    cin >> N;

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

        cin >> h[i];

    }



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

    

    long int ans;

    ans = rec(N-1);

    cout << ans << endl;



    return 0;

    

}

// Faster C++ solution for the same problem (measured speedup: 1.7995687445976323x):
#include <iostream>

#include <cmath>

#include <algorithm>



using namespace std;



int main() {

    int N;

    cin >> N;

    

    long long int h[N], dp[N];

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

        cin >> h[i];

        if(i==0) {

            dp[i]=0;

        } else if(i==1) {

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

        } else {

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

        }

    }

    

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



    return 0;

    

}
// Slower C++ solution:
/************

* 	@Just Another Source code by: ankit.sangwan1999

*	@created on: 23 Apr 2020

*/



#include<bits/stdc++.h>

using namespace std;

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

#define ll long long



int DP[100005];



int fun(vector<int>&H, int ind){

	if(DP[ind] != -1){

		return DP[ind];

	}

	if(ind==0){

		return 0;

	}

	int pos1=INT_MAX, pos2 = INT_MAX;

	if(ind-1>=0){

		int val1 = abs(H[ind] - H[ind-1]);

		pos1 = val1 + fun(H,ind-1);

	}

	if(ind-2>=0){

		int val2 = abs(H[ind] - H[ind-2]);

		pos2 = val2 + fun(H,ind-2);

	}



	return DP[ind] = min(pos1, pos2);

}





signed main(){

    fastio;

    int t=1;

    // cin>>t;

    while(--t>=0){

    	int n;

    	cin>>n;

    	vector<int>H(n);

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

    	for(int i=0;i<n;i++) cin>>H[i];

    	cout<<fun(H,n-1);





    }





    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3913677669120832x):
/************

* 	@Just Another Source code by: ankit.sangwan1999

*	@created on: 23 Apr 2020

*/



#include<bits/stdc++.h>

using namespace std;

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

#define ll long long



int DP[100005];

int fun(vector<int>&H, int ind){

	if(DP[ind] != -1){

		return DP[ind];

	}

	if(ind==0){

		return 0;

	}

	int pos1=INT_MAX, pos2 = INT_MAX;

	if(ind-1>=0){

		int val1 = abs(H[ind] - H[ind-1]);

		pos1 = val1 + fun(H,ind-1);

	}

	if(ind-2>=0){

		int val2 = abs(H[ind] - H[ind-2]);

		pos2 = val2 + fun(H,ind-2);

	}



	return DP[ind] = min(pos1, pos2);

}



/* MEMO



signed main(){

    fastio;

    int t=1;

    // cin>>t;

    while(--t>=0){

    	int n;

    	cin>>n;

    	vector<int>H(n);

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

    	for(int i=0;i<n;i++) cin>>H[i];

    	cout<<fun(H,n-1);

    }



    return 0;

}



*/



/* BOTTOM-UP */



signed main(){

    fastio;

    int t=1;

    // cin>>t;

    while(--t>=0){

    	int n;

    	cin>>n;

    	vector<int>H(n);

    	int dp[n];



    	for(int i=0;i<n;i++) cin>>H[i];

    		

    	dp[0] = 0;

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



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

    		int val1 = INT_MAX;

    		int val2 = INT_MAX;

    		if(i-1>=0){

    			val1 = abs(H[i] - H[i-1]);

    		}

    		if(i-2>=0){

    			val2 = abs(H[i] - H[i-2]);

    		}

    		dp[i] = min(dp[i-1] + val1, dp[i-2] + val2);

    	}

    	cout<<dp[n-1];

    }



    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n;

vector <int> v(100005);

int dp[100005];

int solve(int i){

    if(i==n){

        return 0;

    }

    if(i>n){

        return 2e9;

    }

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

        return dp[i];

    }

    int q = min(abs(v[i]-v[i+1])+solve(i+1), abs(v[i]-v[i+2])+solve(i+2));

    dp[i]=q;

    return q;

}

void initialize(){

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

        dp[i]=-1;

    }

}

int main(){

    initialize();

    cin>>n;

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

        cin>>v[i];

    }

    cout<<solve(1)<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.795741832384668x):
#include<bits/stdc++.h>

using namespace std;

int main(){

	int n;

  	cin>>n;

  	vector <int> v(n);

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

    	cin>>v[i];

	}

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

	dp[0]=0;

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

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

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

	}

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

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;



#define FRO freopen("in.txt","r",stdin);



ll arr[100005],n;

vector<ll >dp(100005,0);



int main()

{

      ll i,j;

      cin>>n;

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

            cin>>arr[i];

      arr[0]=0;

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

      {



            if(i>2)

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

            else

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

      }

      cout<<dp[n]<<endl;



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.2817771194840872x):
/*

#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;



#define FRO freopen("in.txt","r",stdin);



int main()

{

      ios_base::sync_with_stdio(false);

      cin.tie(nullptr);

	cout.tie(nullptr);

	cerr.tie(nullptr);





      int n,i,j







	return 0;

}



cout<<"Case "<<++tt<<": No"<<endl;



#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745

*/



#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;



#define FRO freopen("in.txt","r",stdin);



int arr[100005],dp[100005];

int fun(int n)

{

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

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

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

}







int main()

{

      ios_base::sync_with_stdio(false);

      cin.tie(nullptr);

	cout.tie(nullptr);

	cerr.tie(nullptr);





      int n,i,j;

      cin>>n;

      memset(dp,-1,sizeof dp);

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

      dp[0]=0;

      dp[1]=0;

      arr[0]=0;



      cout<<fun(n);







	return 0;

}