stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include<climits>



using namespace std;

#define ll long long int

#define Max 110000



int main() {

	int n;

	cin>>n;

	int arr[n];

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

	{

		cin>>arr[i];

	}

	ll dp[Max+1];

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

	{

		dp[i]=INT_MAX;

	}

	dp[0]=0;

	//cout<<dp[1];

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

	{

		if(i+1<n)

		{

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

		}

		if(i+2<n)

		{

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

		}

	}

	cout<<dp[n-1];

	return 0;

}

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

#define ll long long int

using namespace std;

ll solve(int cost[],int n)

{

	ll dp[n];

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

		dp[i]=INT_MAX;

	dp[0]=0;

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

	{

		if(i+1<n)

			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]));

	}

	return dp[n-1];

}

int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	int n;

	cin>>n;

	int cost[n];

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

		cin>>cost[i];

	long long int ans=solve(cost,n);

	cout<<ans;

	return 0;

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

using namespace std;

int v[100010];

int dp[100010];

int f(int i){

    if(i == 1) return 0;

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

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

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

    return dp[i];

}

int main(){

    memset(dp,-1,sizeof dp);

    memset(v,0,sizeof v);

    int n;

    cin>>n;

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

    cout<<f(n)<<"\n";

    return 0;

}


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

using namespace std;

#define PB push_back

#define MP make_pair

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

typedef long long ll;

typedef int i;

typedef vector<i>vi;

typedef pair<i,i>pi;

int v[100010];

int dp[100010];

int f(int i){

	if(i < 0) return 1e8;

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

	int &r = dp[i];

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

	return r;



}



int main(){

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

	ios::sync_with_stdio(0);

	cin.tie(0);

	int n;cin>>n;

	fora(i,0,n){

		cin>>v[i];

	}

	memset(dp, -1,sizeof dp);

	dp[0] = 0;

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

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

	

	return 0;

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

using namespace std;

int dp[100005];

int n,arr[100005];

int func(int i)

{

    int ans1=0,ans2=0;

    if(i>=n) return 0;

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

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

    if(i<=n-2) ans2=abs(arr[i]-arr[i+2])+func(i+2);

    else ans2=123456;

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

}

int main()

{

    int i;

    cin>>n;



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

    memset(dp,-1,sizeof dp);

    int ans = func(1);

    cout<<ans;

}


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

using namespace std;

int dp[100005];

int main()

{

    int n,i;

    cin>>n;

    int arr[n+2];

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



    dp[1]=0;

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



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

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



#define fast1 ios_base::sync_with_stdio(false)

#define fast2 cin.tie(NULL)

#define ll long long



using namespace std;



int main(){



    int n;

    cin >> n;



    int a[n];

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

        cin >> a[i];

    }



    int dp[100008];

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

        dp[i]=INT_MAX;

    }





    dp[0]=0;



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

        if(i==n-2){

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

        }else{

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

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

        }

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

    }



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





    return 0;

}


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

using namespace std;



int main(){



	int n;

	cin >> n;



	vector<int> a(n);

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

		cin >> a[i];

	}



	vector<int> dp(n,INT_MAX);

	dp[n-1]=0;





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

		if(i+1<n){

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

		}

	}



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





	return 0;

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

#include <vector>

#include <map>

using namespace std;



int N;

int h[111111];

int dp[111111];

int main(){

    cin >> N;

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

        cin >> h[i];



    fill_n(dp, 111111, 1<<30);

    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;

    return 0;

}

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

using namespace std;

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

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(int i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }

template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }



int main(){

    int N;

    cin >> N;

    vector<int> h(N);

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

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

    dp[0] = 0;

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

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

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

    }

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

    return 0;

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

#include<vector>

#include<algorithm>

#include<queue>

#include<map>

#include<stack>

#include<cmath>

#include<iomanip>

#include<set>

#include<numeric>

#include<sstream>

#include<random>

#include<cassert>

#include<climits>

#include<cstring>

using namespace std;

typedef long long ll;

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

#define rrep(i, st, n) for (int i = st; i < n; ++i)

using pii = pair<int, int>;

const int inf = 1e9 + 7;

int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};

int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

#define ceil(a, b) a / b + !!(a % b)

#define chmax(a, b) a = max(a, b)

