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

}




// Optimized solution to the same problem (faster):
/*

    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;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}


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

}


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

#include <vector>

#include <cstdlib>

using namespace std;

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

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



const long long INF = 1LL << 60;



// 入力

int N;

long long h[100010];



// メモ用の DP テーブル

long long dp[100010];



long long rec(int i) {

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

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



    // 足場 0 のコストは 0

    if (i == 0) return 0;



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

    long long res = INF;

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

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



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

    return dp[i] = res;

}



int main() {

    int N; cin >> N;

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



    // 初期化 (最小化問題なので INF に初期化)

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



    // 答え

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

}

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

#include <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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

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

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

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

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


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

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}


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

using namespace std;

int main(){

  int n;

  cin>>n;

  vector<int> h(n+5);

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

    cin>>h[i+1];

  }

  vector<int> dp(n+5,100000);

  dp[1]=0;

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

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

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

  }

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

  return(0);

}

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

using namespace std;



const int MAX=100005;

vector<int> S(MAX),h(MAX);

int N;



void DP(int u){

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

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

    else if(i==3) S[3]=abs(h[3]-h[1]);

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

    }

    cout<<S[u]<<endl;

}



int main(){

    

    cin>>N;

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

        cin>>h[i+1];

    }

    DP(N);

    

}


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

using namespace std;



typedef long long ll;

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

const int mod=1000000007;



int main(){

    

    int N;cin>>N;

    vector<int> S(N),dp(N+2,1500000000);

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

        cin>>S[i];

    }

    dp[0]=0;

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

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

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

    }

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

}


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


// Problem : A - Frog 1

// Contest : AtCoder - Educational DP Contest

// URL : https://atcoder.jp/contests/dp/tasks/dp_a

// Memory Limit : 1024 MB

// Time Limit : 2000 ms

// Powered by CP Editor (https://github.com/cpeditor/cpeditor)



#pragma GCC optimize("O3")  

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define F first

#define pii pair<int,int>

#define S second

#define endl "\n"

#define gcd(a,b) __gcd(a,b)

#define lcm(a,b) (a*b)/gcd(a,b)

#define mem(z,i) memset(z,i,sizeof(z))

#define eps 1e-7

#define I (int)

#define mod 1000000007

#define pb push_back

const long long INF = 1000000000000000000LL;

//const int WASTE=∞

const int N=1e5+5;

int a[N],dp[N];

int f(int x){

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

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

	return dp[x];

}

signed main() {

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

  	// cout<<fixed;

  	// cout.precision(10);

   	int n;

   	cin>>n;

   	mem(dp,-1);

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

   	for(int x=1;x<=n;x++) cin>>a[x];

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

   	int ans=f(n);

   	cout<<ans<<endl;

   	//for(int x=1;x<=n;x++) cout<<dp[x]<<' ';

   	

   	

   	

   	

   	

   	

   	

   	

   	

   	

   	

  	return 0;

}




// Optimized solution to the same problem (faster):


// Problem : A - Frog 1

// Contest : AtCoder - Educational DP Contest

// URL : https://atcoder.jp/contests/dp/tasks/dp_a

// Memory Limit : 1024 MB

// Time Limit : 2000 ms

// Powered by CP Editor (https://github.com/cpeditor/cpeditor)



#pragma GCC optimize("O3")  

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define F first

#define pii pair<int,int>

#define S second

#define endl "\n"

#define gcd(a,b) __gcd(a,b)

#define lcm(a,b) (a*b)/gcd(a,b)

#define mem(z,i) memset(z,i,sizeof(z))

#define eps 1e-7

#define I (int)

#define mod 1000000007

#define pb push_back

const long long INF = 1000000000000000000LL;

//const int WASTE=∞

const int N=1e5+5;

signed main() {

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

  	// cout<<fixed;

  	// cout.precision(10);

   	int n;

   	cin>>n;

   	int a[n];

   	for(int x=0;x<n;x++) cin>>a[x];

   	int dp[n];

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

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

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

   	}

   	cout<<dp[n-1];

   	

   	

   	

   	

   	

   	

   	

   	

   	

   	

  	return 0;

}




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

using namespace std;



using ll=long long;



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



int N;

ll h[100010];

ll dp[100010];



int main(){

  cin >> N;

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

    cin >> h[i];

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

    dp[i]=INF;

  dp[0]=0;

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

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

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

  }

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

  

}

// Optimized solution to the same problem (faster):
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

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;}

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

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

typedef long long ll;

typedef pair<ll,ll> l_l;

typedef pair<int,int> i_i;

const ll MOD=1e9+7;

const int INF=1<<30;



int dp[100100];



int main(){

  int N; cin >> N;

  vector<int> h(N);

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

  rep(i,100100){

    dp[i]=INF;

  }

  dp[0]=0;

  rep(i,N){

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

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

  }

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

}

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

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; }



using ll=long long;

const int Nmax=100010;

int N; 

ll dp[Nmax];

int h[Nmax];

const ll INF=1LL<<60;





int main(){

  cin >> N;

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

    cin >> h[i];

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

    dp[i]=INF;

  dp[0]=0;

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

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

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

  }

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

  

}

// Optimized solution to the same problem (faster):
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

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;}

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

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

typedef long long ll;

typedef pair<ll,ll> l_l;

typedef pair<int,int> i_i;

const ll MOD=1e9+7;

const int INF=1<<30;



int dp[100100];



int main(){

  int N; cin >> N;

  vector<int> h(N);

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

  rep(i,100100){

    dp[i]=INF;

  }

  dp[0]=0;

  rep(i,N){

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

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

  }

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

}

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

using namespace std;

typedef unsigned long long int ull;

typedef long long int ll;

typedef long double ld;

#define mod 1000000007

#define pub(a) push_back(a)

#define mp(a,b) make_pair(a,b)



const ll N = 100004;

vector<ll>dp(N,-1);



ll call(ll h[],ll n){

    if(n==1){

        dp[1]= 0;

        return dp[1];

    }else if(n==2){

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

        return dp[2];

    }else{

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

            return dp[n];

        }

    }

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



}





int main(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    ll n;

    cin>>n;

    ll h[n+1];

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

        cin>>h[i];

    }

    cout<<call(h,n);

    



    return 0;

}


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

using namespace std;

typedef unsigned long long int ull;

typedef long long int ll;

typedef long double ld;

#define mod 1000000007

#define pub(a) push_back(a)

#define mp(a,b) make_pair(a,b)

#define getl(s) getline(cin,s);







int main(){

  ios::sync_with_stdio(0);

  cin.tie(0);

  ll n;

  cin>>n;

  ll dp[n+1];

  ll h[n+1];

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

    cin>>h[i];

  }

  dp[1]=dp[0] =0;

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

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

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

  }

  cout<<dp[n];



  return 0;

}


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



using namespace std;

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

int f(int i = 0)

{

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

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

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

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

}

int main()

{

    memset(dp,-1,sizeof dp);

    cin >> n;

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

        cin >> a[i];

    cout << f();

    return 0;

}

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

using namespace std;

#define ll long long

int main()

{

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

    scanf("%d", &n);

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

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

    dp[n-1] = 0;

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

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

    {

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

    }

    cout << dp[0];

    return 0;

}

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

using namespace std;

#define ll long long

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

int f(int i)

{

    if( i == n-1 )

        return 0;

    if( dp[i] != -1 )

        return dp[i];

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

    if( i < n-2 )

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

    return dp[i];

}

int main()

{

    scanf("%d", &n);

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

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

    memset(dp, -1, sizeof dp);

    cout << f(0);

    return 0;

}

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

using namespace std;

#define ll long long

int main()

{

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

    scanf("%d", &n);

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

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

    dp[n-1] = 0;

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

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

    {

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

    }

    cout << dp[0];

    return 0;

}

// Fastest known solution for this problem: