stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}

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

}


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



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

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

// #include <ext/pb_ds/detail/standard_policies.hpp>



using namespace std;

// using namespace __gnu_pbds;



#define int ll

#define endl "\n"

#define pb push_back

#define mp make_pair

#define ff first

#define ss second

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

#define vi vector<int>

#define pii pair<int,int>

#define For(i,s,e) for (ll i=(s); i<(e); i++)

#define MAX 500005

#define initialize(arr,elem) memset(arr,elem,sizeof(arr))



typedef long long ll;

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

int memo[MAX], arr[MAX];

int k = 2;

int solve(int i){

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

	if (i==1) return memo[i] = 0;

	int dp = 100000000000000;

	for (int j =i-1; j>=i-k && j>0;j--){

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

	}

	return memo[i] = dp;

}

signed main()

{

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);

		

	// #ifndef ONLINE_JUDGE

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

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

	// #endif



	int n;

	cin>>n;

	initialize(memo,-1);

	For(i,1,n+1) cin>>arr[i];

	cout<<solve(n)<<endl;

	// For(i,1,3) cout<<memo[i]<<" ";







	return 0;

}


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

 

using namespace std;



typedef long long ll;

#define int ll

#define pb push_back

const int INF = 1e18;



signed main(){



	ios_base::sync_with_stdio(false);

	cin.tie(0);



	int n; cin>>n;

	int cost[n+1];

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

		cin>>cost[i];



	vector<int> dp(n+1,INF);

	dp[1] = 0;



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

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

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

	}



	cout<<dp[n];

	return 0;

}

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

using namespace std;

const int maxn=100005;

int a[maxn];

int dp[maxn];

int mincost(int n)

{

    if(n==1)

        return 0;

    else if(n==2)

        return abs(a[n]-a[1]);

    else if(dp[n]!=-1)

        return dp[n];

    else

        return dp[n]=min(mincost(n-1)+abs(a[n]-a[n-1]),mincost(n-2)+abs(a[n]-a[n-2]));

}

int main()

{

    int n;

    cin>>n;

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

        cin>>a[i];

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

        cout<<mincost(n)<<endl;

    return 0;

}


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

using namespace std;

const int mod=1000000007;

const int maxn=100005;

int dp[maxn],a[maxn];

int main()

{

    int n;

    cin>>n;

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

        cin>>a[i];

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

        dp[i]=mod;

    dp[0]=0;

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

    {

        if(i+1<n)

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

        if(i+2<n)

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

    }

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

    return 0;

}




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

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

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

#define fore(i,a) for(auto &i:a)

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

//#pragma GCC optimize ("-O3")

using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }

typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

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

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

const int MAX_N = 100010;



int N;

vector<int> h;



int dp[MAX_N];



int Solve(int pos)

{

    if (dp[pos] >= 0) return dp[pos];



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

    if (pos >= N) return inf;



    return dp[pos] = min(abs(h[pos] - h[pos + 1]) + Solve(pos + 1), abs(h[pos] - h[pos + 2]) + Solve(pos + 2));

}



void _main()

{

    cin >> N;

    h.resize(N);

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

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

    cout << Solve(0) << endl;

}


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

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

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

#define fore(i,a) for(auto &i:a)

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

//#pragma GCC optimize ("-O3")

using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }

typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

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

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

const int MAX_N = 100010;



int N;

vector<int> h;



int dp[MAX_N];



void _main()

{

    cin >> N;

    h.resize(N);

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

    rep(i, 0, N + 1) dp[i] = inf;

    dp[0] = 0;

    rep(i, 0, N)

    {

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

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

    }

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

}


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

using namespace std;

int dp[100100];

int v[100100];

int n;



int run(int i) {

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

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

	if(i == n - 2) return dp[i] = abs(v[i] - v[i + 1]);



	dp[i + 2] = run(i + 2);

	dp[i + 1] = run(i + 1);

	

	return dp[i] = min(

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

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

	);

}



int main() {

	cin>>n;

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

		cin>>v[i];

	}

	memset(dp, -1, sizeof dp);

	

	cout<< run(0) <<endl;

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

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

	} cout<<endl;*/

	

	return 0;

}

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