#define chmin(a, b) a = min(a, b)



int n;

int h[100001];

int memo[100001];

int recur(int i) {

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

    if (memo[i] != inf) return memo[i];

    int a = (i + 1 < n ? abs(h[i] - h[i + 1]) + recur(i + 1) : inf);

    int b = (i + 2 < n ? abs(h[i] - h[i + 2]) + recur(i + 2) : inf);

    return memo[i] = min(a, b);

}

int main() {

    cin >> n;

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

    rep(i, 100001) memo[i] = inf;

    cout << recur(0) << endl;

}


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

using namespace std;

typedef long long ll;

#define F first

#define S second

#define pii pair<int, int>

#define eb emplace_back

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

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

#define rep3(i, l, n) for (int i = l; i < (n); ++i)

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

const int inf = 1e9 + 7;

const ll INF = 1e18;

#define abs(x) (x >= 0 ? x : -(x))

#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())

#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())

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

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

template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }

const int mod = 1000000007;

ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }

template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }

template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }

template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }







void solve();



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);



    int T;

    // cin >> T;

    T = 1;



    while (T--) {

        solve();

    }

}



void solve() {

  int n;

  cin >> n;

  vector<int> a(n);

  rep(i, n) cin >> a[i];

  vector<int> dp(n, inf);

  dp[0] = 0;

  rep(i, n) {

    rep3(j, i - 2, i) {

      if (j >= 0) chmin(dp[i], dp[j] + abs(a[i] - a[j]));

    }

  }

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

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

#include<vector>

#include<algorithm>

#include<queue>

#include<map>

#include<stack>

#include<cmath>

#include<iomanip>

#include<set>

#include<numeric>

#include<sstream>

#include<random>

#include<cassert>

#include<climits>

#include<cstring>

using namespace std;

typedef long long ll;

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

#define rrep(i, st, n) for (int i = st; i < n; ++i)

using pii = pair<int, int>;

const int inf = 1e9 + 7;

int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};

int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

#define ceil(a, b) a / b + !!(a % b)

#define chmax(a, b) a = max(a, b)

#define chmin(a, b) a = min(a, b)



int n;

int h[100001];

int dp[100001];



int main() {

    cin >> n;

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

    rep(i, 100001) dp[i] = inf;

    dp[0] = 0;

    rep(i, n - 2) {

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

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

    }

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

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

}


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

using namespace std;

typedef long long ll;

#define F first

#define S second

#define pii pair<int, int>

#define eb emplace_back

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

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

#define rep3(i, l, n) for (int i = l; i < (n); ++i)

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

const int inf = 1e9 + 7;

const ll INF = 1e18;

#define abs(x) (x >= 0 ? x : -(x))

#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())

#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())

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

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

template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }

const int mod = 1000000007;

ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }

template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }

template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }

template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }







void solve();



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);



    int T;

    // cin >> T;

    T = 1;



    while (T--) {

        solve();

    }

}



