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

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

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

#define     bug(a,b)        cout<<a<<"\t"<<b<<"\n";

#define     Case(a,b)       cout<<"Case "<<a<<": "<<b<<"\n";

#define     watch(a)        cout<<fixed<<setprecision(a)

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

#define     Endl            "\n";

#define     tab             "\t"

#define     reset(a,b)      memset(a,b,sizeof(a));

#define     sf(a)           scanf(" %d", &a);

#define     srt(a)          sort(a.begin(),a.end());

#define     pi              2*acos(0.0)

#define     inf             INT_MAX

const int sz=1e5+9;

int n,x,arr[sz],dp[sz];



int clac(int i){

    if(i==n) return 0;

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

    int left=abs(arr[i]-arr[i+1])+clac(i+1);

    int right=inf;

    if(i+2<=n){

        right=abs(arr[i]-arr[i+2])+clac(i+2);

    }

    return dp[i]=min(left,right);

}









void solve(){



    cin>>n;





    reset(dp,-1);

    //bug(n,dp[n]);

    lp(i,1,n+1)cin>>arr[i];

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



}



int main(){

    //FasterIO;

   // #ifndef ONLINE_JUDGE

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

   // #endif

    //int t;

    //cin>>t;

    //while(t--)

        solve();

}


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

#include<iomanip>

#include<cstdio>

#include<cmath>

#include<vector>

#include<string>

#include<algorithm>

#include<queue>

#include<set>

#include<map>

#include<limits>

#include<stack>



using namespace std;



typedef unsigned long long ll;

typedef pair<int,int> ii;

typedef vector<pair<int,int> > vii;

typedef vector<vii> vvii;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<ll> vll;

typedef vector<vll> vvll;

typedef vector<bool> vb;

typedef vector<vb> vvb;

typedef vector<char> vc;

typedef vector<vc> vvc;

typedef vector<string> vs;



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

int NINF = std::numeric_limits<int>::min();

int MOD = 1e9+7;



int col[] = {0,-1,0,1,1,1,-1,-1};

int row[] = {-1,0,1,0,1,-1,1,-1};



//knight moves

int cc[] = {1,2,2,1,-1,-1,-2,-2};

int rr[] = {-2,-1,1,2,-2,2,1,-1};



int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);



    int n;

    cin >> n;



    vi hight(n);

    vll cost(n);



    cin >> hight[0];

    cost[0] = 0;



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

    {

        cin >> hight[i];



        if(i > 1)

        {

            ll one = abs(hight[i]-hight[i-1]), two = abs(hight[i]-hight[i-2]);



            cost[i] = min(one+cost[i-1],two+cost[i-2]);



            //cout << i << " " << cost[i] << endl;

        }

        else

        {

            cost[i] = abs(hight[0]-hight[1]);

        }

    }



    cout << cost[n-1];



    return 0;

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

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

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

#define     bug(a,b)        cout<<a<<"\t"<<b<<"\n";

#define     Case(a,b)       cout<<"Case "<<a<<": "<<b<<"\n";

#define     watch(a)        cout<<fixed<<setprecision(a)

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

#define     Endl            "\n";

#define     tab             "\t"

#define     reset(a,b)      memset(a,b,sizeof(a));

#define     sf(a)           scanf(" %d", &a);

#define     srt(a)          sort(a.begin(),a.end());

#define     pi              2*acos(0.0)

#define     inf             INT_MAX

const int sz=1e5+9;

int n,x,arr[sz],dp[sz];



int clac(int i){

    if(i==n) return 0;

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

    int left=abs(arr[i]-arr[i+1])+clac(i+1);

    int right=inf;

    if(i+2<=n){

        right=abs(arr[i]-arr[i+2])+clac(i+2);

    }

    return dp[i]=min(left,right);

}



void solve(){

    cin>>n;

    reset(dp,-1);

    lp(i,1,n+1)cin>>arr[i];

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

}



int main(){

    //FasterIO;

    #ifndef ONLINE_JUDGE

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

   #endif

   // int t;

    //cin>>t;

    //while(t--)

        solve();

}


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

#include<iomanip>

#include<cstdio>

#include<cmath>

#include<vector>

#include<string>

#include<algorithm>

#include<queue>

#include<set>

#include<map>

#include<limits>

#include<stack>



using namespace std;



typedef unsigned long long ll;

typedef pair<int,int> ii;

typedef vector<pair<int,int> > vii;

typedef vector<vii> vvii;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<ll> vll;

typedef vector<vll> vvll;

typedef vector<bool> vb;

typedef vector<vb> vvb;

typedef vector<char> vc;

typedef vector<vc> vvc;

typedef vector<string> vs;



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

int NINF = std::numeric_limits<int>::min();

int MOD = 1e9+7;



int col[] = {0,-1,0,1,1,1,-1,-1};

int row[] = {-1,0,1,0,1,-1,1,-1};



//knight moves

int cc[] = {1,2,2,1,-1,-1,-2,-2};

int rr[] = {-2,-1,1,2,-2,2,1,-1};



int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);



    int n;

    cin >> n;



    vi hight(n);

    vll cost(n);



    cin >> hight[0];

    cost[0] = 0;



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

    {

        cin >> hight[i];



        if(i > 1)

        {

            ll one = abs(hight[i]-hight[i-1]), two = abs(hight[i]-hight[i-2]);



            cost[i] = min(one+cost[i-1],two+cost[i-2]);



            //cout << i << " " << cost[i] << endl;

        }

        else

        {

            cost[i] = abs(hight[0]-hight[1]);

        }

    }



    cout << cost[n-1];



    return 0;

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

#define f(i,s,v) for(int i=(int)s;i<(int)v;++i)

#define rf(i,s,v) for(int i=(int)s-1;i>(int)v;--i)

#define pb push_back

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

#define memset(c, value) memset(c, (int)value, sizeof(c))

using namespace std;

typedef long long ll;

const int oo = 1e9;

const ll MOD =1e9+7;

void fast(){

    ios_base :: sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}

int n;

int h[100005];

bool valid (int r,int c){

    return (r < n && r >= 0 && c >= 0 && c < n);

}

int row[] = {0 , 1 , 0, -1};

int column[] = {1 , 0, -1, 0};

int vis[100002];

int dp(int i){

    if(i == n-1)

        return 0;

    int &ret = vis[i];

    if(ret != -1)

        return ret;



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

    if(i+2 < n)

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

    return ret = path1;

}



int main()

{

    fast();

    memset(vis, -1);

    cin>>n;

    f(i,0,n)

        cin>>h[i];

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

    return 0;

}


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

#include<iomanip>

#include<cstdio>

#include<cmath>

#include<vector>

#include<string>

#include<algorithm>

#include<queue>

#include<set>

#include<map>

#include<limits>

#include<stack>



using namespace std;



typedef unsigned long long ll;

typedef pair<int,int> ii;

typedef vector<pair<int,int> > vii;

typedef vector<vii> vvii;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<ll> vll;

typedef vector<vll> vvll;

typedef vector<bool> vb;

typedef vector<vb> vvb;

typedef vector<char> vc;

typedef vector<vc> vvc;

typedef vector<string> vs;



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

int NINF = std::numeric_limits<int>::min();

int MOD = 1e9+7;



int col[] = {0,-1,0,1,1,1,-1,-1};

int row[] = {-1,0,1,0,1,-1,1,-1};



//knight moves

int cc[] = {1,2,2,1,-1,-1,-2,-2};

int rr[] = {-2,-1,1,2,-2,2,1,-1};



int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);



    int n;

    cin >> n;



    vi hight(n);

    vll cost(n);



    cin >> hight[0];

    cost[0] = 0;



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

    {

        cin >> hight[i];



        if(i > 1)

        {

            ll one = abs(hight[i]-hight[i-1]), two = abs(hight[i]-hight[i-2]);



            cost[i] = min(one+cost[i-1],two+cost[i-2]);



            //cout << i << " " << cost[i] << endl;

        }

        else

        {

            cost[i] = abs(hight[0]-hight[1]);

        }

    }



    cout << cost[n-1];



    return 0;

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

#include<cstring>

#include<algorithm>





using namespace std;



const long long inf= 1e10+ 123;

const int mx=1e5+123;

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



int solve( int i)

{

    if(i==n)

        return 0;



    if(dp[i]!= -1)

        return dp[i];



    int ret1, ret2;

    ret1= abs(h[i]- h[i+1])+ solve(i+1);

    if(i+2<=n)

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

    else

        ret2= inf;

    return dp[i]=min(ret1, ret2);

}



int main()

{

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



    cin>> n;

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

        cin>> h[i];



    cout<< solve(1)<< endl;



    return 0;

}


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

#include<iomanip>

#include<cstdio>

#include<cmath>

#include<vector>

#include<string>

#include<algorithm>

#include<queue>

#include<set>

#include<map>

#include<limits>

#include<stack>



using namespace std;



typedef unsigned long long ll;

typedef pair<int,int> ii;

typedef vector<pair<int,int> > vii;

typedef vector<vii> vvii;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<ll> vll;

typedef vector<vll> vvll;

typedef vector<bool> vb;

typedef vector<vb> vvb;

typedef vector<char> vc;

typedef vector<vc> vvc;

typedef vector<string> vs;



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

int NINF = std::numeric_limits<int>::min();

int MOD = 1e9+7;



int col[] = {0,-1,0,1,1,1,-1,-1};

int row[] = {-1,0,1,0,1,-1,1,-1};



//knight moves

int cc[] = {1,2,2,1,-1,-1,-2,-2};

int rr[] = {-2,-1,1,2,-2,2,1,-1};



int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);



    int n;

    cin >> n;



    vi hight(n);

    vll cost(n);



    cin >> hight[0];

    cost[0] = 0;



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

    {

        cin >> hight[i];



        if(i > 1)

        {

            ll one = abs(hight[i]-hight[i-1]), two = abs(hight[i]-hight[i-2]);



            cost[i] = min(one+cost[i-1],two+cost[i-2]);



            //cout << i << " " << cost[i] << endl;

        }

        else

        {

            cost[i] = abs(hight[0]-hight[1]);

        }

    }



    cout << cost[n-1];



    return 0;

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

using namespace std;

#define    sz    100110

#define    ll    long long int

ll n,c=0,p,q;

ll num[sz];

ll vis[sz];

ll dp[sz];



ll tani(int pos)

{



  if(pos>=n)return 0;

  if(vis[pos]==1)return dp[pos];

  vis[pos]=1;



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



}



int main()

{

    ll t,i;



    for(i=1;i<sz;i++)num[i]=1000000;



    cin>>n;

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

    {

        cin>>num[i];

    }

    t=tani(1);

    cout<<t<<endl;

    return 0;

}


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

 ALLAH is Almighty....

*/

#include <bits/stdc++.h>



#define ll  long long

using namespace std;



const ll mx = 10e5 + 9;

ll n;

ll ar[ mx ];

ll dp[ mx ];



void solve( )

{

    cin >> n;

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

        cin >> ar[ i ];



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



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

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



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

}



int main()         // Md. Inzamam-ul Haque

