stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define mod 1000000009

#define ll long long

#define mp make_pair

#define pb push_back

#define ff first

#define ss second

#define set0(a) memset ((a), 0 , sizeof(a))

#define set1(a) memset((a),-1,sizeof (a))

#define pi pair<int, int>

#define ps pair<string, string>

#define pl pair<long, long>

#define pll pair<long long, long long>

#define vll vector<long long>

#define vl vector<long>

#define vi vector<int>

#define vs vector<string>

#define vps vector< ps >

#define vpi vector< pi >

#define vpl vector< pl >

#define vpll vector< pll >

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

#define tc(t,T) for(long long t=0;t<T;t++)

#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)

#define meax 100007

 vll a(meax,0);

  vll b(meax,meax);

  ll sum1=0;

ll maximize(ll i,ll n,ll prev){



    if(b[i]!=meax){

        return b[i];

    }

    if(i>=n){

        return meax;

    }



    if(i==n-1){

            b[i]=0;

        return b[i];

    }

    ll d1=maximize(i+1,n,a[i]);

    ll d2=maximize(i+2,n,a[i]);

    b[i]=min(abs(a[i]-a[i+1])+d1,abs(a[i+2]-a[i])+d2);

    return b[i];





}

int main(){

    ll n;

    cin>>n;



    rep(i,0,n,1){

        cin>>a[i];

    }

    ll d=maximize(0,n,a[0]);

    cout<<d<<endl;

}


// Optimized solution to the same problem (faster):
#include <iostream>



using namespace std;



int N, ns[100000+9];

int dp[100000+9];

int main(){

    scanf("%d",&N);

    for(int i=0;i<N;i++)scanf("%d",&ns[i]);

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

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

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

    }

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

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
/**

 * @author      : Luis Miguel Baez <es.luismiguelbaez@gmail.com>

 * @created     : Thursday August 13, 2020

 */



#include <bits/stdc++.h>



using namespace std;



#define endl '\n'

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

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

#define ms(arr, value) memset(arr, value, sizeof arr)

#define ll    int64_t



#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "



string to_string(string s) {

    return '"' + s + '"';

}



string to_string(bool b) {

    return (b ? "true" : "false");

}



// add template here



template <typename A>

string to_string(A v) {

    bool first = true;

    string res = "{";

    for (const auto &x : v) {

        if (!first) {

            res += ", ";

        }

        first = false;

        res += to_string(x);

    }

    res += "}";

    return res;

}



template<class T>

void println(const T &data) {

#ifndef ONLINE_JUDGE

    cout << to_string((T)data) << endl;

#endif

}





const int oo  = (int)(1e9);

const ll lloo  = (ll)(1e18);



const int N = 1e5 + 10;



class Task {

public:

    int n;

    vector<int> A;



    ll dp[N];



    ll go(int index) {

        if(index > n) return 0LL;

        if(index == n) {

            return 0LL;

        }



        ll &ans = dp[index];

        if(ans != -1) return ans;



        ll x = oo;

        ll y = oo;



        if(index+1 <= n) {

            x = abs(A[index]-A[index+1]) + go(index + 1);

        }

        

        if(index+2 <= n) {

            y = abs(A[index]-A[index+2]) + go(index + 2);

        }

        ll mn = min(x, y);

        if(mn == oo) {

            ans = 0;

            return ans;

        }

        ans = min(x, y);

        return ans;

    }



    ll solveOne(istream &in, ostream &out) {

        in >> n;

        A.resize(n+1);

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

            in >> A[i];

        }

        memset(dp, -1, sizeof dp);

        ll ans = go(1);

        return ans;  

    }

    

    void solve(istream &in, ostream &out) {

        int t = 1;

        while(t--) {

            out << solveOne(in, out) << endl;

        }

    }

};



auto main() -> int {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    

    Task solver;

    istream &in(cin);

    ostream &out(cout);

    solver.solve(in, out);

    return 0;

}




// Optimized solution to the same problem (faster):
#include <iostream>



using namespace std;



int N, ns[100000+9];

int dp[100000+9];

int main(){

    scanf("%d",&N);

    for(int i=0;i<N;i++)scanf("%d",&ns[i]);

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

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

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

    }

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

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):


