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

}

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

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

}

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

#define ld long double

typedef vector <ll> vi;                 // Vector of long long

typedef vector <vi> vvi;                // Vector of vi

typedef vector <pair<ll,ll>> ii;        // Vector of pairs

#define ff first                        // For pairs

#define ss second                       // For pairs

#define sz(a) int((a).size())           // Function to determine size of any container

#define pb push_back                    // Pushback to vector

#define mp make_pair                    // Makes pairs to be stored as pair

#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting

// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()

// order_of_key returns number of elements less that parameter. If element exists, that order is its index

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

#define INF (ll)(1e10)

#define MAX (ll)(1e5 + 5)



ll dp[MAX];

ll n;

vi h;



ll solve(ll i)

{

    if (i < 0)

        return INF;



    if (dp[i] == -1)

        dp[i] = min(solve(i - 1) + llabs(h[i] - h[i - 1]), solve(i - 2) + llabs(h[i] - h[i - 2]));

    return dp[i];

}



int main(void)

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    cin >> n;

    h.resize(n);



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

        cin >> h[i];



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



    dp[0] = 0;

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



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

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

}

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

#define ld long double

typedef vector <ll> vi;                 // Vector of long long

typedef vector <vi> vvi;                // Vector of vi

typedef vector <pair<ll,ll>> ii;        // Vector of pairs

#define ff first                        // For pairs

#define ss second                       // For pairs

#define sz(a) int((a).size())           // Function to determine size of any container

#define pb push_back                    // Pushback to vector

#define mp make_pair                    // Makes pairs to be stored as pair

#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting

// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()

// order_of_key returns number of elements less that parameter. If element exists, that order is its index

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

#define MAX (ll)(1e5 + 5)

ll dp[MAX];



int main(void)

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    ll n;

    cin >> n;

    ll h[n];

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

        cin >> h[i];



    dp[0] = 0;

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

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

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

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

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

#include <vector>

#include <cstdlib>

using namespace std;

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

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



const long long INF = 1LL << 60;



// 入力

int N;

long long h[100010];



// DP テーブル

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;



    // ループ

    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;

}

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

using namespace std;

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



int main() {

    const int INF = 1e9;

    int n;

    cin >> n;

    vector<int> h(n);

    REP(i, n) cin >> h[i];

    vector<int> dp(n, INF);

    dp[0] = 0;

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

        int cost1 = abs(h[i] - h[i - 1]);

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

        if(i > 1) {

            int cost2 = abs(h[i] - h[i - 2]);

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

        }

    }

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

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

using namespace std;



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

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}



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

    if (a < b) {

        a = b;

        return true;

    }

    return false;

}



const long long INF = 1LL << 60;

long long h[100010];

long long dp[100010];





long long rec(int i) {

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

    if (dp[i] < INF) {

        return dp[i];

    }

    // 足場0のコストは0

    if (i == 0) {

        return 0;

    }

    long long res = INF;

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

    if (i > 1) {

        chainge_min(res, rec(i - 2) + abs(h[i] - h[i -2]));

    }

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

    return dp[i] = res;

}



int main(void) {

    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;

    return 0;

}

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

#include <cmath>

#include <vector>

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

using namespace std;

const int INF = 1 << 30;



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

    if (a > b) a = b; return true;

    return false;

}



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);



    int n;

    cin >> n;



    vector<int> h(n);

    REP(i, n) cin >> h[i];



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



    dp[0] = 0;

    REP(i, 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] << '\n';

    return 0;

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

using namespace std;

const int MAX = 1e5 + 10;

int dp[MAX];

int a[MAX];

int n;

const int inf = 0x3f3f3f3f;



int run(int idx) {

	if(idx >= n)return inf;

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

	int &res = dp[idx];

	if(res != -1)return res;

	res = inf;

	if(idx+1 < n)res = min(res, abs(a[idx] - a[idx+1]) + run(idx+1));

	if(idx+2 < n)res = min(res, abs(a[idx] - a[idx+2]) + run(idx+2));

	return res;

}



int main() {

	scanf("%d", &n);

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

		scanf("%d", a+i);

	}

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

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





	return 0;

}

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

using namespace std;

const int MAX = 1e5 + 10;

int dp[MAX];

int a[MAX];

int n;

const int inf = 0x3f3f3f3f;





int main() {

	scanf("%d", &n);

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

		scanf("%d", a+i);

	}

	dp[n-1] = 0;

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

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

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

	}

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



	return 0;

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

using namespace std;



typedef long long ll;



const int N = 1 * 1e5 + 10;



ll res;

ll a[N];

ll dp[N];



ll go(ll idx, ll n){

	if(idx == n)	return 0;

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

	ll xx = INT_MAX, yy = INT_MAX;

	xx = abs(a[idx] - a[idx + 1]) + go(idx + 1, n);

	if(idx <= n - 2)

	yy = abs(a[idx] - a[idx + 2]) + go(idx + 2, n);

	return dp[idx] = min(xx, yy);

}



void solve() {

	ll n;

	cin >> n;

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

		cin >> a[i];

	}

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

	cout << go(1, n);

}



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

  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

  ll t = 1;

  //cin >> t;

  while(t--){

    solve();

  }

    return 0;

}

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

using namespace std;



typedef long long ll;



const int N = 1 * 1e5 + 10;

const ll inf = 1 * 1e9 + 10;



ll res;

ll a[N];



void solve() {

	ll  n;

	cin >> n;

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

		cin >> a[i];

	}

	std::vector<ll> dp(n, inf);

	dp[0] = 0;



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



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

		for(auto j : {i - 1, i - 2}){

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

		}

	}

	cout << dp[n - 1];



}



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

  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

  ll t = 1;

  //cin >> t;

  while(t--){

    solve();

  }

    return 0;

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

using namespace std;



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

#define reps(i,n) for(int i=1; i<=(n); i++)

#define pii pair<int,int>

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

#define gsort(x,n) sort(x,x+n,greater<int>())

#define rv(s) reverse((s).begin(),(s).end())

//#define abs(a) llabs(a)

//#define int long long

#define setout(n,x) setw(n) << setfill(x)

#define Fixed fixed << setprecision(10)

#define INF 1000000000;



int x[1000010],mem[1000010];

int dp(int i){

    if(i == 1) return 0;

    if(i < 1 ) return INF;

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



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

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

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

}



int main(){

  

  cin.tie(0);

  ios::sync_with_stdio(false);



  int n;

  cin >> n;



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

 

  reps(i,n) cin>>x[i];



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

}

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

using namespace std;



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

#define reps(i,n) for(int i=1; i<=(n); i++)

#define pii pair<int,int>

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

#define gsort(x,n) sort(x,x+n,greater<int>())

#define rv(s) reverse((s).begin(),(s).end())

#define abs(a) llabs(a)

#define int int64_t

#define setout(n,x) setw(n) << setfill(x)

#define Fixed fixed << setprecision(10)

#define INF 1000000000;

     

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



signed dp(int i){

    if(i == 1) return 0;

    if(i < 1) return INF;

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



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

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

    

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

}



signed main(){

    int n;

    cin >> n;

    

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



    reps(i,n){

        cin >> h[i];

    }



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

    return 0;

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

using namespace std;



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

#define reps(i,n) for(int i=1; i<=(n); i++)

#define pii pair<int,int>

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

#define gsort(x,n) sort(x,x+n,greater<int>())

#define rv(s) reverse((s).begin(),(s).end())

//#define abs(a) llabs(a)

//#define int long long

#define setout(n,x) setw(n) << setfill(x)

#define Fixed fixed << setprecision(10)

#define INF 1000000000;



int x[1000010],mem[1000010];

int dp(int i){

    if(i == 1) return 0;

    if(i < 1 ) return INF;

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



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

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

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

}



int main(){

  

  cin.tie(0);

  ios::sync_with_stdio(false);



  int n;

  cin >> n;



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

 

  reps(i,n) cin>>x[i];



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

}

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

using namespace std;

 

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

#define reps(i,n) for(int i=1; i<=(n); i++)

#define pii pair<int,int>

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

#define gsort(x,n) sort(x,x+n,greater<int>())

#define rv(s) reverse((s).begin(),(s).end())

#define abs(a) llabs(a)

#define int int64_t

#define setout(n,x) setw(n) << setfill(x)

#define Fixed fixed << setprecision(10)

#define INF 1000000000;

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

 

signed dp(int i){

if(i == 1) return 0;

if(i < 1) return INF;

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

 

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

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

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

}

 

signed main(){

int n;

cin >> n;

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

 

reps(i,n){

cin >> h[i];

}

 

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

return 0;

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

using namespace std;



constexpr int MAX_N = 100100;

constexpr long long INF = 1e18;



int main() {

    int n;

    cin >> n;

    vector<long long> h(n);

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

        cin >> h[i];

    }

    

    long long dp[MAX_N];

    fill(dp, dp + MAX_N, INF);

    dp[0] = 0;

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

    

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

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

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

    }

    

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

    return 0;

}

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

using namespace std;



template<class J>

struct semi_lattice {

	const J join;

	semi_lattice (J join) : join(join) { }

	template<class T> bool operator() (T &a, const T &b) {

		if (not join(a, b)) { a = b; return true; }

		return false;

	}

};



template<class J>

semi_lattice<J> make_sl(J join) {

	return semi_lattice<J>(join);

}



int main() {

	int n;

	cin >> n;

	vector<int> h(n);

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

		cin >> h[i];

	}

	

	auto chmin = make_sl(less<int>());

	

	vector<int> dp(n, (1 << 30));

	dp[0] = 0;

	

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

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

			if (i + j < n) {

				int cost = abs(h[i] - h[i + j]);

				chmin(dp[i + j], dp[i] + cost);

			}

		}

	}

	

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

	

	return 0;

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

#include <string>

#include <cstdlib>

#include <vector>

#include <sstream>

#include <set>

#include <tuple>

#include <algorithm>

#include <memory>

#include <numeric>

#include <queue>

#include <functional>

#include <cmath>

#include <cstring>

#include <map>



using namespace std;



typedef long long ll;

typedef unsigned long long ull;

typedef pair<ll, ll> P;

typedef pair<ll, P> PP;



ll N;

vector<ll> h;



ll memo[100001];



ll func(ll pos)

{

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



	if (pos == 0) return 0;

	if (pos == 1) return abs(h[1] - h[0]);



	memo[pos] = min(func(pos - 1) + abs(h[pos-1] - h[pos]), func(pos - 2) + abs(h[pos - 2] - h[pos]));



	return memo[pos];

}



int main()

{

	cin.tie(0);

	ios::sync_with_stdio(false);



	cin >> N;

	h.resize(N);



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

	for (auto& e : memo) e = -1;



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



	//system("pause");

}


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

#include <string>

#include <cstdlib>

#include <vector>

#include <sstream>

#include <set>

#include <tuple>

#include <algorithm>

#include <memory>

#include <numeric>

#include <queue>

#include <functional>

#include <cmath>

#include <cstring>

#include <map>



using namespace std;



typedef long long ll;

typedef unsigned long long ull;

typedef pair<ll, ll> P;

typedef pair<ll, P> PP;



ll N;

vector<ll> h;



int main()

{

	cin.tie(0);

	ios::sync_with_stdio(false);



	cin >> N;

	h.resize(N);



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



	vector<ll> dp(N);

	dp[0] = 0;

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



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

	{

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

	}



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



	//system("pause");

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

#include <cstdio>

#include <cstring>

#include <cmath>

#include <cstring>

#include <chrono>

#include <complex>

#define endl "\n"

#define ll long long int

#define vi vector<int>

#define vll vector<ll>

#define vvi vector < vi >

#define pii pair<int,int>

#define pll pair<long long, long long>

#define mod 1000000007

#define inf 1000000000000000001;

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

#define mp(x,y) make_pair(x,y)

#define mem(a,val) memset(a,val,sizeof(a))

#define eb emplace_back

  #define pb push_back

#define f first

#define s second

  #define MAXN 100005

using namespace std;

int n;

int arr[MAXN],dp[MAXN];

int solve(int i){

	if(i>=n) {

		return 1e9;

	}

	if(i==n-1) {

		return 0;

	}

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



	int cost2=abs(arr[i+2]-arr[i]);

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

	return dp[i]=min(cost1+solve(i+1),cost2+solve(i+2));

}

int main()

{

	std::ios::sync_with_stdio(false);



	cin>>n;

	mem(dp,-1);

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

	cout<<solve(0)<<endl;



	return 0;

}


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

#include <cstdio>

#include <cstring>

#include <cmath>

#include <cstring>

#include <chrono>

#include <complex>

#define endl "\n"

#define ll long long int

#define vi vector<int>

#define vll vector<ll>

#define vvi vector < vi >

#define pii pair<int,int>

#define pll pair<long long, long long>

#define mod 1000000007

#define inf 1000000000000000001;

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

#define mp(x,y) make_pair(x,y)

#define mem(a,val) memset(a,val,sizeof(a))

#define eb emplace_back

  #define pb push_back

#define f first

#define s second

  #define MAXN 100005

using namespace std;

int n;

int arr[MAXN],dp[MAXN];

/*

   int solve(int i){

        if(i>=n) {

                return 1e9;

        }

        if(i==n-1) {

                return 0;

        }

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



        int cost2=abs(arr[i+2]-arr[i]);

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

        return dp[i]=min(cost1+solve(i+1),cost2+solve(i+2));

   }

 */

int main()

{

	std::ios::sync_with_stdio(false);



	cin>>n;



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

	dp[0]=0;

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

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

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

	}

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

	return 0;

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

using namespace std;

#define ll long long

#define ull unsigned long long

#define PII pair<int,int>

#define PSI pair<string,int>

#define PIII pair< int, pair<int,int> >

const int MXN = 1e5;

const int INF = 1e9;

int a[MXN+5];

ll dp[MXN+5];

int N;



ll rec(int pos){



    if(pos==N) return 0;

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

    ll ret = INF;

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

        int next = pos + i;

        if(next<=N){

            ret = min( ret , (ll) rec(next) + abs(a[next]-a[pos]) );

        }

    }



    return dp[pos]=ret;

}



void solve(){



    cin>>N;

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

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

    cout<< rec(1) << "\n";

}



int main(){



    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    solve();

}

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

using namespace std;

#define ll long long

#define ull unsigned long long

#define PII pair<int,int>

#define PSI pair<string,int>

#define PIII pair< int, pair<int,int> >

const int MXN = 1e5;

int a[MXN+5], dp[MXN+5];

int N,K;



int rec(int pos){



    if(pos==N) return 0;

    if(pos>=N) return 1<<30;

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

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

}



void solve(){



    cin>>N;

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

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

    cout<< rec(1) << "\n";

}



int main(){



    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    solve();

}