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

using namespace std;



typedef long long LL; 

typedef pair<int, int> pii; 

typedef pair<LL, LL> pll; 

typedef pair<string, string> pss; 

typedef vector<int> vi; 

typedef vector<vi> vvi; 

typedef vector<pii> vii; 

typedef vector<LL> vl; 

typedef vector<vl> vvl;

typedef queue<int> qi;

typedef queue<char> qc;

typedef stack<int> si;

typedef stack<char> sc;

#define F first

#define S second

#define PB push_back



int costs[1000001];

int dp[1000001];





int frog(int i, int n){



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

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

    int cost = abs(costs[i] - costs[i + 1]) + frog(i+1, n);

    if(i + 2 <= n){

        cost = min(cost, abs(costs[i] - costs[i+2]) + frog(i + 2, n));

    }



    return dp[i] = cost;

}



int main(){

    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);



    int n;

    cin >> n;

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

        cin >> costs[i];

    } //cost for a jump = abs(h.i - h.j)

      //find minimum cost



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

    cout << frog(1, n)<<endl;



    return 0;

}

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

using namespace std;



typedef long long ll;

typedef vector<int> vi;

#define PB push_back

#define MP make_pair

#define endl '\n'

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

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



int n;

int arr[100005];

int dp[100005];







int main()