#include<bits/stdc++.h>

#define lld         long long int

#define llf         long double

#define pb          push_back

#define mp          make_pair

#define IN          insert

#define loopN(n)    for(lld i=0;i<n;i++)

#define loop(p,n)   for(lld i=p;i<=n;i++)

#define rloop(p,n)  for(lld i=n;i>=p;i--)

#define loop2(p,n)  for(lld j=p;j<=n;j++)

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

#define F1          first

#define F2          second

#define INF         2e18

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

#define PI          2*acos(0.0)

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

#define mem(a,b)    memset(a,b,sizeof(a))

#define case(z)     cout<<"Case "<<z<<": ";

using namespace std;

const lld mod=1e9+7;



lld n;

lld a[100005];

lld dp[100005];



lld fun(lld p)

{



    if(p==n-1)

    {

        return 0;

    }

    if(p==n-2)

    {

        return abs(a[p]-a[p+1]);

    }

    if(dp[p]!=-1)

    {

        return dp[p];

    }

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





}



int main()

{

    ISO;



    //lld t;cin>>t;while(t--)

    mem(dp,-1);

    cin>>n;

    loopN(n)cin>>a[i];

    cout<<fun(0)<<endl;



    return 0;

}




// Optimized solution to the same problem (faster):
#include <iostream>



using namespace std;



int N, ns[100000+9];

int dp[100000+9];

int main(){

    scanf("%d",&N);

    for(int i=0;i<N;i++)scanf("%d",&ns[i]);

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

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

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

    }

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

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):


#include <bits/stdc++.h>



using namespace std;





#define ll              long long

#define pb              push_back

#define nn           cout << "\n";





ll dp[100000],ht[100000];

int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    ll t,a,b,i,j,c,d,e,f,n,k,m,w;



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



    cin>>n;

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

    {

        cin>>a;

        ht[i]=a;



    }



    dp[n]=0;dp[n+1]=10000000;ht[n+1]=10000000;

    for(i=n-1;i>=1;i--)

    {

        

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

    }



    cout<<dp[1];

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

ll dp[100005];

int main()

{

   ll n;

   cin>>n;

   ll a[n];

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

    cin>>a[i];

   }

   dp[n-1]=0;

   for(int i=n-2;i>=0;i--){

    if(i==n-2){

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

    }

    else{

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

    }

   }

   cout<<dp[0];

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

ll dp[100005],ara[100005];

ll ans(ll n)

{

    if(n==1)

    {

        dp[1]=0;

    }

    if(n==2)

    {

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

        return dp[2];

    }

    if(dp[n]!=-1)

        return dp[n];

    dp[n]=min((ans(n-1)+abs(ara[n]-ara[n-1])),ans(n-2)+abs(ara[n]-ara[n-2]));

    return dp[n];

}

int main()

{

    ll n;

    int i;

    cin>>n;

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

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

    {

        cin>>ara[i];

    }

    cout<<ans(n)<<endl;

    return 0;

}




// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

const int INF = 10e9+5;

int main()

{

    int n,x,i,j;

    cin>>n;

    vector<int>v;

    vector<int>dp(n,INF);

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

   {

       cin>>x;

       v.push_back(x);

   }

    dp[0]=0;

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

    {

        for(j=i+1;j<=i+2;j++)

        {

            if(j<n)

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

        }

    }

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

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

#include<climits>

using namespace std;



#define ll long long

#define tc                int T;cin>>T;while(T--)

int a[100000];

int main()

{

	int n, c, b ; cin >> n;

	for (int& e : a)cin >> e;

	vector<int> dp(n, INT_MAX);

	dp[0] = 0;

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

		for (int e : {i + 1, i + 2}) {

			if (e < n)

				if ((dp[i] + abs(a[e] - a[i])) < dp[e])

					dp[e] = dp[i] + abs(a[e] - a[i]);

		}

	}

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

	return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

using namespace std;



#define ll long long

#define tc                int T;cin>>T;while(T--)

const int INF =1e9+5;

int main()

{

    ios_base::sync_with_stdio(false);cin.tie(NULL);

	int n, c, b ; cin >> n;

  	vector<int> a(n,0);

	for (int& e : a)cin >> e;

	vector<int> dp(n, INF);

	dp[0] = 0;

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

		for (int e : {i + 1, i + 2}) {

			if (e < n)

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

		}

	}

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

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

#include<climits>

using namespace std;



#define ll long long

#define tc                int T;cin>>T;while(T--)

int a[100000];

int main()

{

  ios_base::sync_with_stdio(false);cin.tie(NULL);

	int n, c, b ; cin >> n;

	for (int& e : a)cin >> e;

	vector<int> dp(n, INT_MAX);

	dp[0] = 0;

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

		for (int e : {i + 1, i + 2}) {

			if (e < n)

				if ((dp[i] + abs(a[e] - a[i])) < dp[e])

					dp[e] = dp[i] + abs(a[e] - a[i]);

		}

	}

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

	return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

using namespace std;



#define ll long long

#define tc                int T;cin>>T;while(T--)

const int INF =1e9+5;

int main()

{

    ios_base::sync_with_stdio(false);cin.tie(NULL);

	int n, c, b ; cin >> n;

  	vector<int> a(n,0);

	for (int& e : a)cin >> e;

	vector<int> dp(n, INF);

	dp[0] = 0;

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

		for (int e : {i + 1, i + 2}) {

			if (e < n)

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

		}

	}

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

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

#include<climits>

using namespace std;



#define ll long long

#define tc                int T;cin>>T;while(T--)

int a[100000];

int main()

{

    ios_base::sync_with_stdio(false);cin.tie(NULL);

	int n, c, b ; cin >> n;

	for (int& e : a)cin >> e;

	vector<int> dp(n, INT_MAX);

	dp[0] = 0;

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

		for (int e : {i + 1, i + 2}) {

			if (e < n)

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

		}

	}

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

	return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

using namespace std;



#define ll long long

#define tc                int T;cin>>T;while(T--)

const int INF =1e9+5;

int main()

{

    ios_base::sync_with_stdio(false);cin.tie(NULL);

	int n, c, b ; cin >> n;

  	vector<int> a(n,0);

	for (int& e : a)cin >> e;

	vector<int> dp(n, INF);

	dp[0] = 0;

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

		for (int e : {i + 1, i + 2}) {

			if (e < n)

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

		}

	}

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

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;

int dp[1000009];

int n,h[100000];

int bt(int i)

{

    if(i==n-1)

        return 0;

    if(i==n-2)

        return abs(h[i]-h[i+1]);

    if(dp[i]!=-1)

        return dp[i];

    int &ret=dp[i];

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

    return ret;

}

int main()

{

    cin>>n;

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

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

        cin>>h[i];

    cout<<bt(0);

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

int n,dp[100009],a[100009],mx=1e9+8;

int main()

{

    cin>>n;

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

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

    {

        dp[i]=mx;

    }

    dp[0]=0;

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

    {

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

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

    }

    cout<<dp[n-1];

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;

int dp[100000],n,arr[100000];

int bt(int i)

{

    if(dp[i]!=-1)

        return dp[i];

    if(i==n)

        return 99999999;

    if(i==n-1)

        return 0;

    int &ret=dp[i];

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

    return ret;

}

int main()

{

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

    cin>>n;

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

    {

        cin>>arr[i];

    }

    cout<<bt(0);

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

int n,dp[100009],a[100009],mx=1e9+8;

int main()

{

    cin>>n;

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

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

    {

        dp[i]=mx;

    }

    dp[0]=0;

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

    {

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

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

    }

    cout<<dp[n-1];

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int n,dp[100009],arr[100009];

int bt(int x)

{

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

    int &ret=dp[x];

    if(x==1)ret=abs(arr[x]-arr[x-1]);

    else ret=min(bt(x-1)+abs(arr[x]-arr[x-1]),bt(x-2)+abs(arr[x]-arr[x-2]));

    return ret;

}

int main()

{

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

    dp[0]=0;

    cin>>n;

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

    cout<<bt(n-1);

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

int n,dp[100009],a[100009],mx=1e9+8;

int main()

{

    cin>>n;

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

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

    {

        dp[i]=mx;

    }

    dp[0]=0;

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

    {

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

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

    }

    cout<<dp[n-1];

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;

typedef long long ll;



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

#define  output freopen("out.txt","w",stdout)



const int mxn = 1e5+5;

ll dp[mxn];

ll arr[mxn];

ll n;



ll solve(int i)

{

	if(i>=n) return 0;

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



	ll ret = 4e18;

	if(i==n-1) 

	{

		ll x = solve(i+1)+abs(arr[i]-arr[i+1]);

		ret = min(ret, x);

	}

	else

	{

		ll x = solve(i+1)+abs(arr[i]-arr[i+1]);

		ll y = solve(i+2)+abs(arr[i]-arr[i+2]);

		ret = min(ret, min(x, y));

	}

	return dp[i] = ret;

}

int main()

{

	//input;

	//output;



	cin >> n;



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

	memset(dp, -1, sizeof dp);

	ll ans = solve(1);

	cout << ans << '\n';

 	return 0;

 	

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;

typedef long long ll;



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

#define  output freopen("out.txt","w",stdout)



const int mxn = 1e5+5;

ll dp[mxn];

ll arr[mxn];

ll n;



int main()

{

	//input;

	//output;



	cin >> n;



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

	dp[0] = 0;



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

	{

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

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

	}

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

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

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

#define ll long long

#define endl '\n'

#define pb push_back

#define ff first

#define ss second

#define mod 1000000007

#define mx 200005

#define inf 2e9

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

//i  = current stair

int ans = 0;

int dp[mx];

int fun(int *h,int n,int i)

{

    if(i==(n-1))

        return 0;

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

        return dp[i];

    else if((i+1) <n && (i+2)<n)

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

    else if( (i+1)<n )

        return dp[i] = (abs(h[i+1] - h[i])+fun(h,n,i+1));

    else if((i+2)<n)

        return dp[i] = (abs(h[i+2] - h[i])+fun(h,n,i+2));

}

int main()

{

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

    int n;

    cin>>n;

    int h[n];

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

        cin>>h[i];

    cout<<fun(h,n,0)<<endl;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

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

#define ll long long

#define endl '\n'

#define pb push_back

#define ff first

#define ss second

#define mod 1e9+5

#define mx 200005

//#define inf 2e9

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

const int inf = 1e9+5;

//i  = current stair

int main()

{

    int n;

    cin>>n;

    int h[n];

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

        cin>>h[i];

    int dp[n];

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

        dp[i] = inf;

    dp[0] = 0;

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

    {

        for(int j= (i+1);j<=(i+2);j++)

        {

            if(j<n)

            {

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

            }

        }

    }

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

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



const int INF = 1 << 30;



int N;

int h[100010];



int dp[100010];



int main() {

    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++) {

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

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

    }



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



    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstring>

#include <iostream>

using namespace std;



const int INF = 1 << 30;



int N;

int h[100009];

int dp[100009];



int main() {

    cin >> N;

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

        cin >> h[i];



    dp[0] = INF;

    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;



    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



const int INF = 1 << 30;



int N;

int h[100010];



int dp[100010];



int main() {

    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 = 0; i < N; i++) {

        // dp[i] から dp[i + 1], dp[i + 2] に「配る」

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

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

    }



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



    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstring>

#include <iostream>

using namespace std;



const int INF = 1 << 30;



int N;

int h[100009];

int dp[100009];



int main() {

    cin >> N;

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

        cin >> h[i];



    dp[0] = INF;

    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;



    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



const int INF = 1 << 30;



int N;

int h[100010];



int dp[100010];



int solve(int i) {

    if(i == 0) return 0;

    if(dp[i] != INF) return dp[i];



    int res = INF;

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

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

    return dp[i] = res;

}



int main() {

    cin >> N;

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

        cin >> h[i];



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

        dp[i] = INF;



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



    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstring>

#include <iostream>

using namespace std;



const int INF = 1 << 30;



int N;

int h[100009];

int dp[100009];



int main() {

    cin >> N;

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

        cin >> h[i];



    dp[0] = INF;

    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;



    return 0;

}

// Fastest known solution for this problem: