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

using namespace std;

#define f first

#define s second

typedef long long int ll;

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

int n,a[N],memo[N];

int solve(int ind){

    if(ind==n-1)

        return 0;

    if(~memo[ind])

        return memo[ind];

    if(ind+1!=n-1)

    return memo[ind]= min( abs(a[ind+1]-a[ind])+ solve(ind+1), abs(a[ind+2]-a[ind])+solve(ind+2) ) ;

    return memo[ind]= abs(a[ind+1]-a[ind]);

}

int main(){

    cin.tie(NULL);

    ios_base::sync_with_stdio(false);

    memset(memo,-1,sizeof memo);

    cin>>n;

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

        cin>>a[i];

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

    return 0;

}


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

using namespace std;

#define f first

#define s second

typedef long long int ll;

const int N=1e5+5,MAX=1e9+2;

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

int main(){

    cin.tie(NULL);

    cout.tie(NULL);

    ios_base::sync_with_stdio(false);

    cin>>n;

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

        cin>>a[i];

        dp[i]=MAX;

    }

    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]<<'\n';

    return 0;

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

#include<algorithm>

#include<string.h>

#define ll long long

#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

#define fr first

#define sc second

#define M_PI           3.14159265358979323846

using namespace std;

int n;

int Dp[200200];

int A[100100];

int Solve(int i)

{



    if(i>n-1)

        return 1e9;

    if(i==n-1)

        return 0;

    if(Dp[i]!=-1)

        return Dp[i];

    Dp[i]=min(Solve(i+1)+abs(A[i+1]-A[i]), Solve(i+2)+abs(A[i+2]-A[i]));



    return Dp[i];

}

int main()

{

    Start;



    cin>>n;

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

        cin>>A[i];

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

    cout<<Solve(0);



}


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

#include<algorithm>

#include<string.h>

#define ll long long

#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

#define fr first

#define sc second

#define M_PI           3.14159265358979323846

using namespace std;

int n;

int Dp[200200];

int A[100100];



int main()

{

    Start;



    cin>>n;

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

        cin>>A[i];

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

        Dp[i]=1e9;

    Dp[0]=0;

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

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

        Dp[j]=min(Dp[j],Dp[i]+abs(A[j]-A[i]));

        cout<<Dp[n-1];



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

using namespace std;



#define int long long

#define INF 9223372036854775807

#define M_PI 3.14159265358979323846

#define double long double



int mod = INF;



int fastPow(int b, int e){int r = 1;while(e){if(e%2 == 1){r*=b;r%=mod;}b*=b;b%=mod;e/=2;}return r;}

int pgcd(int a, int b){ if(a%b == 0) return b; else return pgcd(b, a%b);}

int sign(int a){if(a < 0){ return -1;}if(a == 0) {return 0;}if(a > 0) {return 1;}}

bool isPrime(int a){if(a == 1) {return false;}int f = sqrt(a);for(int i = 2; i<=f; i++){if(a%i == 0){return false;}}return true;}

int toInt(string s){int tot = 0;for(int i = s.size()-1; i >= 0; i--){tot+=((s[i]-'0')%mod)*fastPow(10,i);tot%=mod;}return tot;}

string toString(int a){string s = "";while(a){s = (char)('0'+a%10) + s;a/=10;}return s;}



int n;

vector<int> v;



vector<int> memo(100009);



int dp(int index){

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

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

    if(index+2 == n){

        return memo[index] = dp(index+1)+abs(v[index+1]-v[index]);

    }else{

        return memo[index] = min(dp(index+1)+abs(v[index+1]-v[index]), dp(index+2)+abs(v[index+2]-v[index]));

    }

}



signed main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cin >> n;

    v.resize(n);

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

        cin >> v[i];

    }

    fill(memo.begin(), memo.end(), -1);

    cout << dp(0) << endl;

}


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

using namespace std;



#define int long long

#define INF 9223372036854775807

#define M_PI 3.14159265358979323846

#define double long double



int mod = INF;



int fastPow(int b, int e){int r = 1;while(e){if(e%2 == 1){r*=b;r%=mod;}b*=b;b%=mod;e/=2;}return r;}

int pgcd(int a, int b){ if(a%b == 0) return b; else return pgcd(b, a%b);}

int sign(int a){if(a < 0){ return -1;}if(a == 0) {return 0;}if(a > 0) {return 1;}}

bool isPrime(int a){if(a == 1) {return false;}int f = sqrt(a);for(int i = 2; i<=f; i++){if(a%i == 0){return false;}}return true;}

int toInt(string s){int tot = 0;for(int i = s.size()-1; i >= 0; i--){tot+=((s[i]-'0')%mod)*fastPow(10,i);tot%=mod;}return tot;}

string toString(int a){string s = "";while(a){s = (char)('0'+a%10) + s;a/=10;}return s;}



int n;

vector<int> v;



signed main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cin >> n;

    v.resize(n);

    vector<int> dp(n);

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

        cin >> v[i];

    }

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

        dp[i] = 0;

        if(i){

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

        }

        if(i > 1){

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

        }

    }

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

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



#include <algorithm>

#include <cmath>

#include <iostream>

#include <list>

#include <map>

#include <queue>

#include <stdio.h>

#include <string>

#include <vector>

#include <set>



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

using namespace std;

using ll = long long;

using P = pair<int, int>;

const double PI = 3.1415926535897932;



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

	if (a > b) {

		a = b;

		return true;

	}

	return false;

}



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

	if (a < b) {

		a = b;

		return true;

	}

	return false;

}



int N;

const long long INF = 1LL << 60;

long long h[100010];

long long dp[100010];



int main()

{

	int N; cin >> N;

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



	// 初期化 (最小化問題なので INF に初期化)

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



	// 初期条件

	dp[0] = 0;



	dp[0] = 0;

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

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

		if (i > 1) chmin(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.7840312275973622x):
#include <cstdlib>



#include <algorithm>

#include <cmath>

#include <iostream>

#include <list>

#include <map>

#include <queue>

#include <stdio.h>

#include <string>

#include <vector>

#include <set>



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

using namespace std;

using ll = long long;

using P = pair<int, int>;

const double PI = 3.1415926535897932;



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

	if (a > b) {

		a = b;

		return true;

	}

	return false;

}



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

	if (a < b) {

		a = b;

		return true;

	}

	return false;

}



int main()

{

	int N;

	cin >> N;

	const ll INF = (int)1e10;

	vector<ll> h(N, 0);

	rep(i, N) cin >> h[i];



	vector<ll> dp(N, INF);



	dp[0] = 0;

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

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

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

	}



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

	return 0;

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

using namespace std;



#define pb push_back

#define eb emplace_back

#define ff first

#define ss second

#define endl '\n'

typedef long long li;

const int N = 1e5 + 10;

int n;

int a[N];

int dp[N];

li solve(int i){



	if(i>=n-1)

		return 0;

	if(dp[i]!=-1)

		return dp[i];

	int p = abs(a[i]-a[i+1]) + solve(i+1);

	int q = INT_MAX;

	if(n-i>2){



		q = abs(a[i]-a[i+2]) + solve(i+2);

	}

	return dp[i] = min(p,q);

}

int main(){

	cin>>n;

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

		cin>>a[i];

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

	cout<<solve(0)<<endl;

}

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

using namespace std;



#define pb push_back

#define eb emplace_back

#define ff first

#define ss second

#define endl '\n'

typedef long long li;

const int N = 1e5 + 10;

int n;

int a[N];

int dp[N];

li solve(int i){



	if(i>=n-1)

		return 0;

	if(dp[i]!=-1)

		return dp[i];

	int p = abs(a[i]-a[i+1]) + solve(i+1);

	int q = INT_MAX;

	if(n-i>2){



		q = abs(a[i]-a[i+2]) + solve(i+2);

	}

	return dp[i] = min(p,q);

}

