stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
////////////////////////////////////

//          ,.                    //

//         (_|,.                  //

//        ,' /, )_______   _      //

//     __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; 

// }

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

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

}


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

  

  

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

}

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

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

}




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



}
// Slower C++ solution:
//g++ -std=gnu++14 a.cpp

#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <iostream>

#include <istream>

#include <iterator>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <vector>

#include <tuple>

#include <iomanip>

#include <random>

using namespace std;



#define ll long long

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

ll MOD = 1e9 + 7;

int INF = 1 << 30;

ll INFL = 1LL << 60;



int main() {

  ll N;

  cin >> N;

  ll dp[1000010];

  rep(i,N){

    dp[i] = INF;

  }

  dp[0] = INF;

  vector<ll> h(N);

  rep(i,N){

    cin >> h[i];

  }

  dp[1] = 0;

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

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

  }

/*

  rep(i,N){

    cout << dp[i] <<endl;

  }

  */



  cout << dp[N] <<endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.1885313499356605x):
//g++ -std=gnu++14 a.cpp

#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <iostream>

#include <istream>

#include <iterator>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <vector>

#include <tuple>

#include <iomanip>

#include <random>

using namespace std;



#define ll long long

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

ll MOD = 1e9 + 7;

int INF = 1 << 30;

ll INFL = 1LL << 60;



int main(){



  ll N;

  cin >> N;

  vector<ll> h(N+1);



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

    cin >> h[i];

  }

  h[0]=INFL;

  vector<ll> dp(N+1, 0);

  dp[0] = 0;

  dp[1] = 0;



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

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

  }

  cout << dp[N] <<endl;





}
// Slower C++ solution:
//g++ -std=gnu++14 a.cpp

#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <iostream>

#include <istream>

#include <iterator>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <vector>

#include <tuple>

#include <iomanip>

#include <random>

using namespace std;



#define ll long long

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

ll MOD = 1e9 + 7;

int INF = 1 << 30;

ll INFL = 1LL << 60;



int main() {

  ll N;

  cin >> N;

  ll dp[1000010];

  rep(i,N){

    dp[i] = INF;

  }

  dp[0] = INF;

  vector<ll> h(N);

  rep(i,N){

    cin >> h[i];

  }

  dp[1] = 0;

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

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

  }

/*

  rep(i,N){

    cout << dp[i] <<endl;

  }

  */



  cout << dp[N] <<endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.1848570204539361x):
//g++ -std=gnu++14 a.cpp

//#include <bits/stdc++.h>

#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <iostream>

#include <istream>

#include <iterator>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <vector>

#include <tuple>

#include <iomanip>

#include <random>

#include <math.h>



using namespace std;



#define ll long long

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

ll MOD = 1e9 + 7;

int INF = 1 << 30;

ll INFL = 1LL << 60;



int main(){

  int N;

  cin >> N;

  vector<ll> h(N+10);

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

    cin >> h[i];

  }

  vector<ll> sum(N+10, INFL);

  sum[0] = INFL;

  sum[1] = 0;

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

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

  }

  //rep(i,N+1){

    cout << sum[N] << endl;

  //}





}
// Slower C++ solution:
//g++ -std=gnu++14 a.cpp

#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <iostream>

#include <istream>

#include <iterator>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <vector>

#include <tuple>

#include <iomanip>

#include <random>

using namespace std;



#define ll long long

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

ll MOD = 1e9 + 7;

int INF = 1 << 30;

ll INFL = 1LL << 60;



//int N;

vector<ll> h(100010);

vector<ll> dp(100010, INFL);



ll rec(ll i){

if(dp[i]<INFL) return dp[i];



  if(i==0) return 0;



  ll res = INF;

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

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

  return dp[i]=res;

}



int main(){

  ll N;

  cin >> N;

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

    cin >> h[i];

  }



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



}


// Faster C++ solution for the same problem (measured speedup: 2.5894162453032923x):
//g++ -std=gnu++14 a.cpp

//#include <bits/stdc++.h>

#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <iostream>

#include <istream>

#include <iterator>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <vector>

#include <tuple>

#include <iomanip>

#include <random>

#include <math.h>



using namespace std;



#define ll long long

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

ll MOD = 1e9 + 7;

int INF = 1 << 30;

ll INFL = 1LL << 60;



int main(){

  int N;

  cin >> N;

  vector<ll> h(N+10);

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

    cin >> h[i];

  }

  vector<ll> sum(N+10, INFL);

  sum[0] = INFL;

  sum[1] = 0;

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

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

  }

  //rep(i,N+1){

    cout << sum[N] << endl;

  //}





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