{

    optimize();

    cin>>n;

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

        cin>>arr[i];

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

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

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



    cout<<dp[n]<<endl;



    return 0;

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

#define ll long long 

#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');

#define setbit(x,k) (x |= (1 << k))

#define clearbit(x,k) (x &= ~(1ll << k))

#define checkbit(x,k) (x & (1ll << k))

#define mp make_pair

#define scl(x) scanf("%lld",&x)

#define sci(x) scanf("%d",&x)

#define pb push_back

#define pf push_front

#define ppb pop_back

#define ppf pop_front

#define pii pair<int,int> 

#define YES printf("YES\n")

#define Yes printf("Yes\n")

#define yes printf("yes\n")

#define NO printf("NO\n")

#define No printf("No\n")

#define no printf("no\n")

#define nn printf("\n") 

#define mod 10000007

using namespace std;    



ll n;

ll h[100005];

ll dp[100005];

ll solve(int pos)

{

    if(pos>=n-1) return 0;

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

    ll res = LONG_LONG_MAX;

    if(pos+1<n) res = min(res, abs(h[pos]-h[pos+1]) + solve(pos+1));

    if(pos+2<n) res = min(res, abs(h[pos]-h[pos+2]) + solve(pos+2));

    return dp[pos] = res;

    

}



int main() 

{

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

   cin>>n;

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

   cout<<solve(0); nn;

}

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

using namespace std;



typedef long long ll;

typedef vector<int> vi;

#define PB push_back

#define MP make_pair

#define endl '\n'

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

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



int n;

int arr[100005];

int dp[100005];







int main()

{

    optimize();

    cin>>n;

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

        cin>>arr[i];

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

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

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



    cout<<dp[n]<<endl;



    return 0;

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



template <typename T>

using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



typedef long long ll;

typedef pair<ll, ll> pll;

typedef pair<int, int> pii;

typedef complex<double> point;



#define X real()

#define Y imag()

#define angle(a) (atan2((a).imag(), (a).real()))

#define vec(a, b) ((b) - (a))

#define same(p1, p2) (dp(vec(p1, p2), vec(p1, p2)) < EPS)

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

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

#define length(a) (hypot((a).imag(), (a).real()))

#define normalize(a) (a) / length(a)

#define rotateO(p, ang) ((p)*exp(point(0, ang)))

#define rotateA(p, ang, about) (rotateO(vec(about, p), ang) + about)

#define reflectO(v, m) (conj((v) / (m)) * (m))

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



const ll N = 100005;

const int MOD = 1e9 + 7;

const double EPS = 1e-7;

const double PI = acos(-1.0);



ll n, h[N];

ll memo[N];



ll solve(int i)

{

	if(i == n - 1)

		return 0;



	ll& ret = memo[i];

	if(~ret)

		return ret;



	ret = solve(i + 1) + llabs(h[i] - h[i + 1]);



	if(i < n - 2)

		ret = min(ret, solve(i + 2) + llabs(h[i] - h[i + 2]));



	return ret;

}



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(NULL), cout.tie(NULL);

    cin >> n;

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

    	cin >> h[i];

    clr(memo, -1);

    cout << solve(0) << endl;

}

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



using namespace std;



typedef long long ll;

typedef pair<ll, ll> pll;

typedef pair<int, int> pii;



const ll N = 100005;

const ll INF = 1e9;

const int MOD = 1e9 + 7;

const double EPS = 1e-7;

const double PI = acos(-1.0);



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



int main() {

	ios::sync_with_stdio(false);

	cin.tie(NULL), cout.tie(NULL);

	cin >> n;

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

		cin >> h[i];



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

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

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

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

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

using namespace std;



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



int solve(int x)

{

  if (x == n - 1)

    return 0;

  if (dp[x] != -1)

    return dp[x];

  int c = solve(x + 1) + abs(a[x] - a[x + 1]); 

  if (x < n - 2)

    c = min(c, solve(x + 2) + abs(a[x] - a[x + 2]));

  return dp[x] = c;

}



int main()

{

  memset(dp, -1, sizeof dp);

  cin >> n;

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

    cin >> a[i];

  cout << solve(0);

  return 0;

}

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

using namespace std;



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

#define wtf(s) freopen((s), "w", stdout)

#define rff(s) freopen((s), "r", stdin)

#define pi (2 * acos(0))

typedef long double ld;

typedef long long ll;

typedef complex<ld> point;

#define endl '\n'

#define matrix vector<vector<ll>>

#define EPS 1e-9

#define X real()

#define Y imag()

#define vec(a, b) ((b) - (a))

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

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

#define lengthsqr(v) (dot(v, v))

#define length(v) ((ld)hypot((v).Y, (v).X))

#define same(a, b) (lengthsqr(vec(a, b)) < EPS)



const int N = 1e5 + 5, inf = 1e9 + 5;

const ll mod = 1e9 + 7;



int dp[N], a[N];



int main()

{

    VIC

    int n;

    cin >> n;

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

        cin >> a[i];

    a[0] = a[1];

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

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

    cout << dp[n];

    return 0;

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

using namespace std;



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



int main()

{

    memset(dp, -1, sizeof dp);

    cin >> n;

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

        cin >> a[i];

    dp[n - 1] = 0;

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

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

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

      cout << dp[0];

      return 0;

}

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

using namespace std;



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

#define wtf(s) freopen((s), "w", stdout)

#define rff(s) freopen((s), "r", stdin)

#define pi (2 * acos(0))

typedef long double ld;

typedef long long ll;

typedef complex<ld> point;

#define endl '\n'

#define matrix vector<vector<ll>>

#define EPS 1e-9

#define X real()

#define Y imag()

#define vec(a, b) ((b) - (a))

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

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

#define lengthsqr(v) (dot(v, v))

#define length(v) ((ld)hypot((v).Y, (v).X))

#define same(a, b) (lengthsqr(vec(a, b)) < EPS)



const int N = 1e5 + 5, inf = 1e9 + 5;

const ll mod = 1e9 + 7;



int dp[N], a[N];



int main()

{

    VIC

    int n;

    cin >> n;

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

        cin >> a[i];

    a[0] = a[1];

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

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

    cout << dp[n];

    return 0;

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

using namespace std;

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#pragma GCC optimize ("-ffloat-store")  

#pragma GCC optimize ("-fno-defer-pop")

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

#define ll long long int

#define ld long double

ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}

ll modInverse(ll a, ll m) { return power(a, m-2, m); }

#define ps push_back

#define fs first

#define sc second

#define N 300005

#define endl "\n"

#define mod 1000000007

ll n,ar[N],dp[N];

ll minval(ll i){

	if(i==n){

		return 0;

	}

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

		return dp[i];

	}



	if(i+2<=n){

		ll a,b;

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

		b=minval(i+2)+abs(ar[i+2]-ar[i]);

		return dp[i]=min(a,b);

	}

	else {

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

	}

}

int main(){



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

	

	ll i,j,k,l;

	cin>>n;

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

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

		cin>>ar[i];

	}

	

	k=minval(1);

	cout<<k;

	return 0;

}


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

using namespace std;

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision

#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns

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

#define ll long long int

#define ld long double

ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}

ll modInverse(ll a, ll m) { return power(a, m-2, m); }

#define ps push_back

#define fs first

#define sc second

#define takeline cin.ignore();

#define iactive cout.flush();

#define N 3000005

#define endl "\n"

#define mod 1000000007

//((1.0l)*BIG MULTIPLY MAGIC?)

// string to integer stoi()

// string to long long stoll()

// string.substr(position,length);

// integer to string to_string();

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

