stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

#include<iostream>

#include<algorithm>

#include<iomanip>

#include<string>

#include<cmath>

#include<vector>

#include<set>

#include<queue>

#include<stack>

#include<fstream>

#include<map>

#include<bitset>

#include<unordered_map>

#include<cstring>

#include<cctype>

using namespace std;

#define  ll long long

#define  ull unsigned long long

#define  ul unsigned long

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

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

#define pb(s) push_back(s);

#define format(n) fixed<<setprecision(n)

#define finl "\n"

#define Mohammed_Atef_Hassan fast();

#define mod 1000000007

#define INF LLONG_MAX

#define PI acos(-1)

#define clr(dp,n) memset(dp,n,sizeof dp)

#define ex(n) return cout<<n<<finl,0;

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

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

ll fix_mod(ll x, ll y)

{

	return (y + x % y) % y;

}

void fast() {

	std::ios_base::sync_with_stdio(false);

	cin.tie(nullptr); cout.tie(nullptr);





}

int n;

vector<ll>v;

ll mem[(int)1e5 + 10];

ll solve(int i)

{

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

	ll& ret = mem[i];

	if (~ret)return ret;

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

	if (i + 2 < n)

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

	return ret;

}

int main()

{

	Mohammed_Atef_Hassan

		clr(mem, -1);

		cin >> n;

	v = vector<ll>(n);

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

	ex(solve(0));

}

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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

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

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int arr[N], n, memo[N], res;



int Solve(int idx){



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

    int op1 = OO, op2 = OO;

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

    op1 = abs(arr[idx]-arr[idx+1]) + Solve(idx+1);

    if(idx + 2 < n)

        op2 = abs(arr[idx]-arr[idx+2]) + Solve(idx+2);



    return memo[idx] = min(op1, op2);

}



int main() {

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

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

    GO();

    scanf("%d", &n);

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

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

    }

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

    printf("%d", Solve(0));

    return 0;

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

#include <sstream>

using namespace std;

#include <bits/stdc++.h>

#include<utility>

#include <algorithm>

#include<iterator>

#define  go return 0

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

#define rep(j,m) for(int j=0;j<m;++j)

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

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

#define len(s)   ((int)s.size())

#define F first

#define S second

#define pb push_back

#define pf push_front

#define mp make_pair

typedef long long ll;

typedef double db;

typedef vector<ll> ve;

typedef vector< vector <int> >vee;

typedef vector<pair<int,int> >vepa;

typedef set<char>se;

typedef map<ll,ll> mpp;

const ll N=1e5+5;

bool f;

ll n,arr[N],dp[N];

ll solve(ll i=0)

{

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

  ll &ret=dp[i];

  if(~ret)return ret;

   return ret=min(solve(i+1)+abs(arr[i]-arr[i+1]) ,i+2<n? solve(i+2)+abs(arr[i]-arr[i+2]):12345 );

}

int main()

{

ios::sync_with_stdio(0);

cin.tie(0);

   cin>>n;

   memset(dp,-1,sizeof dp);

   rep(i,n)

    cin>>arr[i];

   cout<<solve();



go;

}


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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

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

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int arr[N], n, memo[N], res;



int Solve(int idx){



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

    int op1 = OO, op2 = OO;

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

    op1 = abs(arr[idx]-arr[idx+1]) + Solve(idx+1);

    if(idx + 2 < n)

        op2 = abs(arr[idx]-arr[idx+2]) + Solve(idx+2);



    return memo[idx] = min(op1, op2);

}



int main() {

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

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

    GO();

    scanf("%d", &n);

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

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

    }

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

    printf("%d", Solve(0));

    return 0;

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

using namespace std;



vector<long long int> dp(100005,-1);

long long int n,ara[100005];

int f(long long int i){



    if(i==n) return 0;



    if(i==n-1) return abs(ara[i+1]-ara[i]);



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



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

    return dp[i];





}









int main()

{

    long long int i;

    cin>>n;

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

        scanf("%lld",&ara[i]);

    }



    cout<<f(1)<<endl;



    return 0;

}


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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

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

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int arr[N], n, memo[N], res;



int Solve(int idx){



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

    int op1 = OO, op2 = OO;

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

    op1 = abs(arr[idx]-arr[idx+1]) + Solve(idx+1);

    if(idx + 2 < n)

        op2 = abs(arr[idx]-arr[idx+2]) + Solve(idx+2);



    return memo[idx] = min(op1, op2);

}



int main() {

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

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

    GO();

    scanf("%d", &n);

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

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

    }

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

    printf("%d", Solve(0));

    return 0;

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

#define ll long long

using namespace std;

#define inf 0x3f3f3f3f 

int main(){

	ll t , h[100001] , dp[100001] = {0};

    cin >> t;

	for(int i = 0 ; i < t ; ++i) scanf("%lld",h+i);

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

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

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

        cout<<dp[t-1];

}

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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

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

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int arr[N], n, memo[N], res;



int Solve(int idx){



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

    int op1 = OO, op2 = OO;

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

    op1 = abs(arr[idx]-arr[idx+1]) + Solve(idx+1);

    if(idx + 2 < n)

        op2 = abs(arr[idx]-arr[idx+2]) + Solve(idx+2);



    return memo[idx] = min(op1, op2);

}



int main() {

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

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

    GO();

    scanf("%d", &n);

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

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

    }

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

    printf("%d", Solve(0));

    return 0;

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

using namespace std;

#define ll long long int





ll a[100005];

vector<ll> cache(100005,-1);

ll n;



ll frog1(ll x)

{

	if(cache[x]!=-1)

		return cache[x];

	if(x>=n)

		return INT_MAX;

	if(x==n-1)

		return 0;

	else

		return cache[x] = min( abs(a[x+1]-a[x])+frog1(x+1), abs(a[x+2]-a[x])+frog1(x+2));

}



int main()

{

	cin>>n;

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

	{

		cin>>a[i];

	}

	cout<<frog1(0);

	return 0;

}

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

using namespace std;

#define ll long long int





//ll a[100005];

//vector<ll> cache(100005,-1);

//ll n;

//

//ll frog1(ll x)

//{

//	if(cache[x]!=-1)

//		return cache[x];

//	if(x>=n)

//		return INT_MAX;

//	if(x==n-1)

//		return 0;

//	else

//		return cache[x] = min( abs(a[x+1]-a[x])+frog1(x+1), abs(a[x+2]-a[x])+frog1(x+2));

//}

//

//int main()

//{

//	cin>>n;

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

//	{

//		cin>>a[i];

//	}

//	cout<<frog1(0);

//	return 0;

//}



int main()

{

	ll n;

	cin>>n;

	vector<int> a;

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

	{

		int x;

		cin>>x;

		a.push_back(x);

	}

	vector<int> dp(n,INT_MAX);

	dp[0] = 0;

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

	{

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

		{

			if(j<n)

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

		}

	}

	cout<<dp[n-1];

	return 0;

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

using namespace std;

typedef long long ll;

#define MAXN 100100

const ll inf = (ll)1e10;

ll dp[MAXN];

int n, h[MAXN],k;

ll solve( int pos ) {

	if ( pos == n ) return 0;

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

	ll ret = inf;

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

		if ( pos + i <= n ) {

			ret = min(ret,solve(pos+i)+abs(h[pos]-h[pos+i]));

		}

	}

	return dp[pos] = ret;

}

int main()

{

	#ifdef __APPLE__

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

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

	#endif

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	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.77774678767305x):
/*

    Author : Simanta Deb Turja

*/

#include <bits/stdc++.h>

using namespace std;



#define Professor



using ll = long long;

using i64 = unsigned long long;



template <typename T> inline T Min (T a, T b, T c) { return min(a, min(b, c)); }

template <typename T> inline T Min (T a, T b, T c, T d) { return min(a, min(b, min(c, d))); }

template <typename T> inline T Max (T a, T b, T c) { return max(a, max(b, c)); }

template <typename T> inline T Max (T a, T b, T c, T d) { return max(a, max(b, max(c, d))); }



template <typename T> inline T Ceil(T a, T b) { return ((a % b == 0) ? (a / b) : (a / b + 1)); } 

template <typename T> inline T Floor(T a, T b) { return a / b; }



template <typename T> inline T Power (T a, T p) { T res = 1, x = a; while ( p ) { if ( p & 1 ) res = ( res * x ); x = ( x * x ); p >>= 1;}return res; }

template <typename T> inline T BigMod (T a,T p,T M) { a %= M;T ret = 1; while (p) { if (p & 1) ret = (ret * a) % M; a = (a * a) % M; p = p >> 1; } return ret; }