void solve() {

  int n;

  cin >> n;

  vector<int> a(n);

  rep(i, n) cin >> a[i];

  vector<int> dp(n, inf);

  dp[0] = 0;

  rep(i, n) {

    rep3(j, i - 2, i) {

      if (j >= 0) chmin(dp[i], dp[j] + abs(a[i] - a[j]));

    }

  }

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

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

using namespace std;

typedef long long int lli;

typedef vector <int> vi;

typedef vector <vi> vvi;

typedef pair <int,int> pr;

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

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

#define pb push_back

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

#define tr(c, i) for (typeof ((c).begin() i = (c).begin(); i != (c).end(); i++)

#define present(c, x)((c).find(x) != (c).end())

#define cpresent(c, x)(find(all(c), x) != (c).end())

// for mod power a^b%m use power<lli> (a,b,m)

template < class mytype >

mytype power(mytype a, mytype b, mytype m){if (b == 1) return a % m;if (b == 0) return 1;

lli root = power < lli > (a, b / 2, m);lli ans = (root * root) % m;if (b % 2) ans = (ans * a) % m;

return ans;

}

// for gcd use gcd<int> (a,b)

template < class type >type gcd(type a, type b){if (a == 0) return b;else return gcd(b % a, a);}

template < class type >type mod_inv(type a, type p) {return power(a, p - 2, p);}



// use from here bitches

int n;

vector<int> height(100002) , values(100002 , -1);

int dp(int x){

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

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

if(x >= n-2) return values[x] = abs(height[x+1] - height[x]);

else return values[x] = min(abs(height[x+1] - height[x]) + dp(x+1) , abs(height[x+2] - height[x]) + dp(x+2));

}





int main()

{    

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cin >> n;

	fr(i , n){

		cin >> height[i];

	}

	cout << dp(0);

		



	





    return 0;

	

}


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

using namespace std;

typedef long long int lli;

typedef vector <int> vi;

typedef vector <vi> vvi;

typedef pair <int,int> pr;

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

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

#define pb push_back

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

#define tr(c, i) for (typeof ((c).begin() i = (c).begin(); i != (c).end(); i++)

#define present(c, x)((c).find(x) != (c).end())

#define cpresent(c, x)(find(all(c), x) != (c).end())

// for mod power a^b%m use power<lli> (a,b,m)

template < class mytype >

mytype power(mytype a, mytype b, mytype m){if (b == 1) return a % m;if (b == 0) return 1;

mytype root = power < lli > (a, b / 2, m);mytype ans = (root * root) % m;if (b % 2) ans = (ans * a) % m;

return ans;

}

// for gcd use gcd<int> (a,b)

template < class type >type gcd(type a, type b){if (a == 0) return b;else return gcd(b % a, a);}

template < class type >type mod_inv(type a, type p) {return power(a, p - 2, p);}





int main()

{

    int n;

    cin >> n;

    vector<int> h(n) , cost(n , 1e9+7);

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

    cost[0] = 0;

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

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

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

        }

    }

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

    return 0;

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

using namespace std;

typedef long long int lli;

typedef vector <int> vi;

typedef vector <vi> vvi;

typedef pair <int,int> pr;

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

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

#define pb push_back

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

#define tr(c, i) for (typeof ((c).begin() i = (c).begin(); i != (c).end(); i++)

#define present(c, x)((c).find(x) != (c).end())

#define cpresent(c, x)(find(all(c), x) != (c).end())

// for mod power a^b%m use power<lli> (a,b,m)

template < class mytype >

mytype power(mytype a, mytype b, mytype m){if (b == 1) return a % m;if (b == 0) return 1;

mytype root = power < lli > (a, b / 2, m);mytype ans = (root * root) % m;if (b % 2) ans = (ans * a) % m;

return ans;

}

// for gcd use gcd<int> (a,b)

template < class type >type gcd(type a, type b){if (a == 0) return b;else return gcd(b % a, a);}

template < class type >type mod_inv(type a, type p) {return power(a, p - 2, p);}

int n;

vector<int> h(100001);

vector<int> cost(100001 , -1);



int dp(int index){

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

    cost[index] = dp(index - 1) + abs(h[index] - h[index - 1]);

    if(index != 1) cost[index] =  min(cost[index] , dp(index - 2) + abs(h[index] - h[index - 2]) );

    return cost[index];

    }

int main()

{

    cin >> n;cost[0] = 0;

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

        cin >> h[i];

    }

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







    return 0;

}


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

using namespace std;

typedef long long int lli;

typedef vector <int> vi;

typedef vector <vi> vvi;

typedef pair <int,int> pr;

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

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

#define pb push_back

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

#define tr(c, i) for (typeof ((c).begin() i = (c).begin(); i != (c).end(); i++)

#define present(c, x)((c).find(x) != (c).end())

#define cpresent(c, x)(find(all(c), x) != (c).end())

// for mod power a^b%m use power<lli> (a,b,m)

template < class mytype >

mytype power(mytype a, mytype b, mytype m){if (b == 1) return a % m;if (b == 0) return 1;

mytype root = power < lli > (a, b / 2, m);mytype ans = (root * root) % m;if (b % 2) ans = (ans * a) % m;

return ans;

}

// for gcd use gcd<int> (a,b)

template < class type >type gcd(type a, type b){if (a == 0) return b;else return gcd(b % a, a);}

template < class type >type mod_inv(type a, type p) {return power(a, p - 2, p);}





int main()

{

    int n;

    cin >> n;

    vector<int> h(n) , cost(n , 1e9+7);

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

    cost[0] = 0;

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

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

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

        }

    }

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

    return 0;

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