ll n,ar[100005],dp[100005];

ll findmin(ll i){

	if(i==n){

		return 0;

	}

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

		return dp[i];

	}



	ll a=1e18,b=1e18;

	if(i+1<=n)

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

	if(i+2<=n)

		b=findmin(i+2)+abs(ar[i]-ar[i+2]);

	return dp[i]=min(a,b);

}

int main(){



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



	ll i,j,k,l;

	cin>>n;

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

		cin>>ar[i];

	}

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

	ll an=findmin(1);

	cout<<an;

	return 0;

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

using namespace std;

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#pragma GCC optimize ("-ffloat-store")  

#pragma GCC optimize ("-fno-defer-pop")

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

#define ll long long int

#define ld long double

ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}

ll modInverse(ll a, ll m) { return power(a, m-2, m); }

#define ps push_back

#define fs first

#define sc second

#define N 300005

#define endl "\n"

#define mod 1000000007

ll n,ar[N],dp[N];

ll minval(ll i){

	if(i==n){

		return 0;

	}

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

		return dp[i];

	}



	if(i+2<=n){

		ll a,b;

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

		b=minval(i+2)+abs(ar[i+2]-ar[i]);

		return dp[i]=min(a,b);

	}

	else {

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

	}

}

int main(){



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

	

	ll i,j,k,l;

	cin>>n;

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

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

		cin>>ar[i];

	}

	

	k=minval(1);

	cout<<k;

	return 0;

}


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

using namespace std;

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision

#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns

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

#define ll long long int

#define ld long double

ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}

ll modInverse(ll a, ll m) { return power(a, m-2, m); }

#define ps push_back

#define fs first

#define sc second

#define takeline cin.ignore();

#define iactive cout.flush();

#define N 100005

#define endl "\n"

#define mod 1000000007

#define PI 3.141592653589793

//((1.0l)*BIG MULTIPLY MAGIC?)

// string to integer stoi()

// string to long long stoll()

// string.substr(position,length);

// integer to string to_string();

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

ll n,ar[N],dp[N];

ll maxval(ll i){

	if(i==n) return 0;

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



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

	ll a,b;

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

	b=maxval(i+2)+abs(ar[i]-ar[i+2]);

	return dp[i]=min(a,b);

}

int main(){



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

	

	ll i,j,k,l;

	cin>>n;

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

		cin>>ar[i];

	}	

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

	ll an=maxval(1);

	cout<<an;

	return 0;	

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

using namespace std;

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#pragma GCC optimize ("-ffloat-store")  

#pragma GCC optimize ("-fno-defer-pop")

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

#define ll long long int

#define ld long double

ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}

ll modInverse(ll a, ll m) { return power(a, m-2, m); }

#define ps push_back

#define fs first

#define sc second

#define N 300005

#define endl "\n"

#define mod 1000000007

ll n,ar[N],dp[N];

ll minval(ll i){

	if(i==n){

		return 0;

	}

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

		return dp[i];

	}



	if(i+2<=n){

		ll a,b;

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

		b=minval(i+2)+abs(ar[i+2]-ar[i]);

		return dp[i]=min(a,b);

	}

	else {

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

	}

}

int main(){



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

	

	ll i,j,k,l;

	cin>>n;

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

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

		cin>>ar[i];

	}

	

	k=minval(1);

	cout<<k;

	return 0;

}


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

using namespace std;

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision

#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns

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

#define ll long long int

#define ld long double

ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}

ll modInverse(ll a, ll m) { return power(a, m-2, m); }

#define ps push_back

#define fs first

#define sc second

#define takeline cin.ignore();

#define iactive cout.flush();

#define N 100005

#define endl "\n"

#define mod 1000000007

//((1.0l)*BIG MULTIPLY MAGIC?)

// string to integer stoi()

// string to long long stoll()

// string.substr(position,length);

// integer to string to_string();

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

ll n,ar[N],dp[N];

ll maxval(ll i){

	if(i>=n) return 0;

	

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

		return dp[i];

	}

	ll an=1e18;

	if(i+1<=n) an=min(an,maxval(i+1)+abs(ar[i+1]-ar[i]));

	if(i+2<=n) an=min(an,maxval(i+2)+abs(ar[i+2]-ar[i]));

	return dp[i]=an;

}

int main(){

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

	

	ll i,j,k,l;

	cin>>n;

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

		cin>>ar[i];

	}

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

	ll an=maxval(1);

	cout<<an;

	return 0;

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