{

    solve();

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

using namespace std;



#define fr(i,n) _back

#define pb	push_back

#define eb	emplace_back

#define mk	make_pair

#define fi	first

#define se	second

#define endl	'\n'



typedef long long ll;

typedef pair<int,int> ii;

typedef vector<ii> vii;

const int INF = 0x3f3f3f3f;

const double PI = acos(-1.0);

const int N = 1e5 + 3;

int h[N];

int dp[N];



int main() {

    ios_base::sync_with_stdio(false);

    memset(dp, INF, sizeof dp);

    int n; cin >> n;

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



    dp[0] = 0;

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

        for(int j = max(0,i-2); j < i; j++)

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



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

    return 0;

}


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

 ALLAH is Almighty....

*/

#include <bits/stdc++.h>



#define ll  long long

using namespace std;



const ll mx = 10e5 + 9;

ll n;

ll ar[ mx ];

ll dp[ mx ];



void solve( )

{

    cin >> n;

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

        cin >> ar[ i ];



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



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

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



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

}



int main()         // Md. Inzamam-ul Haque

{

    solve();

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

using namespace std;



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



int f(int n) {

	if (n==1) return 0;

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

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

	dp[n] = min(

				f(n-1) + abs(a[n] - a[n-1]),

				f(n-2) + abs(a[n] - a[n-2])

				);

	return dp[n];

}



int main() {

	cin >> N;

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

		cin >> a[i];

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

	cout << f(N) << endl;

	return 0;

}

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

 ALLAH is Almighty....

*/

#include <bits/stdc++.h>



#define ll  long long

using namespace std;



const ll mx = 10e5 + 9;

ll n;

ll ar[ mx ];

ll dp[ mx ];



void solve( )

{

    cin >> n;

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

        cin >> ar[ i ];



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



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

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



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

}



int main()         // Md. Inzamam-ul Haque

{

    solve();

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

using namespace std;

typedef long long LL;



int arr[100007];

int dp[100007];



int Solve(int idx, int n){

//	cout<<cost<<" "<<idx<<endl;

	if(idx >= n)return 1e9;

	if(idx == n - 1){

		return 0;	

	}

	

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

	

	

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

}



int main(){

	int n; cin>>n;

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

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

		

	cout<<Solve(0,n)<<endl;

	return 0;

}

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

 ALLAH is Almighty....

*/

#include <bits/stdc++.h>



#define ll  long long

using namespace std;



const ll mx = 10e5 + 9;

ll n;

ll ar[ mx ];

ll dp[ mx ];



void solve( )

{

    cin >> n;

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

        cin >> ar[ i ];



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



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

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



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

}



int main()         // Md. Inzamam-ul Haque

{

    solve();

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

using namespace std;

int dp[100005];

int H[100005];

void memo(int i,int n)

{

	if(i==n) return;

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

	memo(i+1,n);

}

int main()

{

	int N;cin>>N;

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

	{

        cin>>H[i];

	}

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

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

	memo(2,N);

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

	return 0;

}

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

 ALLAH is Almighty....

*/

#include <bits/stdc++.h>



#define ll  long long

using namespace std;



const ll mx = 10e5 + 9;

ll n;

ll ar[ mx ];

ll dp[ mx ];



void solve( )

{

    cin >> n;

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

        cin >> ar[ i ];



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



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

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



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

}



int main()         // Md. Inzamam-ul Haque

{

    solve();

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



using namespace std;



int dp[(int)1e5+5];

int main()

{



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







    fill(dp, dp+(int)1e5+5 , INT_MAX );



    dp[1] = 0;

    int n;

    cin>>n;

    vector <int> v(n+3,0);

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



        cin>>v[i];



    }

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



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

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



    }

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

}


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

 ALLAH is Almighty....

*/

#include <bits/stdc++.h>



#define ll  long long

using namespace std;



const ll mx = 10e5 + 9;

ll n;

ll ar[ mx ];

ll dp[ mx ];



void solve( )

{

    cin >> n;

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

        cin >> ar[ i ];



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



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

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



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

}



int main()         // Md. Inzamam-ul Haque

{

    solve();

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



using namespace std;



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

#define DB( x ) cout << #x << " = " << x << endl;

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

#define endl '\n'



typedef long long ll;

typedef unsigned long long ull;

typedef pair<ll, ll> pii;

typedef pair<int, pii> tri;

typedef vector <vector <ll>> matrix;

typedef pair<string, string> pss;



const ll mod = (ll)1e9 + 7;

const int MAX = (int)1e6 + 100;



const ll oo = 0x3f3f3f3f3f3f3f3f;



ll dp[MAX], a[MAX];



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    memset(dp, oo, sizeof(dp));



    int n; cin >> n;



    dp[1] = 0;



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

        cin >> a[i];

    }



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

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

        if(i - 2 >= 1){

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

        }

    }



    cout << dp[n] << endl;

}


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

 ALLAH is Almighty....

*/

#include <bits/stdc++.h>



#define ll  long long

using namespace std;



const ll mx = 10e5 + 9;

ll n;

ll ar[ mx ];

ll dp[ mx ];



void solve( )

{

    cin >> n;

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

        cin >> ar[ i ];



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



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

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



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

}



int main()         // Md. Inzamam-ul Haque

{

    solve();

}
// Slower C++ solution:
/*|In The Name Of Allah|*/



#include <bits/stdc++.h>



using namespace std;



const int N = 1e5+5;



int n;

int h[N];

int mem[N];



int go(int idx){

    if(idx >= n)

        return 0;

    if(mem[idx] != -1)

        return mem[idx];

    int best = 1e9;

    if(idx + 1 <= n)

        best = go(idx + 1) + abs(h[idx] - h[idx + 1]);

    if(idx + 2 <= n)

        best = min(best , go(idx + 2)  + abs(h[idx] - h[idx + 2]));

    return mem[idx] = best;

}



int main(){

    scanf("%d" , &n);

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

        scanf("%d" , &h[i]);

    }

    memset(mem , -1 , sizeof mem);

    printf("%d\n" , go(1));

}