#define LL long long int 

#define LD long double

#define PI 3.14159265358979323846

#define MOD ((LL)1e9+7)

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

using namespace std;

const LL N=1e5+10;

vector<LL>A(N),dp(N);

vector<bool>f(N);

LL n;





LL DP(LL I)

{

	if(f[I])return dp[I];

	if(I==1)dp[I]=0;

	else if(I==2)dp[I]=abs(A[1]-A[2]);

	else

	{

		dp[I]=min(DP(I-1)+abs(A[I-1]-A[I]),DP(I-2)+abs(A[I]-A[I-2]));

	}

	f[I]=true;

	return dp[I];

	

}



int main()

{

	IOS

	cin>>n;

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

	cout<<DP(n)<<endl;

	

}

			

				

			

	

	

	

			

		




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

using namespace std;

#define MOD ((int)(1e9+7))

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

#define int long long

#define float long double



int ans=0,c=0;



int32_t main()

{

	IOS

	int n;cin>>n;

	vector<int>H(n+1),dp(n+1);

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

	dp[0]=1e17;

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

		

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

#include <vector>

using namespace std;

int n;

vector<int> h(100000);

vector<int> cost(100000);



int ans(int n)

{

    if (cost.at(n) != -1)

        return cost.at(n);

    cost.at(n) = min(ans(n - 1) + abs(h.at(n) - h.at(n - 1)),

                     ans(n - 2) + abs(h.at(n) - h.at(n - 2)));

    return cost.at(n);

}



int main()

{

    cin >> n;

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

    {

        cin >> h.at(i);

        cost.at(i) = -1;

    }

    cost.at(0) = 0;

    cost.at(1) = abs(h.at(1) - h.at(0));

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

}

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

#include <string>

#include <algorithm>

#include <vector>

#include <cmath>

#include <math.h>

using namespace std;

vector<long> memo;

vector<int> vc;

int dp(int num)

{

    if(memo[num] != -1) 

        return memo[num];

    memo[num] =  min(dp(num-1)+abs(vc[num]-vc[num-1]),dp(num-2)+abs(vc[num]-vc[num-2]));

    return memo[num];

}





int main()

{

    int N;

    cin >> N;

   

    int temp;

    

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

    {

        cin >> temp;

        vc.push_back(temp);

        memo.push_back(-1);

    }

    

    memo[0]=0;

    memo[1] = abs(vc[0]-vc[1]);



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

    

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

#include <vector>

using namespace std;

int n;

vector<int> h(100000);

vector<int> cost(100000);



int ans(int n)

{

    if (cost.at(n) != -1)

        return cost.at(n);

    cost.at(n) = min(ans(n - 1) + abs(h.at(n) - h.at(n - 1)),

                     ans(n - 2) + abs(h.at(n) - h.at(n - 2)));

    return cost.at(n);

}



int main()

{

    cin >> n;

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

    {

        cin >> h.at(i);

        cost.at(i) = -1;

    }

    cost.at(0) = 0;

    cost.at(1) = abs(h.at(1) - h.at(0));

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

}

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

#include <string>

#include <algorithm>

#include <vector>

#include <cmath>

#include <math.h>

using namespace std;

vector<long> memo;

vector<int> vc;

int dp(int num)

{

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

    else{

        memo[num] =  min(dp(num-1)+abs(vc[num]-vc[num-1]),dp(num-2)+abs(vc[num]-vc[num-2]));

        return memo[num];

    }

}





int main()

{

    int N;

    cin >> N;

   

    int temp;

    

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

    {

        cin >> temp;

        vc.push_back(temp);

        memo.push_back(-1);

    }

    

    memo[0]=0;

    memo[1] = abs(vc[0]-vc[1]);



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

    

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

#include <vector>

using namespace std;

int n;

vector<int> h(100000);

vector<int> cost(100000);



int ans(int n)

{

    if (cost.at(n) != -1)

        return cost.at(n);

    cost.at(n) = min(ans(n - 1) + abs(h.at(n) - h.at(n - 1)),

                     ans(n - 2) + abs(h.at(n) - h.at(n - 2)));

    return cost.at(n);

}



int main()

{

    cin >> n;

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

    {

        cin >> h.at(i);

        cost.at(i) = -1;

    }

    cost.at(0) = 0;

    cost.at(1) = abs(h.at(1) - h.at(0));

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

}

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

#include <string>

#include <algorithm>

#include <vector>

#include <cmath>

#include <math.h>

using namespace std;

vector<long> memo;



int dp(vector<int>& vc,int num)

{

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

    else{

        memo[num] =  min(dp(vc,num-1)+abs(vc[num]-vc[num-1]),dp(vc,num-2)+abs(vc[num]-vc[num-2]));

        return memo[num];

    }

}





int main()

{

    int N;

    cin >> N;

   

    int temp;

    vector<int> vc;

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

    {

        cin >> temp;

        vc.push_back(temp);

        memo.push_back(-1);

    }

    

    memo[0]=0;

    memo[1] = abs(vc[0]-vc[1]);



    cout << dp(vc,N-1) << endl;

    

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

#include <vector>

using namespace std;

int n;

vector<int> h(100000);

vector<int> cost(100000);



int ans(int n)

{

    if (cost.at(n) != -1)

        return cost.at(n);

    cost.at(n) = min(ans(n - 1) + abs(h.at(n) - h.at(n - 1)),

                     ans(n - 2) + abs(h.at(n) - h.at(n - 2)));

    return cost.at(n);

}



int main()

{

    cin >> n;

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

    {

        cin >> h.at(i);

        cost.at(i) = -1;

    }

    cost.at(0) = 0;

    cost.at(1) = abs(h.at(1) - h.at(0));

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

}

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

using namespace std;



typedef pair<int,int> P;

#define ll long long

#define ld long double

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

#define PI 3.14159265358979323846

#define sz(x) ((int)(x).size())

#define chmin(x,y) x = min(x,y)



const int INF = 1e9;

const int MOD = 1e9 + 7;

const ll LINF = 1e18;

ll dp[150000];

ll h[150000];

int main()

{

    int n;

    cin >> n;

    rep(i,n)

    {

        cin >> h[i];

    }

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

    rep(i,n)

    {

        dp[i] = LINF;

    }

    dp[0] = 0;

    for (int i = 0; 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;

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

using namespace std;

#define ll long long

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define si size()

#define bk back()

#define popb pop_back()

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

#define endl "\n"

#define lb lower_bound

#define ub upper_bound

#define emp empty()

#define beg begin()

#define en end()

#define ump unordered_map

#define forl(i,a,n) for(int i=a;i<n;i++)

#define rfor(i,n,a) for(int i=n;i>=a;i--)

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

#define len length()

#define N 100001 

int dp[N];

int func(int arr[],int i,int n)

{

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

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

	if(i==n-2) return dp[i]=abs(arr[i+1]-arr[i])+func(arr,i+1,n);

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

}

int main()

{

	int n;

	cin>>n;

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

	int arr[n];

	forl(i,0,n) cin>>arr[i];

	cout<<func(arr,0,n)<<endl;

	

	

}

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

using namespace std;

#define ll long long

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define si size()

#define bk back()

#define popb pop_back()

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

#define endl "\n"

#define lb lower_bound

#define ub upper_bound

#define emp empty()

#define beg begin()

#define en end()

#define ump unordered_map

#define forl(i,a,n) for(int i=a;i<n;i++)

#define rfor(i,n,a) for(int i=n;i>=a;i--)

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

#define len length()

#define N 200000

int main()

{

	int n;

	cin>>n;

	int arr[n];

	forl(i,0,n) cin>>arr[i];

	int dp[n];

	dp[0]=0;

	forl(i,1,n) dp[i]=INT_MAX;

	forl(i,1,n)

	{

		for(int j:{i-1,i-2})

		{

			if(j>=0)

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

		}

	}

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

	

	

}
// Slower C++ solution:
///----------------------///

///---Code Written by----///

///-----Al-Shahreyaj-----///

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

#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define endl "\n"

#define vin vector<int>

#define vll vector<long long>

#define pii pair<int,int>

#define pil pair<int,ll>

#define pll pair<ll,ll>

#define ff first

#define ss second

#define pb push_back

#define pq priority_queue

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

#define mod 1000000007

#define cone __builtin_popcount

#define conel __builtin_popcountll

typedef vector<vector<ll> > matrixl;

typedef vector<vector<int> > matrix;

#define N 100009



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



int solve(int i)

{

    if(i > n) return 0;

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

    int k = (n - i == 1? 1 : 2);

    return dp[i] = min(solve(i + 1) + (i + 1 <= n? abs(h[i+1] - h[i]) : 0), solve(i + k) + (i + k <= n? abs(h[i+k] - h[i]) : 0));

}



int main()

{

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

    cin >> n;

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

    cout << solve(1) << endl;

}


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

using namespace std;



int a[100009], dp[100009];



int main()

{

    int n;

    cin >> n;

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

    {

        cin >> a[i];

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

        else if(i > 2) 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;

}