using namespace std;



const int MAXN = 1e5+5;

const int INF = 1e9+7;

int a[MAXN],dp[MAXN];

// The minimum we can get from i to 0 house

int main()

{

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



    int n;cin >> n;

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

        cin >> a[i];

    }



    dp[0] = 0;

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

        // We can jump in dp[i-1] or dp[i-2]

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

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

        }

    }

    cout << dp[n-1];

}


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

using namespace std;



const int MAXN = 3e5+5;

const int INF = 1e9+7;

#define ll long long

#define pb push_back

#define endl '\n'

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

#define F first

#define S second



ll poww(ll a, ll b, ll md) {

    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));

}



ll MOD(ll a){

    return ((a%INF)+INF)%INF;

}



ll inv(ll a){

    return poww(a,INF-2,INF);

}



int h[MAXN],dp[MAXN];



int main()

{

    fast_io;

    //cout << fixed << setprecision(15);



    int n;cin >> n;

    int k = 2;

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

    dp[n] = 0;

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

        dp[i] = INF;

        for(int j =i+1;j<=min(n,i+k);++j){

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

        }

    }

    cout << dp[1];

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

#include <cmath>

using namespace std;

 

int N, cost[100005], memo[500005];

 

int minCost(int v) {

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

  if (v <= 0) return 0;

  

  int a = minCost(v - 1) + abs(cost[v] - cost[v - 1]);

  int b;

  if (v == 1) {

    b = 1000000000;

  }

  else {

    b = minCost(v - 2) + abs(cost[v] - cost[v - 2]);

  }

  

  

  memo[v] = min(a, b);

  

  return (min(a, b));

}

 

int main() {

  cin >> N;

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

  

  for (int i = 0; i < 500005; i++) memo[i] = -1;

  

  cout << minCost(N - 1) << "\n";

  return 0;

}

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

#include <vector>

using namespace std;



const int MX = 100005;



int main() {

    int n; cin >> n;

    vector<int> a(MX), dp(MX, 0);

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

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

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

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

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

    }

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

    return 0;

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

#include <vector>

using namespace std;

typedef long long ll;



template<class T> inline bool chmin(T& a, T b){

    if(a>b){

        a=b;

        return true;

    }

    else

    {

        return false;

    }

}



int main(int argc, char const *argv[])

{

    int n;

    const ll INF = 1ll<<60;

    vector<ll> dp(100000,INF);

    cin >> n;

    vector<int> h(n);

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

    dp[0]=0;

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

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

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

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

    }

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

    



    return 0;

}


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

#include <vector>

using namespace std;



int main(int argc, char const *argv[])

{

    int n;cin>>n;

    vector<int> h(n);

    vector<int> dp(n,-1);

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

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

    if (n==2){

        cout << dp[1]<< endl;

        return 0;

    }

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

    if (n==3){

        cout << dp[2]<< endl;

        return 0;

    }

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

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

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

        dp[i]=min(d1,d2) ;

    }

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



    return 0;

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



using namespace std;



typedef long long ll;

typedef vector <int> vi;

typedef vector <ll> vl;

typedef pair <ll, ll> dl;

typedef pair <int, int> ii;

typedef vector <ii> vii;

typedef vector <vi> graph;



int n;

ll arr[100010];

ll dp[100010];



ll piedra(int id) {

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

	if (id >= n) return 1000000000;

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

	ll temp1, temp2;

	temp1 = abs(arr[id] - arr[id + 1]) + piedra(id + 1);

	temp2 = abs(arr[id] - arr[id + 2]) + piedra(id + 2);

	return dp[id] = min(temp1, temp2);

}



int main() {

    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);



	cin >> n;

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

	{

		cin >> arr[i];

	}

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

	{

		dp[i] = -1;

	}

	cout << piedra(0) << "\n";

    return 0;

}


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

#define tam 100010

#define inf 1000000000



using namespace std;



typedef long long ll;

typedef vector <int> vi;

typedef vector <ll> vl;

typedef pair <ll, ll> dl;

typedef pair <int, int> ii;

typedef vector <ii> vii;

typedef vector <vii> graph;



bool comp(int a, int b) {

	return a > b;

}



int main() {

	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);



	int n;

	cin >> n;

	int arr[n];

	vi dp (n, inf);

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

	{

		cin >> arr[i];

	}

	dp[0] = 0;

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

	{

		for (int j = i + 1; j < i + 3 && j < n; ++j)

		{

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

		}

	}

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

	return 0;

}