using namespace std;



#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )

template <typename Arg1>

void __f( const char* name , Arg1&& arg1 ) {

        cerr << name << " : " << arg1 << "\n";

}

template <typename Arg1, typename... Args>

void __f( const char* na , Arg1&& arg1 , Args&&... args ) {

        const char* c = strchr( na + 1 , ',' );

        cerr.write( na , c - na ) << " : " << arg1 << " , ";

        __f( c + 1 , args... );

}

#define endl "\n"

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

#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())

#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long int LL;

typedef pair <int,int> pii;

const int MOD = 1e9 + 7;

const int inf = 1e9;

const double EPS = 1e-9;

const double PI = acos(-1.0);

const long long INF = 1e18;

const int N = 1e5 + 5;



int n;

int h[ N ];

int dp[ N ];



int solve( int idx ) {

        if( idx == n ) return 0;

        if( idx > n ) return inf;

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

        int ret = inf;

        ret = min( ret , solve( idx + 1 ) + abs( h[idx+1] - h[idx] ) );

        ret = min( ret , solve( idx + 2 ) + abs( h[idx+2] - h[idx] ) );

        return dp[idx] = ret;

}

int main( ) {

        IO;

        #ifdef LOCAL

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

        #endif // LOCAL

        cin >> n;

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

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

        cout << solve( 1 ) << endl;

        return 0;

}










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

using namespace std;



#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void __f(const char* name, Arg1&& arg1) {

  cerr << name << " : " << arg1 << "\n";

}

template <typename Arg1, typename... Args>

void __f(const char* na, Arg1&& arg1, Args&&... args) {

  const char* c = strchr(na + 1, ',');

  cerr.write(na, c - na) << " : " << arg1 << " , ";

  __f(c + 1, args...);

}

#define endl "\n"

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

#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())

typedef long long LL;

typedef pair <int,int> pii;

const double pi = acos(-1.0);

const double eps = 1e-8;

const int mod = 1e9 + 7;

const int inf = 1e9;

const LL INF = 1e18;

const int N = 1e5 + 5;



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(0); cout.tie(0);

  #ifdef LOCAL

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

  #endif // LOCAL

  int n;

  cin >> n;

  vector <LL> h (n + 1);

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

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

  dp[1] = 0;

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

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

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

  }

  cout << dp[n] << endl;

  return 0;

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

using namespace std;



#define ll long long



int dp[100001];

int n, arr[100001];

int pound(int pos)

{

    if (dp[pos] != -1)

        return dp[pos];

    

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

    

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    cin >> n;



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

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

        cin >> arr[i];



    dp[0] = 0;

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

    

    cout << pound(n - 1);



    return 0;

}


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

using namespace std;



#define ll long long



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

  

    int n;

    cin >> n;



    int arr[n], dp[n];



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

        cin >> arr[i];



    dp[0] = 0;

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

    

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

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



    cout << dp[n - 1];



    return 0;

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



using namespace std;



typedef long long ll;



const int mx = 100050;

int arr[mx];

int dp[mx];

int n;



int func(int idx)

{

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

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



    int nxt = idx+1;

    int ans  , ret;

    ans = 1e9;

    ans += 100;

    if(nxt < n)

    {

        ret = abs(arr[nxt]-arr[idx]) + func(nxt);

        ans = min(ans,ret);

    }

    nxt = idx+2;

    if(nxt < n)

    {

        ret = abs(arr[nxt]-arr[idx]) + func(nxt);

        ans = min(ans,ret);

    }



    return dp[idx] = ans;

}



int main()

{

    scanf("%d",&n);



    int i, j , k , p , q;



    for(i = 0 ; i < n ; i++)scanf("%d",arr+i);

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

    int ans = func(0);



    printf("%d\n",ans);



    return 0;

}


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



using namespace std;



typedef long long ll;



const int mx = 100050;

int arr[mx];

int dp[mx];

int n;





int main()

{

    scanf("%d",&n);



    int i, j , k , p , q;



    for(i = 0 ; i < n ; i++)scanf("%d",arr+i);



    dp[0] = 0;



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

    {

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

        if(i > 1)

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

    }



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



    return 0;

}