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

using namespace std;

int N;

vector<int>v;

int dp[100000+1];

int culc(int i){

    if(i == N)return 0;

    if(i == 0){

        dp[i]  = 0;

    }else if(i == 1){

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

    }

    else {

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

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

    }

    return culc(i+1);

}

int main(){

    cin>>N;

    v.resize(N);

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

    memset(dp,0,sizeof dp);

    culc(0);

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

	return 0 ;

}


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

using namespace std;



int main(){

    int N;cin>>N;

    vector<int>v(N);

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

    int dp[N+1];

    memset(dp,0,sizeof dp);

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

        if(i == 0){

            dp[i] = 0;

        }

        else if(i == 1){

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

        }

        else {

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

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

        }

     //   cout<<i<< " "<<dp[i]<<endl;

    }

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

	return 0 ;

}


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

using namespace std;

#define I INT32_MAX

#define IM INT_MIN

#define MOD 1000000007

#define ll long long

#define lli long long int

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

#define repk(i,k,n) for (int i = k; i <= n; i++)

#define repr(i,k,n) for (int i = k; i >= n; i--)

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

typedef vector<int> vi;

typedef set<int> si;

ll dp[100005];

ll arr[100005];

ll n;



ll mincost(ll i) {

	// int n = sizeof(arr);

	if (i == n - 1) {

		return 0;



	}

	if (i >= n) return INT_MAX;



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

		return dp[i];

	}

	ll onejump = mincost(i + 1) + abs(arr[i] - arr[i + 1]);

	ll twojump = INT_MAX;

	if (i + 2 < n) {

		twojump = mincost(i + 2) + abs(arr[i] - arr[i + 2]);



	}

	return dp[i] = min(onejump, twojump);



}



void solve() {

	// int n;

	cin >> n;



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

	rep(i, n) {

		cin >> arr[i];

	}

	cout << mincost(0);

}



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0);



	int t = 1;

	// cin >> t;

	while (t--)

		solve();



	return 0;



}










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

using namespace std;

#define I INT32_MAX

#define IM INT_MIN

#define MOD 1000000007

#define ll long long

#define lli long long int

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

#define repk(i,k,n) for (int i = k; i <= n; i++)

#define repr(i,k,n) for (int i = k; i >= n; i--)

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

typedef vector<int> vi;

typedef set<int> si;





void solve() {

	ll n;

	cin >> n;

	std::vector<ll> arr(n + 1);

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

	{

		cin >> arr[i];

	}

	std::vector<ll> dp(n + 1);

	dp[0] = 0;

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

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

	{

		ll onejump = dp[i - 1] + abs(arr[i] - arr[i - 1]);

		ll twojump  = dp[i - 2] + abs(arr[i] - arr[i - 2]);

		dp[i] = min(onejump, twojump);

	}

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



}



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0);



	int t = 1;

	// cin >> t;

	while (t--)

		solve();



}










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



using namespace std;



const int N = 100001;

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



int solve(int i) {

    if (i == 1) {

        return 0;

    }

    int& ans = dp[i];

    if (ans != -1) {

        return ans;

    }

    ans = 1e9;

    if (i > 1) {

        ans = solve(i - 1) + abs(h[i] - h[i - 1]);

    }

    if (i > 2) {

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

    }

    return ans;

}



int main() {

    cin >> n;

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

        cin >> h[i];

    }

    memset(dp, -1, sizeof dp);

    cout << solve(n);

    return 0;

}


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



using namespace std;



const int N = 1e5 + 1;

int dp[N], h[N];



int main() {

    int n;

    cin >> n;

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

        cin >> h[i];

    }

    dp[1] = 0;

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

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

    return 0;

}


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

using namespace std;

typedef long long ll;

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

// Welcome to my source code!



const ll INF = 1LL<<60;



int main() {

    int n;

    cin >> n;

    ll h[n];

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

    ll dp[101000];

    for (int i = 0; i < 101000; i++) dp[i] = 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;

}

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

using namespace std;

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

typedef long long ll;

// Welcome to my source code!



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



const int INF = 1e9;



int main() {

    int n;

    cin >> n;

    int h[n], dp[n];

    for (int i = 0; i < n; i++) { cin >> h[i]; dp[i] = 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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);



}


// Optimized solution to the same problem (faster):
#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];



}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}




// Optimized solution to the same problem (faster):
#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);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
// 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;

}


// Optimized solution to the same problem (faster):
// 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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

	}

// Optimized solution to the same problem (faster):
// #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;

}

// Fastest known solution for this problem: