stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 4.993410238867794x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.4006431014252516x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.395045110708243x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.4075013683993631x):
#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;

}
// Slower C++ solution:
#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;

}




// Faster C++ solution for the same problem (measured speedup: 1.3742564315543044x):
#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;

}
// Slower C++ solution:
#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);



}

// Faster C++ solution for the same problem (measured speedup: 1.3947415278731767x):
#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;



}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 2.98237562922591x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 9.269736778283084x):
#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;



}
// Slower C++ solution:
/*

	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;

}


// Faster C++ solution for the same problem (measured speedup: 1.3832596302053168x):
/*

	author: Ibrahim-Elsayed (Codeforces Handle)

	date: 9/17/2020

*/

//#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

typedef long long ll;

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

const double PI = acos(-1);



int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);



	int n;

	cin >> n;

	vector<int> arr(n);

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

	vector<int64_t> dp(n); // dp[i] is minimum total cost to reach the end starting from idx i;

	dp[n - 1] = 0;

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

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

		if(i+2 < n) {

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

		}

	}

	cout << dp[0];



	return 0;

}
// Slower C++ solution:
/*

	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;

}


// Faster C++ solution for the same problem (measured speedup: 1.384676918885832x):
//#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.8053503335388523x):
#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;

}
// Slower C++ solution:
#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;

}

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

using namespace std;

#define INF (1 << 30)



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 = 0; i < n; i++) {

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

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

	}

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

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.8022234647218314x):
#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;

}
// Slower C++ solution:
#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;

    }

}

// Faster C++ solution for the same problem (measured speedup: 1.397286137007083x):
#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];

    }

}