using namespace std;

const int N = 1e5 + 10;

int n;

int v[N];

int dp[N];

int main() {

	scanf("%d", &n);

	for(int i = 0; i < n; ++i) scanf("%d", &v[i]);

	for(int i = n - 2; i >= 0; --i) {

		if(i == n - 2) {

			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]

			);

		}

	}

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

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <math.h>

#include <string.h>

#include <vector>

#include <algorithm>

#include <stack>



using namespace std;

typedef long long ll;



int N;

int h[100005];



int abs(int i){

    if(i>=0) return i;

    return -i;

}



int min(int x,int y){

    if(x>=y) return y;

    return x;

}



int memo[100005];



int dp(int i){

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

    if(i==0){

        memo[0]=0;

        return 0;

    }

    if(i==1){

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

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

    }

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

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

}



int main(){

    for(int j=0;j<=100004;j++){

        memo[j]=-1;

    }

    int i;

    cin>>N;

    

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

        cin>>h[i];

    }

    cout<<dp(N-1)<<endl;

}




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

using namespace std;

typedef long long ll;

//#include <boost/multiprecision/cpp_ll.hpp>

//typedef boost::multiprecision::cpp_ll ll;

typedef long double dd;

#define i_7 (ll)(1E9+7)

//#define i_7 998244353

#define i_5 i_7-2

ll mod(ll a){

    ll c=a%i_7;

    if(c>=0)return c;

    return c+i_7;

}

typedef pair<ll,ll> l_l;

ll inf=(ll)1E16;

#define rep(i,l,r) for(ll i=l;i<=r;i++)

#define pb push_back

ll max(ll a,ll b){if(a<b)return b;else return a;}

ll min(ll a,ll b){if(a>b)return b;else return a;}

void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);

void Min(ll &pos,ll val){pos=min(pos,val);}

void Add(ll &pos,ll val){pos=mod(pos+val);}

dd EPS=1E-9;

string alp="abcdefghijklmnopqrstuvwxyz";

#define endl "\n"

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







int main(){fastio

    ll n;cin>>n;

    ll h[n];rep(i,0,n-1)cin>>h[i];

    ll dp[n];

    dp[0]=0;

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

    rep(i,2,n-1){

        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),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 ll long long

#define f(i, x, n) for(int i = x; i < (int)(n); ++i)

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

int const N = 1e5 + 2;

int n, arr[100010], ans, dp[100010];



int calc(int x){

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

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

	int a, b;

	a = calc(x + 1);

	b = x + 2 <= n - 1 ? calc(x + 2) : -1;

	if (b == -1)return dp[x] = a + abs(arr[x + 1] - arr[x]);

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

}



int main(){

	speed

	cin>>n;

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

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

	cout<<calc(0);



}

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

using namespace std;

#define ll long long

#define f(i, x, n) for(int i = x; i < (int)(n); ++i)

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

int const N = 1e5 + 2;

int n, arr[100010], ans, dp[100010];



int main(){

	speed

	cin>>n;

	f(i, 0, n)cin >> arr[i];

	dp[n - 1] = 0;

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

	for (int i = n - 3; i >= 0; i--){

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

	}

	cout << dp[0] << endl;



}

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

using namespace std;

typedef long long int ll;

#define INF 1LL << 60;



int main() {

  int n;

  cin >> n;

  int h[100010];

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



  ll dp[100010];

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



  dp[0] = 0;

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

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

    dp[i + 2] = min(dp[i + 2], dp[i] + 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;



int main() {

  // 入力

  int n;

  cin >> n;

  vector<int> v(n);

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

    cin >> v[i];

  }



  // 貰うDPをする

  vector<int> dp(n);

  dp[0] = 0;

  for (int i = 1; i < n; i++) { // 0より左に行かないように、場合分け

    if (i - 2 >= 0) {  // 1つ前と2つ前を比較する

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

    } else {  // 1つ前から取ってくる

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

    }

  }



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

}


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

#define ll long long

using namespace std;



ll n, dp[1000000], vet[1000000];



ll solve(int i) {

    if(dp[i] != -1)

        return dp[i];

    if(i == n-1)

        return 0;

    if(i > n-1)

        return 99999999;



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

    return dp[i];

}

int main() {

    cin >> n;

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

    memset(dp, -1, sizeof dp);

    solve(0);

    cout << dp[0] << endl;

}


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

#define pb push_back

#define INF 0x3f3f3f3

#define LINF 0x3f3f3f3f3f3f3f

#define MAXN int(2*(10e5+3))

#define fim '\n'

#define ll long long

#define f first

#define s second

#define debug(x) cout << "DEBUG " << x << endl

using namespace std;

typedef pair<int, int> pii;



int vet[MAXN], dp[MAXN];

int n, c, k;





int main(){

	cin.tie(NULL);

	cout.tie(NULL);

	ios::sync_with_stdio(false);

	int n;

	cin >> n;

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

		cin >> vet[i];

		

	dp[1] = 0;

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

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

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

	}

	cout << dp[n] << endl;



}




// Fastest known solution for this problem:
// Original C++ solution (slower):
/*

	author: Ibrahim-Elsayed (Codeforces Handle)

	date: 8/28/2020

*/



#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pb push_back

const double PI = acos(-1);

const int MOD = 1000000007;



const int mxN = 1e5;

int n;

int dp[mxN+1];

int arr[mxN+1];



int go(int i) { // min cost starting from stone i to reach stone n;

	if(i == n) {

		return 0;

	}

	if(i > n) {

		return int(1000000025);

	}

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

		return dp[i];

	}

	int c1 = 1000000025, c2 = 1000000025;

	if(i+1 <= n) c1 = go(i+1) + abs(arr[i] - arr[i+1]);

	if(i+2 <= n) c2 = go(i+2) + abs(arr[i] - arr[i+2]);

	int ans = min(c1, c2);

	return dp[i] = ans;

}



int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);



	cin >> n;

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

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

	cout << go(1);



	return 0;

}


// Optimized solution to the same problem (faster):
//#pragma GCC optimize("Ofast")

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

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

#include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define bit(i) (1<<(i))

#define set(mask,i) (mask |= (1<<(i)))

#define get(mask,i) (mask & (1<<(i)))

typedef long long ll;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const double PI = acos(-1);

const ll INF64 = (ll)1e15;

const int INF32 = (int)1e9;

const int64_t md = (int64_t)((int64_t)1e9 + 7);

 

int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);



	int n;

	cin >> n;

	int arr[n];

	for(int& el : arr) cin >> el;

	int dp[n + 1];

	for(int& el : dp) el = INF32;

	dp[0] = 0;

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

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

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

	}

	cout << dp[n-1];



	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <cstdlib>

using namespace std;

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 long long INF = 1LL << 60;



// 入力

int N;

long long h[100010];



// メモ用の DP テーブル

long long dp[100010];



long long rec(int i) {

    // DP の値が更新されていたらそのままリターン

    if (dp[i] < INF) return dp[i];



    // 足場 0 のコストは 0

    if (i == 0) return 0;



    // i-1, i-2 それぞれ試す

    long long res = INF;

    chmin(res, rec(i-1) + abs(h[i] - h[i - 1])); // 足場 i-1 から来た場合

    if (i > 1) chmin(res, rec(i-2) + abs(h[i] - h[i - 2])); // 足場 i-2 から来た場合



    // 結果をメモしながら、返す

      return dp[i] = res;

}



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;



    // 答え

    cout << rec(N-1) << endl;

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<cmath>

using namespace std;



const int INF = 1 << 30;

int h[100000];

int dp[100000];



// i番目の足場に行くまでの最小コストを返す関数

int rec(int i) {

	// メモされていたらメモされた値を返す

	if (dp[i] < INF) return dp[i];



	// i = 0 なら明示的に値を返す

	if (i == 0) return 0;



	// 再帰的にrecを呼び出す

	int ret = min(

		rec(i-1) + abs(h[i] - h[i-1]),

		i != 1 ? rec(i-2) + abs(h[i] - h[i-2]) : INF

	);



	// 結果をメモする

	dp[i] = ret;

	return ret;

}



int main() {

	// 入力を受け取る

	int n;

	cin >> n;

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

		cin >> h[i];

		// メモを初期化する

		dp[i] = INF;

	}



	cout << rec(n-1) << endl;

}


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



using namespace std;



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

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

#define pb push_back

#define endl '\n'

#define snd second

#define fst first

#define fastio cin.tie(NULL),cout.sync_with_stdio(true)



typedef long long int ll;

typedef unsigned long long int ull;

typedef vector <int> vi;

typedef pair <ll,int> ii;

typedef pair <ii,int> iii;



const int mod = 1e9 + 7;

const int N = 200005;



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



int solve(int i){

    if(dp[i] != -1)

        return dp[i];

    int ans = 0;

    if(i + 1 < n)

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

    if(i + 2 < n)

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

    return dp[i] = ans;

}



int main(){

	fastio;

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

    cin >> n;

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

        cin >> v[i];

    cout << solve(0) << endl;

	return 0;

}


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



using namespace std;



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

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

#define pb push_back

#define endl '\n'

#define snd second

#define fst first

#define fastio cin.tie(NULL),cout.sync_with_stdio(true)



typedef long long int ll;

typedef unsigned long long int ull;

typedef vector <int> vi;

typedef pair <ll,int> ii;

typedef pair <ii,int> iii;



const int mod = 1e9 + 7;

const int N = 200005;



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



int main(){

	fastio;

    cin >> n;

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

        cin >> v[i];

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

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

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

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

    }

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

	return 0;

}


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

using namespace std;

#define ll long long

#define fo(p,n) for(int i=p;i<n;i++)

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

#define endl "\n"

#define mp make_pair

#define pb push_back

#define M 1000000007

ll mod(ll x){

return ((x%M + M)%M);

}

ll add(ll a,ll b){

return mod(mod(a)+mod(b));

}

ll mul(ll a,ll b){

return mod(mod(a)*mod(b));

}



// ....................................................................................

int dp[100001];

int fun(int a[],int i){

    if(i==0)

    return 0;

    if(dp[i]!=-1)

    return dp[i];



   if(i-2>=0){

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

   }

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

}

int main()

{

    FIO

    ll t;

    t=1;

    // cin>>t;

    while(t--)

    {

     int n;

     cin>>n;

     int a[n];

     fo(0,n)

     cin>>a[i];

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

     dp[0]=0;

     cout<<fun(a,n-1)<<endl;

    }

}

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

using namespace std;

#define ll long long

#define fo(p,n) for(int i=p;i<n;i++)

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

#define endl "\n"

#define mp make_pair

#define pb push_back

#define M 1000000007

ll mod(ll x){

return ((x%M + M)%M);

}

ll add(ll a,ll b){

return mod(mod(a)+mod(b));

}

ll mul(ll a,ll b){

return mod(mod(a)*mod(b));

}



// ....................................................................................



int main()

{

    FIO

    ll t;

    t=1;

    // cin>>t;

    while(t--)

    {

     int n;

     cin>>n;

     int a[n];

     fo(0,n)

     cin>>a[i];

     int dp[n];

     fo(0,n)

     dp[i]=INT_MAX;

     dp[0]=0;

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

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

         if(i-2>=0)

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

     }

     cout<<dp[n-1];

    }

}

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

using namespace std;



typedef vector< long long > vi;

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

#define pb push_back

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

#define ll long long



ll dp[200000];

ll cost(ll n, ll h[]);



int main(void)

{

    fill_n(dp, 200000, -1);

    ll n;

    cin >> n;

    ll h[n];

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

        cin >> h[i];

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

    dp[1] = 0;

    cout << cost(n, h) << "\n";

}



ll cost(ll n, ll h[])

{

    if (n == 2)

        return dp[2];

    if (n == 1)

        return dp[1];



    if (dp[n] == -1)

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



    return dp[n];

}

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

using namespace std;



typedef vector <long long> vi;

typedef vector <vi> vvi;

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

#define pb push_back

#define mp make_pair

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

#define rall(c) (c).rbegin(), (c).rend()

#define ll long long



int main(void)

{

    ll n;

    cin >> n;

    ll h[n];

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

        cin >> h[i];

    ll dp[n];



    dp[0] = 0;

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

}


// Fastest known solution for this problem: