stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


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

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

}


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

	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;

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

}


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

	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;

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

}


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

	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;

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

}


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

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

}


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

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

}


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

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

}


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

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

}


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

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

 	

}

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

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

}


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

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

}

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

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

}

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

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

}

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

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

using namespace std;

typedef long long ll;

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 ll INF=(1LL<<60);



int main(void){

    int n; cin >> n;

    ll h[100100];

    ll dp[100100];

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



    for(int i=0; i<100100; i++) dp[i]=INF;

    dp[1]=0;



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

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

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

    }

    cout << dp[n] << endl;

}

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

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }



/* attention

    long longのシフト演算には気をつけよう

    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも

    sizeは(int)とキャストしよう

    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？

*/



const ll mod = 1e9+7;



void chmod(ll &M){

    if(M >= mod) M %= mod;

    else if(M < 0){

        M += (abs(M)/mod + 1)*mod;

        M %= mod;

    }

}



ll modpow(ll x, ll n){

    if(n == 0) return 1;



    ll res = modpow(x, n/2);

    if(n%2 == 0) return res*res%mod;

    else return res*res%mod*x%mod;

}



ll power(ll x, ll n){

    if(n == 0) return 1;



    ll res = power(x, n/2);

    if(n%2 == 0) return res*res;

    else return res*res*x;

}



int getl(int i, int N) { return i==0? N-1:i-1; };

int getr(int i, int N) { return i==N-1? 0:i+1; };



/* <--------------------------------------------> */



int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);



    int n; cin >> n;

    vector<int> h(n);

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

    const int inf = 1<<30;

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

    dp[1][0] = dp[1][1] = 0;

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

    

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

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

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

    }



    cout << min(dp[n][0], dp[n][1]) << endl;    



	return 0;

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

using namespace std;

typedef long long ll;

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 ll INF=(1LL<<60);



int main(void){

    int n; cin >> n;

    ll h[100100];

    ll dp[100100];

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



    for(int i=0; i<100100; i++) dp[i]=INF;

    dp[1]=0;



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

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

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

    }

    cout << dp[n] << endl;

}

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

using namespace std;

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

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

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

#define reprev(i,n) reprrev(i,0,n)

typedef long long ll;

typedef unsigned long long ull;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

 

/* attention

    long longのシフト演算には気をつけよう

    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも

    sizeは(int)とキャストしよう

    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？

    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）

    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか

    cin.tie(0);

    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう



*/



const ll mod = 1e9+7;



void chmod(ll &M){

    if(M >= mod) M %= mod;

    else if(M < 0){

        M += (abs(M)/mod + 1)*mod;

        M %= mod;

    }

}



int getl(int i, int N) { return i==0? N-1:i-1; };

int getr(int i, int N) { return i==N-1? 0:i+1; };



/* <--------------------------------------------> */





int main(void){

    cin.tie(0);

    ios::sync_with_stdio(false);



    int n; cin >> n;

    vector<int> h(n+5, 0);

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



    vector<int> dp(n+5, 0);

    repr(i, 2, n+1){

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

        else 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;

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

using namespace std;



const int INF = 1<<30;



int dp[100010];

int h[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=0;i<n;i++){

		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;

}


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

using namespace std;



#define INF (1<<30)

#define MAX 100010



int dp[MAX];

int h[MAX];



int main(){

	int n;	cin>>n;

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

		cin>>h[i];

		dp[i]=INF;

	}

	dp[0]=0;



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

		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;

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

using namespace std;

int min(int a, int b) {

  if (a < b) return a;

  else return b;

}

int ze(int a) {

  int t = min(a, 0);

  int j = a - 2 * t;

  return j;

}

int main () {

  int N;

  cin >> N;

  int h[1100000];

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

    cin >> h[i];

  }

  int cost[100000];

  cost[2] = ze(h[1] - h[0]);

  int k = cost[2] + ze(h[2] - h[1]);

  int j = ze(h[2] - h[0]);

  cost[3] = min(k, j);

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

    int a = cost[i - 1] + ze(h[i - 1] - h[i - 2]);

    int b = cost[i - 2] + ze(h[i - 1] - h[i - 3]);

    cost[i] = min(a, b);

  }

  cout << cost[N] << endl;

}

    


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

using namespace std;

int ze(int a, int b) {

  return max(a - b, b - a);

}

int main () {

  int N;

  cin >> N;

  vector<int>he(N);

  for (int i = 0; i < N; i ++) cin >> he[i];

  vector<int>dp(N);

  dp[0] = 0;

  dp[1] = ze(he[0], he[1]);

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

    int ku = dp[i - 1] + ze(he[i], he[i - 1]);

    int ma = dp[i - 2] + ze(he[i], he[i - 2]);

    dp[i] = min(ku, ma);

  }

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

}