int main(){

	cin>>n;

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

		cin>>a[i];



	dp[0] = 0;

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



	for(int i = 2 ; 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]<<endl;

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

using namespace std;



#define pb push_back

#define eb emplace_back

#define ff first

#define ss second

#define endl '\n'

typedef long long li;

const int N = 1e5 + 10;

int n;

int a[N];

int dp[N];

li solve(int i){



	if(i>=n-1)

		return 0;

	if(dp[i]!=-1)

		return dp[i];

	int p = abs(a[i]-a[i+1]) + solve(i+1);

	int q = INT_MAX;

	if(n-i>2){



		q = abs(a[i]-a[i+2]) + solve(i+2);

	}

	return dp[i] = min(p,q);

}

int main(){

	cin>>n;

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

		cin>>a[i];

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

	cout<<solve(0)<<endl;

}

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

using namespace std;



#define pb push_back

#define eb emplace_back

#define ff first

#define ss second

#define endl '\n'

#define boost ios::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL);

typedef long long li;

const int INF = 1e9 + 12;

#define int long long

const int N = 1e5 + 10;

int dp[N];

signed main(){



	int n;

	cin>>n;

	int a[n];



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

		cin>>a[i];

	fill(dp,dp+n,INF);

	dp[0] = 0;

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



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

			if(j < n)

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

	}



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

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

using namespace std;



#define pb push_back

#define eb emplace_back

#define ff first

#define ss second

#define endl '\n'

typedef long long li;

const int N = 1e5 + 10;

int n;

int a[N];

int dp[N];

li solve(int i){



	if(i>=n-1)

		return 0;

	if(dp[i]!=-1)

		return dp[i];

	int p = abs(a[i]-a[i+1]) + solve(i+1);

	int q = INT_MAX;

	if(n-i>2){



		q = abs(a[i]-a[i+2]) + solve(i+2);

	}

	return dp[i] = min(p,q);

}

int main(){

	cin>>n;

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

		cin>>a[i];

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

	cout<<solve(0)<<endl;

}

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

using namespace std;

 

#define pb push_back

#define ff first

#define ss second

#define endl '\n'

#define fast ios::sync_with_stdio(false); cin.tie(NULL);

const double eps = 1e-6;







/////////////////////////////////////////////



void __print(int x) {cerr << x;}

void __print(long x) {cerr << x;}

void __print(long long x) {cerr << x;}

void __print(unsigned x) {cerr << x;}

void __print(unsigned long x) {cerr << x;}

void __print(unsigned long long x) {cerr << x;}

void __print(float x) {cerr << x;}

void __print(double x) {cerr << x;}

void __print(long double x) {cerr << x;}

void __print(char x) {cerr << '\'' << x << '\'';}

void __print(const char *x) {cerr << '\"' << x << '\"';}

void __print(const string &x) {cerr << '\"' << x << '\"';}

void __print(bool x) {cerr << (x ? "true" : "false");}



template<typename T, typename V>

void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}

template<typename T>

void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}

void _print() {cerr << "]\n";}

template <typename T, typename... V>

void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE

#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

#else

#define debug(x...)

#endif



////////////////////////////////



#define int long long







void solve(){



	int n;

	cin>>n;

	vector<int> a(n+2);

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

		cin>>a[i];



	int dp[n+2];



	dp[0] = 0;

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

		dp[i] = 1e12;

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



			if(i-j < 0)

				break;



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

		}

	}



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





}

signed main(){



    fast;

    int t = 1;

    //cin>>t;

    while(t--)

        solve();

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

using namespace std;

#define mod 1000000007

#define ll long long int

#define pb push_back

#define mp make_pair

#define fi first

#define se second

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

#define inf 9223372036854775807

#define mini 9223372036854775807

#include <ext/pb_ds/assoc_container.hpp> 

#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 

#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update>

pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};

pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

ll power(ll a,ll b)

{

	if(b==0)

		return 1;

	ll c=power(a,b/2);

	if(b%2==0)

		return ((c%mod)*(c%mod))%mod;

	else

		return ((((c%mod)*(c%mod))%mod)*a)%mod;

}

ll n;

ll a[200005];

ll dp[200005];

ll func(ll i)

{

	if(dp[i]!=-1)

		return dp[i];

	ll ans1=inf;

	ll ans2=inf;

	if(i==n-1)

		return 0;

	if(i+2<n)

		ans1=abs(a[i+2]-a[i])+func(i+2);

	if(i+1<n)

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

	dp[i]=min(ans1,ans2);

	return dp[i];

}

int main()

{

	boost

	cin>>n;

	ll i;

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

		dp[i]=-1;

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

		cin>>a[i];

	ll ans=func(0);

	cout<<ans<<endl;

	return 0;

}

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

#include <algorithm>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#define ass 1e18

#define MOD 1000000007

#define mp make_pair

#define pb push_back

#define fi first

#define se second

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

#define debug(x) cout << #x << ": " << x << endl;

#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;

#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;

using namespace std;

typedef long long int ll;

#include <ext/pb_ds/assoc_container.hpp> 

#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;   

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

ll arr[200005],dp[200005];

int main()

{

	boost

	ll n;

	cin>>n;

	ll i;

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

		cin>>arr[i];

	dp[0]=0;

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

	for(i=2; 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-1]<<endl;

	return 0;

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

#define INF 1000000000

using namespace std;

typedef long long ll;

int n,h[100005],men[100005];

int dp(int i){

  if(i==1)

    return 0;

  if(i<1) 

    return INF;

  if(men[i]!=-1)

    return men[i];

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

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

  return men[i]=min(a1,a2);

  }

int main(){

  cin>>n;

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

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

    cin>>h[i];

  }

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

  return(0);

}




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

using namespace std;

int main(){

  long long n,ans=0,dp[100000];

  int t[1000000];

  cin>>n;

  t[0]=10000000;

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

    cin>>t[i];

  }

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

    if(i!=2){

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

  }

    else

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

}

  cout<<dp[n]<<endl;

  return(0);

}
// Slower C++ solution:
// Created by Kshitij Anand NSIT

#include <bits/stdc++.h>





using namespace std;





#define int long long

#define pb push_back

#define P pair<int,int>

#define F first

#define S second

#define vi vector<int>

#define vc vector<char>

#define vb vector<bool>

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

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

#define mp(a, b) make_pair(a, b)

#define min3(a, b, c) min(min(a, b), c)

#define min4(a, b, c, d) min(min(a, b), min(c, d))

#define max3(a, b, c) max(max(a, b), c)

#define max4(a, b, c, d) max(max(a, b), max(c, d))

#define fill(arr,val) memset(arr,val,sizeof(arr))

#define db(x)  cout<<#x<<" : "<<x<<endl





const int N = 1000000007;



int dp[100009];



int func(int arr[] , int n , int curr){



	if(curr >= n){



		return 0;

	}



	if(curr == n-1)

		return 0;



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



	int ans = INT_MAX;



	if(curr+1 <n){



		int temp = func(arr , n , curr+1);



		if(temp!=-1)

			ans = min(ans , abs(arr[curr] - arr[curr+1])  + temp);

	}



	if(curr+2 <n){



		int temp = func(arr , n , curr+2);

		if(temp!=-1)

			ans = min(ans , abs(arr[curr] - arr[curr+2]) + temp);

	}



	if(ans == INT_MAX)

		ans = -1;



	dp[curr] = ans;

	return ans;



}



void solve(){



    int n,a,b,c, ans=0, count=0, sum=0;

    cin>>n;

    int arr[n];

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

      cin>>arr[i];

    }

    fill(dp , -1);

    ans = func(arr , n , 0);

    cout<<ans<<endl;

}



int32_t main() {

    ios_base::sync_with_stdio(false);

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

    

    

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

    {     

      solve();

    }



  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.7927408368856637x):
// Created by Kshitij Anand NSIT

#include <bits/stdc++.h>





using namespace std;





#define int long long

#define pb push_back

#define P pair<int,int>

#define F first

#define S second

#define vi vector<int>

#define vc vector<char>

#define vb vector<bool>

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

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

#define mp(a, b) make_pair(a, b)

#define min3(a, b, c) min(min(a, b), c)

#define min4(a, b, c, d) min(min(a, b), min(c, d))

#define max3(a, b, c) max(max(a, b), c)

#define max4(a, b, c, d) max(max(a, b), max(c, d))

#define fill(arr,val) memset(arr,val,sizeof(arr))

#define db(x)  cout<<#x<<" : "<<x<<endl





const int N = 1000000007;



int func(int arr[] ,  int n){



	int dp[n];



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

		dp[i] = INT_MAX;

	}

	dp[0] = 0;



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





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



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

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

	}



	return dp[n-1];



}



