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

using namespace std;

int n;

int h[1000005], memo[1000005];

int f(int n) {

    if(n == 1) {                        // bisa juga base case nya n = 0, f(0) harus tinggi, misal 1e9;

        return 0;

    }

    if(n == 2) {

        return abs(h[1] - h[2]);

    } 

    else if(memo[n] != -1) {

        return memo[n];

    }

    memo[n] = min(f(n - 1) + abs(h[n] - h[n - 1]), f(n - 2) + abs(h[n] - h[n - 2]));

    return memo[n];

}



int main() {

    scanf("%d", &n);

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

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

    }

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

    f(n);

    printf("%d\n", f(n));

}

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

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2,fma")



using namespace std;



typedef long long ll;



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;



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

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

#define pi pair<int,int>

#define F first

#define S second

#define pb push_back

#define pp pop_back

#define mod 1000000007

#define pai acos(-1)

#define N 100005



ll ar[N],dp[N];



int main ()

{

   ios_base::sync_with_stdio(false);

   cin.tie(NULL);

   int n;cin>>n;

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

   dp[n]=0;

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

      dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),(i+2<=n)?dp[i+2]+abs(ar[i]-ar[i+2]):INT_MAX);

   }

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

   return 0;

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

using namespace std;



typedef signed long long ll;

const int MX = 1e5 + 5;

const int INF = 1e9 + 5;

int n, A[MX], dp[MX];



int solve(int pos) {

    if(pos > n) return INF;

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

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

    int ans = INF;

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

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

    return dp[pos] = ans;

}



int main() {

    scanf("%d", &n);



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

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

    }

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

    printf("%d\n", solve(0));

    return 0;

}

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

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2,fma")



using namespace std;



typedef long long ll;



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;



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

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

#define pi pair<int,int>

#define F first

#define S second

#define pb push_back

#define pp pop_back

#define mod 1000000007

#define pai acos(-1)

#define N 100005



ll ar[N],dp[N];



int main ()

{

   ios_base::sync_with_stdio(false);

   cin.tie(NULL);

   int n;cin>>n;

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

   dp[n]=0;

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

      dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),(i+2<=n)?dp[i+2]+abs(ar[i]-ar[i+2]):INT_MAX);

   }

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

   return 0;

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

#include<cmath>

#include<algorithm>

#include<cstring>

using namespace std;



int h[100055],dp[100055];

const int inf = 0x3f3f3f;

int main()

{

	int n;

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

	cin>>n;

	h[1]=inf;

	h[0]=inf;

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

		cin>>h[i];

	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;

} 

//max(h[i],h[i-2])-min(h[i],h[i-2])

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

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2,fma")



using namespace std;



typedef long long ll;



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;



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

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

#define pi pair<int,int>

#define F first

#define S second

#define pb push_back

#define pp pop_back

#define mod 1000000007

#define pai acos(-1)

#define N 100005



ll ar[N],dp[N];



int main ()

{

   ios_base::sync_with_stdio(false);

   cin.tie(NULL);

   int n;cin>>n;

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

   dp[n]=0;

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

      dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),(i+2<=n)?dp[i+2]+abs(ar[i]-ar[i+2]):INT_MAX);

   }

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

   return 0;

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

using namespace std;

#define IO ios::sync_with_stdio(false), cin.tie(0)

typedef long long ll;

const int maxn = 1e6 + 5;

const int inf = 0x3f3f3f3f;

ll a[maxn];

ll dp[maxn];



int main()

{

    IO;

    int n, k=2;

    cin >> n ;

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

        cin >> a[i];

    memset(dp, inf, sizeof(dp));

    dp[1] = 0;

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

    {

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

        {

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

        }

    }

    cout << dp[n] << endl;

}


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

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2,fma")



using namespace std;



typedef long long ll;



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;



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

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

#define pi pair<int,int>

#define F first

#define S second

#define pb push_back

#define pp pop_back

#define mod 1000000007

#define pai acos(-1)

#define N 100005



ll ar[N],dp[N];



int main ()

{

   ios_base::sync_with_stdio(false);

   cin.tie(NULL);

   int n;cin>>n;

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

   dp[n]=0;

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

      dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),(i+2<=n)?dp[i+2]+abs(ar[i]-ar[i+2]):INT_MAX);

   }

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

   return 0;

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

using namespace std;

const int nax = 1e5+3;

int number;

int dyn[nax];

int a[nax];

int op1(int i){

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

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

	int res = abs(a[i]-a[i+1])+op1(i+1);

	if(i!=number-2) res = min(res, abs(a[i]-a[i+2])+op1(i+2));

	return dyn[i]=res;

}

int main(){

	cin>>number;

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

	memset(dyn, -1, sizeof dyn);

	cout<<op1(0)<<endl;

	return 0;

}


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

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2,fma")



using namespace std;



typedef long long ll;



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;



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

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

#define pi pair<int,int>

#define F first

#define S second

#define pb push_back

#define pp pop_back

#define mod 1000000007

#define pai acos(-1)

#define N 100005



ll ar[N],dp[N];



int main ()

{

   ios_base::sync_with_stdio(false);

   cin.tie(NULL);

   int n;cin>>n;

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

   dp[n]=0;

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

      dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),(i+2<=n)?dp[i+2]+abs(ar[i]-ar[i+2]):INT_MAX);

   }

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

   return 0;

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

using namespace std;

int n, arr[100005], best, memo[100005];



int dp(int x){

	if(x==1 || x == 0){

		return 0;

	}

	if (x == 2){

		return abs(arr[x] - arr[x-1]);

	}

	if (memo[x] != -1){

		return memo[x];

	}

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

	memo[x] = best;

	return best;

}



int main(){

	ios_base::sync_with_stdio(0);

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

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	cout << dp(n) << endl;

}

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

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2,fma")



using namespace std;



typedef long long ll;



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;



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

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

#define pi pair<int,int>

#define F first

#define S second

#define pb push_back

#define pp pop_back

#define mod 1000000007

#define pai acos(-1)

#define N 100005



ll ar[N],dp[N];



int main ()

{

   ios_base::sync_with_stdio(false);

   cin.tie(NULL);

   int n;cin>>n;

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

   dp[n]=0;

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

      dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),(i+2<=n)?dp[i+2]+abs(ar[i]-ar[i+2]):INT_MAX);

   }

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

   return 0;

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

using namespace std;

int n, arr[100005], best, memo[100005];



int dp(int x){

	if(x==0 or x==1){

		return 0;

	}

	else if(x==2){

		return dp(x-1)+abs(arr[x]-arr[x-1]);

	}

	else if(memo[x]!=-1){

		return memo[x];

	}

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

	memo[x]=best;

	return best;

}



int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

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

	cin >> n;

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

		cin >> arr[i];

	}

	cout << dp(n) << endl;

}


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

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2,fma")



using namespace std;



typedef long long ll;



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;



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

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

#define pi pair<int,int>

#define F first

#define S second

#define pb push_back

#define pp pop_back

#define mod 1000000007

#define pai acos(-1)

#define N 100005



ll ar[N],dp[N];



int main ()

{

   ios_base::sync_with_stdio(false);

   cin.tie(NULL);

   int n;cin>>n;

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

   dp[n]=0;

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

      dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),(i+2<=n)?dp[i+2]+abs(ar[i]-ar[i+2]):INT_MAX);

   }

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

   return 0;

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

using namespace std;

int arr[100010],n;

int dp[100010];

int f(int pos){

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

	int &ret=dp[pos];

	if(ret^-1)return ret;

	if(pos+1==n-1)return ret=abs(arr[pos+1]-arr[pos]);

	return ret=min(f(pos+1)+abs(arr[pos]-arr[pos+1]),f(pos+2)+abs(arr[pos]-arr[pos+2]));

}



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

{

	memset(dp,-1,sizeof dp);

	cin>>n;

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

		cout<<f(0)<<endl;

	return 0;

}

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

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2,fma")



using namespace std;



typedef long long ll;



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;



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

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

#define pi pair<int,int>

#define F first

#define S second

#define pb push_back

#define pp pop_back

#define mod 1000000007

#define pai acos(-1)

#define N 100005



ll ar[N],dp[N];



int main ()

{

   ios_base::sync_with_stdio(false);

   cin.tie(NULL);

   int n;cin>>n;

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

   dp[n]=0;

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

      dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),(i+2<=n)?dp[i+2]+abs(ar[i]-ar[i+2]):INT_MAX);

   }

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

   return 0;

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

#define ll long long

using namespace std;

const int maxn = 1e5+5;

int a[maxn], dp[maxn];



int main(){

	int n; cin >> n;

	memset(dp, 0x3f, sizeof dp);

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

	dp[1] = 0;

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

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

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

	}

	cout << dp[n] << endl;

}

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

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2,fma")



using namespace std;



typedef long long ll;



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;



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

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

#define pi pair<int,int>

#define F first

#define S second

#define pb push_back

#define pp pop_back

#define mod 1000000007

#define pai acos(-1)

#define N 100005



ll ar[N],dp[N];



int main ()

{

   ios_base::sync_with_stdio(false);

   cin.tie(NULL);

   int n;cin>>n;

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

   dp[n]=0;

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

      dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),(i+2<=n)?dp[i+2]+abs(ar[i]-ar[i+2]):INT_MAX);

   }

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

   return 0;

}
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

/*                   وتزودوا فإن خير الزاد التقوى                    */

/*       وما تدري نفس ماذا تکسب غدا وما تدري نفس باي ارض تموت      */

#include <bits/stdc++.h>

#include<unordered_map>

#include<iomanip>

#include<fstream>

using namespace std;

#include<iostream>

#define endl '\n'

#define ll long long

#define ull unsigned long long

#define dll double

#define PI acos(-1)

#define watch(x) cout<<#x<<" = { "<<x<<" }\n"

#define sz(n) n.size()

#define M_Sayed fast() 

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

#define allr(v) v.rbegin(),v.rend()

#define RT(v) return cout<<v,0

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

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

const double EPS = (1e-7);

ll Ceil(ll x, ll y) { return (x + y - 1) / y; }

void run() {

#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);

	//freopen("output.txt", "w", stdout);

#else

#endif

}

ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }

ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

ll power(ll x, ll y, ll mod) {

	if (y == 0) return 1;

	if (y == 1) return x % mod;

	ll r = power(x, y >> 1, mod);

	return (((r * r) % mod) * power(x, y & 1, mod)) % mod;

}

void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }

ll n, m, k,su,cnt;

ll vis[100009];

vector<ll>v;

ll Jum(int x) {

	if (x+1 == n)

		return 0;

	ll &ret = vis[x];

	if (~ret)return ret;

	 ret = abs(v[x] - v[x + 1])+Jum(x + 1) ;

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

		if(i+x<n)ret = min(ret,Jum(x + i) + abs(v[x] - v[x + i]));

	}

	return ret;

}

int main()

{

	//run();

	M_Sayed;

	cin >> n ;

	memset(vis, -1, sizeof vis);

	v.resize(n);

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

		cin >> v[i];

	}

	k = 2;

	RT(Jum(0));

}

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

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2,fma")



using namespace std;



typedef long long ll;



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;



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

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

#define pi pair<int,int>

#define F first

#define S second

#define pb push_back

#define pp pop_back

#define mod 1000000007

#define pai acos(-1)

#define N 100005



ll ar[N],dp[N];



int main ()

{

   ios_base::sync_with_stdio(false);

   cin.tie(NULL);

   int n;cin>>n;

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

   dp[n]=0;

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

      dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),(i+2<=n)?dp[i+2]+abs(ar[i]-ar[i+2]):INT_MAX);

   }

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

   return 0;

}
// Slower C++ solution:
//       Author: Mostafa Mounir Shehab

 

#include <bits/stdc++.h>

using namespace std;

 

#define PI  3.14159265  // PI = acos(-1)

#define EPS (1e-10)

#define endl "\n"

#define SZ(v) (int)(v.size())

typedef long long ll;

typedef long double ld;

//template <class Type>

 

 

void Fast(){

	std::ios_base::sync_with_stdio(0);

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

}

 

inline int D(){

	int t;

	scanf("%d",&t);

	return t;

}

inline ll llD(){

	ll t;

	scanf("%lld",&t);

	return t;

}

 

 

ll MOD=1e9 + 7; 

const int N=1e5 + 5,M=50 + 1;

int arr[N];

ll dp[N];

ll OO=1e12; 

 

ll n,m,k,cnt,SU,idx,len,MN,MX;

ll l,r,mid;