template <typename T> inline T InverseMod (T a,T M) { return BigMod (a, M - 2, M); }



template <typename T> inline T gcd ( T a, T b ) { a = abs(a); b = abs(b); while ( b ) { a = a % b; swap ( a, b ); } return a; }

template <typename T> inline T lcm(T x,T y) { return (((x)/gcd((x),(y)))*(y)); }





#define endl '\n'

#define eb emplace_back



const int N = (int)4e5 + 10;

const double EPS = 1e-7;

const double PI = acos(-1.0);

const ll LLINF = numeric_limits<ll>::max();

const int INF = numeric_limits<int>::max();

const ll MOD = (ll)1e9 + 7;



template <typename T> bool cmp (const pair <T, T> &a, const pair <T, T> &b) { return a.first < b.first; }





int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr); cout.tie(nullptr);

    auto Solve = [&]() {

        #ifdef __APPLE__

            cout << "Running\n";

        #endif

        int n;

        cin >> n;

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

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

            cin >> h[i];

        }

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

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

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

        }

        cout << dp[n] << endl;



    };

    Solve();

    

    return 0;

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

using namespace std;

long long int n,minimum[100010];

vector<long long int>v;

long long int dp(long long index)

{

    long long int temp1,temp2=INT_MAX;

    if(index==n-1)

        return 0;

    if(minimum[index+1]==-1)

    {

        minimum[index+1]=dp(index+1);

    }

    temp1=abs(v[index]-v[index+1])+minimum[index+1];

    if(minimum[index+2]==-1 && index<n-2)

    {

        minimum[index+2]=dp(index+2);

    }

    if(index<n-2)

        temp2=abs(v[index]-v[index+2])+minimum[index+2];

    return min(temp1,temp2);



}

int main()

{

    ios_base::sync_with_stdio(false);cin.tie(0);

    long long int i,j,k,temp;

    cin>>n;

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

    {

        cin>>temp;

        v.push_back(temp);

    }

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

    cout<<dp(0);

}


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

using namespace std;



int main()

{

    ios_base::sync_with_stdio(false);cin.tie(0);

    long long int n,i;

    cin>>n;

    long long int a[n],dp[n];

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

        cin>>a[i];

    dp[0]=0;

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

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

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

    cout<<dp[n-1];

}
// 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.8005453179985098x):
#include <iostream>

#include <vector>



const long long INF = 1LL << 60;

// long long early = 0;

long long h[100010];

long long dp[100010];



long long calc_dist(int n)

{

    if (n == 1) return 0;

    if (dp[n] != INF) {

//         early++;

        return dp[n];

    }

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

    return dp[n] = std::min(calc_dist(n-1) + abs(h[n] - h[n-1]), calc_dist(n-2) + abs(h[n] - h[n-2]));

}



int main()

{

    int n;

    std::cin >> n;

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

        std::cin >> h[i];

        dp[i] = INF;

    }

    std::cout << calc_dist(n) << std::endl;

//     std::cout << early << std::endl;

    return 0;

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

using namespace std;

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



typedef long long ll;



const int INF = 1e9;

vector<ll> h(100005,0);

vector<ll> dp(100005,INF);

int main() {

	int N;

	cin>>N;

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

	dp[0] = 0;

	rep(i,N){

		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;

}

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

using namespace std;

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

#define rep1(i,N) for(int i=1;i<int(N);++i)

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

#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }



using P = pair<int, int>;

typedef long long ll;



const int MOD = 1e9+7;

const int INF = 1e9;

int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    int N;cin>>N;

    vector<ll> h(N);

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

    ll dp[N];

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

    dp[0] = 0;

    rep(i,N){

        if(i+1<N){

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

        }

        if(i+2<N){

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

        }

    }

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

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

#include<algorithm>

#include<vector>

#include<unordered_map>

#include<string>

using namespace std;



typedef long long ll;



int dp[100000];

int h[100000];



int main(){

	int n;

	cin>>n;

	for(auto &i:dp){

		i=1e9;

	}

	dp[0]=0;

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

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

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

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

		}

	}

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

}

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

using namespace std;



typedef long long ll;

typedef pair<int,int> P;



int dp[114514];



int main(){

	int n;

	cin>>n;

	vector<int>h(n);

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

		cin>>h[i];

		dp[i]=1145141919;

	}

	dp[0]=0;

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

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

			if(i>=j){

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

			}

		}

	}

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

	return 0;	

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

#define F first

#define S second

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

#define setDP(arr) memset(arr,-1,sizeof arr)

#define Clear(arr) memset(arr,0,sizeof arr)

#define li(x) x.size()-1

#define oo 1000000000

#define inf 1000000000000000000

#define M 1000000007

#define M2 1000000009

#define M3 998244353

#define pii pair<int,int>

#define cpx complex<double>

typedef long long ll;

using namespace std;

const int N = 255000;

const int SQRTN = 320;

const int LOGN = 20;

const long double PI = acos(-1);

const long double TAU = 2*acos(-1);



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



int calc(int i){

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

    if(i>=n)return oo;

    int&ret = dp[i];

    if(ret!=-1)return ret;

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

    return ret;

}



signed main(){

    /*#ifndef ONLINE_JUDGE

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

    #endif*/

    cin >> n ;

    setDP(dp);

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

    h[n]=0;

    cout << calc(0);

    return 0;

}


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

#define F first

#define S second

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

#define setDP(arr) memset(arr,-1,sizeof arr)

#define Clear(arr) memset(arr,0,sizeof arr)

#define li(x) x.size()-1

#define oo 1000000000

#define inf 1000000000000000000

#define M 1000000007

#define M2 1000000009

#define pii pair<ll,ll>

using namespace std;

typedef long long ll;

const int N = 2e5+100;

const int SQRTN = 320;

const int LOGN = 20;

const double PI = acos(-1);



int n,k=3;

int a[N];

int dp[N];

int main() {

	cin >> n;

	//cin >> k;

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

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

	}

	dp[0]=0;

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

		dp[i]=oo;

		for(int j = 1 ; j < k ; j++){

			if(i-j<0)break;

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

		}

	}

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



    return 0;

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

#define INF 1000000000;

using namespace std;

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

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(h[i-1]-h[i]);

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

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

}

signed main(){

  cin>>n;

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

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

    cin>>h[i];

  }

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

  return(0);

}


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

#include <map>

#include <list>

#include <queue>

#include <stack>

#include <cmath>

#include <ctime>

#include <cstdio>

#include <vector>

#include <string>

#include <bitset>

#include <cctype>

#include <cstdlib>

#include <cstring>

#include <utility>

#include <numeric>

#include <complex>

#include <sstream>

#include <fstream>

#include <iomanip>

#include <cassert>

#include <iostream>

#include <iterator>

#include <algorithm>

using namespace std;

typedef long long ll;

typedef vector<int> vint;

typedef pair<int, int> pint;

typedef vector<long long> vlong;

#define vpush(a,x) a.push_back(x);

#define rep(i, n) REP(i, 0, n)

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

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

#define INF 2e9

int fact(int n){

  int m;

  if (n == 0)

      return 1;

  m = fact(n - 1);    

  return n * m;       

}

signed main(){

  cin.tie(0);

  ios::sync_with_stdio(false);

  int n;

  cin>>n;

  vint h(n+100);

  REP(i,1,n+1){

      cin>>h[i];

  }

  vector<vector<int> >dp(n+100,vector<int>(3));

  dp[1][1]=0;

  dp[1][2]=0;

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

  dp[2][2]=9999999;

  REP(i,3,n+1){

      REP(j,1,3){

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

	  

      }

      

  }

  cout<<min(dp[n][1],dp[n][2])<<'\n';

  

  return(0);

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

#define INF 1000000000;

using namespace std;

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

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(h[i-1]-h[i]);

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

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

}

signed main(){

  cin>>n;

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

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

    cin>>h[i];

  }

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

  return(0);

}


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

using namespace std;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

typedef long long ll;

typedef vector<int> vint;

typedef pair<int, int> pint;

typedef vector<long long> vlong;

#define _GLIBCXX_DEBUG

#define vpush(a,x) a.push_back(x);

#define rep(i, n) REP(i, 0, n)

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

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

signed main(){

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n;

    cin>>n;

    vint h(n+1);

   	REP(i,1,n+1){

        cin>>h[i];

    }

    vint dp(n+1);

    REP(i,2,n+1){

        if(i-2>=1){

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

        }

        else{

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

        }

    }

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

    return(0);

}