void solve(){



    int n,a,b,c, ans=0, count=0, sum=0;

    cin>>n;

    int arr[n];

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

      cin>>arr[i];

    }



    ans = func(arr , n);

    

    cout<<ans<<endl; 

}



int32_t main() {

    ios_base::sync_with_stdio(false);

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

    

    

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

    {     

      solve();

    }



  return 0;

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

using namespace std;

#define gcd(a,b) __gcd(a,b)

#define ll long long int

#define ld unsigned long long int

#define pi pair<ll,ll>

#define pb push_back

#define pf push_front

#define pu push

#define po pop

#define fi first

#define se second

#define mk make_pair

#define ve vector

#define lr(n) for(ll i=0;i<n;i++)

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



ll dp[100001];

ve<ll>ar(100001);



ll fun(ll n){

	if(n==0){

		return 0;

	}

	if(dp[n]==-1){

		dp[n]=abs(ar[n]-ar[n-1])+fun(n-1);

		if(n>1){

			dp[n]=min(dp[n],abs(ar[n]-ar[n-2])+fun(n-2));

		}

	}

	return dp[n];

}



	int main(){

		ios_base::sync_with_stdio(0);

		cin.tie(0);

		cout.tie(0);

		ll n;

		cin>>n;

		lr(n){

			cin>>ar[i];

		}

		lr(100001){

			dp[i]=-1;

		}

		cout << fun(n-1) << "\n";

		return 0;

	}

// Faster C++ solution for the same problem (measured speedup: 2.596516182786906x):
// #pragma GCC optimize("Ofast")

// #pragma GCC optimize ("unroll-loops")

// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

 

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

 

using namespace __gnu_pbds;

using namespace std;

#define gcd(a,b) __gcd(a,b)

#define ll long long int

#define ld unsigned long long int

#define pi pair<ll,ll>

#define pb push_back

#define pf push_front

#define pu push

#define po pop

#define fi first

#define se second

#define mk make_pair

#define ve vector

#define lr(n) for(ll i=0;i<n;i++)

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

#define be begin

#define sz(a) (ll)a.size()

#define INF 1e18

 

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// order_of_key(val): returns the number of values less than val

// find_by_order(k): returns an iterator to the kth largest element (0-based)

 

// ll mod=998244353;

// ll gcd(ll a, ll b){

//     if(a<b) swap(a,b);

//     if(b==0) return a;

//     return gcd(b,a%b);

// }

 

// ll fun(ll x, ll y){

//     ll rem=1;

//     while(y!=0){

//         if(y%2==1){

//             rem=(rem*x)%mod;

//         }

//         x=(x*x)%mod;

//         y/=2;

//     }

//     return rem;

// }



int main(){

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);

	ll n;

	cin>>n;

	ve<ll>ar(n+1);

	lr(n){

		cin>>ar[i+1];

	}

	ll dp[n+1]={0};

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

	for(ll i=n-2;i>=1;i--){

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

	}

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

	return 0;

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

using namespace std;



#define INF 0x3f3f3f3f

#define ii pair<int,int >

#define MAXN 100005



int memo[MAXN], a[MAXN];

int n;



int f(int idx){



	if(idx == n) return 0;

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

	int ans1 = INF, ans2 = INF;

	if(idx+1<=n) ans1 = f(idx+1) + abs(a[idx+1] - a[idx]);

	if(idx+2<=n) ans2 = f(idx+2) + abs(a[idx+2] - a[idx]);

	//cout << ans1 << " " << ans2 << endl;

	return memo[idx] = min(ans1, ans2);

}



int main(){



	while(cin >> n){

		//cout << n << endl;

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

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

		cout << f(1) << endl;

	}	



	return 0;

}

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

using namespace std;



#define ll long long

#define ii pair<int,int>

#define INF 1e9 + 7

#define vi vector<int>

#define add emplace_back





int main(){ios_base::sync_with_stdio(false);

    

    int n;

    cin >> n;

    vi a(n);

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

    

    vi dp(n, INF);

    dp[0] = 0;

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

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

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

        }

    }

    

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



    return 0;

}