//1 2 3


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

 ALLAH is Almighty....

*/

#include <bits/stdc++.h>



#define ll  long long

using namespace std;



const ll mx = 10e5 + 9;

ll n;

ll ar[ mx ];

ll dp[ mx ];



void solve( )

{

    cin >> n;

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

        cin >> ar[ i ];



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



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

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



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

}



int main()         // Md. Inzamam-ul Haque

{

    solve();

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

#define pii pair<int,int>

#define vi vector<int>

#define ppii pair<pii>



using namespace std;

const int maxn=1e5+5;



int n;

vi arr;

int dp[maxn];



int dfs(int pos)

{

    if(pos==n){return 0;}



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



    int ans=(1<<29);



    if(pos<n)

        ans=min(ans,dfs(pos+1) + abs(arr[pos]-arr[pos+1]));

    if(pos<n-1)

        ans=min(ans,dfs(pos+2) + abs(arr[pos]-arr[pos+2]));

    dp[pos]=ans;



    return ans;

}



int main()

{

    ios_base::sync_with_stdio(0);

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



    cin>>n;



    arr=vi(n+1);



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

        cin>>arr[i];



    memset(dp,-1,sizeof dp);



    cout<<dfs(1);



    return 0;

}


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

 ALLAH is Almighty....

*/

#include <bits/stdc++.h>



#define ll  long long

using namespace std;



const ll mx = 10e5 + 9;

ll n;

ll ar[ mx ];

ll dp[ mx ];



void solve( )

{

    cin >> n;

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

        cin >> ar[ i ];



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



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

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



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

}



int main()         // Md. Inzamam-ul Haque

{

    solve();

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

#include <queue>

typedef long long ll;



using namespace std;



const int N=1e5+5;





int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

   int n,k=2;

   cin>>n;

   int arr[N]={},dp[N]={};

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

    cin>>arr[i];

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

   dp[0]=0;

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

   {



     for(int j=1;j<=k;j++)

     {

         if(i-j>=0)

         {

             if(dp[i]==-1)

             {

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

             }

             else

             {

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





             }





         }



     }









   }

   cout<<dp[n-1];



   return 0;

}


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

 ALLAH is Almighty....

*/

#include <bits/stdc++.h>



#define ll  long long

using namespace std;



const ll mx = 10e5 + 9;

ll n;

ll ar[ mx ];

ll dp[ mx ];



void solve( )

{

    cin >> n;

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

        cin >> ar[ i ];



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



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

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



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

}



int main()         // Md. Inzamam-ul Haque

{

    solve();

}