ll a,b,c,d;



ll Solve(int idx){

	ll &ret = dp[idx];

	if(~ret)

		return ret;

		

	if(idx >= n)

		return ret = (idx == n) ? 0 : OO;

	

	

	ll x = abs(arr[idx] - arr[idx+1]) + Solve(idx+1);

	ll y = abs(arr[idx] - arr[idx+2]) + Solve(idx+2);

	

	return ret = min(x,y);

}







 

 

int main(){

	

	memset(dp, -1 ,sizeof dp);

	cin>>n;

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

		cin>>arr[i];



	cout<<Solve(1)<<endl;

	



	





}

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

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2,fma")



using namespace std;



typedef long long ll;



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;



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

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

#define pi pair<int,int>

#define F first

#define S second

#define pb push_back

#define pp pop_back

#define mod 1000000007

#define pai acos(-1)

#define N 100005



ll ar[N],dp[N];



int main ()

{

   ios_base::sync_with_stdio(false);

   cin.tie(NULL);

   int n;cin>>n;

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

   dp[n]=0;

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

      dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),(i+2<=n)?dp[i+2]+abs(ar[i]-ar[i+2]):INT_MAX);

   }

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

   return 0;

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

using namespace std;

const int maxn = 1e5 + 5;

int main(){

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

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

	scanf("%d",&n);

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

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

	dp[1] = 0;

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

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

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

	}

	printf("%d\n",dp[n]);

	return 0;

}

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

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2,fma")



using namespace std;



typedef long long ll;



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;



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

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

#define pi pair<int,int>

#define F first

#define S second

#define pb push_back

#define pp pop_back

#define mod 1000000007

#define pai acos(-1)

#define N 100005



ll ar[N],dp[N];



int main ()

{

   ios_base::sync_with_stdio(false);

   cin.tie(NULL);

   int n;cin>>n;

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

   dp[n]=0;

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

      dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),(i+2<=n)?dp[i+2]+abs(ar[i]-ar[i+2]):INT_MAX);

   }

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

   return 0;

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



using namespace std;



const int N = 1e5 + 9;



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



int sol(int i, int prev){

    if(i >= n)  return 1e9;

    if(i == n - 1)  return abs(h[i] - h[i - 1 - (prev == 1)]);



    int &ret = dp[i][prev];

    if(~ret)    return ret;



    return ret = abs(h[i] - h[i - 1 - (prev == 1)]) + min(sol(i + 1, 0), sol(i + 2, 1));

}



int main(){

    cin >> n;

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

        cin >> h[i];



    memset(dp, -1, sizeof dp);



    cout << min(sol(1, 0), sol(2, 1));



    return 0;

}

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

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2,fma")



using namespace std;



typedef long long ll;



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;



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

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

#define pi pair<int,int>

#define F first

#define S second

#define pb push_back

#define pp pop_back

#define mod 1000000007

#define pai acos(-1)

#define N 100005



ll ar[N],dp[N];



int main ()

{

   ios_base::sync_with_stdio(false);

   cin.tie(NULL);

   int n;cin>>n;

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

   dp[n]=0;

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

      dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),(i+2<=n)?dp[i+2]+abs(ar[i]-ar[i+2]):INT_MAX);

   }

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

   return 0;

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



using namespace std;



int n, h[100002], dp[100002][3];



int sol(int i, int choice){

    if(i==0) return 0;

    if(i<0) return 1E9;



    int &ret = dp[i][choice];

    if(~ret) return ret;



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

}



int main()

{

    cin >> n;

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

        cin >> h[i];



    memset(dp, -1, sizeof dp);

    cout << min(sol(n-1, 1), sol(n-1, 2));

}


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

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2,fma")



using namespace std;



typedef long long ll;



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;



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

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

#define pi pair<int,int>

#define F first

#define S second

#define pb push_back

#define pp pop_back

#define mod 1000000007

#define pai acos(-1)

#define N 100005



ll ar[N],dp[N];



int main ()

{

   ios_base::sync_with_stdio(false);

   cin.tie(NULL);

   int n;cin>>n;

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

   dp[n]=0;

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

      dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),(i+2<=n)?dp[i+2]+abs(ar[i]-ar[i+2]):INT_MAX);

   }

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

   return 0;

}