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

}

// 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++)



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;

}


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

}

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

}

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

}

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

}

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

}

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

}

// 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<(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';

}

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

}


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

}

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

}

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

}


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

}


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

}


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

}


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

}

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

}

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

#define ll long long

#define pb push_back

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

#define mp make_pair

#define ff first

#define ss second

#define MAXN  1000005

#define endl "\n"

using namespace std;

vector<ll>v;

ll dp[100003];

ll a,n;

ll rec(int i){

    if(i==n-1)

        return 0;

    if(dp[i]!=-1)

        return dp[i];

    if(i<n-2){

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

    }

    return dp[i]=abs(v[i+1]-v[i])+rec(i+1);

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cin>>n;

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

        cin>>a;

        v.pb(a);

    }

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

    ll ans=rec(0);

    cout<<ans<<endl;







    return 0;

}




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

#define ll long long

#define pb push_back

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

#define mp make_pair

#define ff first

#define ss second

#define MAXN  1000005

#define endl "\n"

using namespace std;



int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    int n, v[100005], dp[100005];

    cin>>n;

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

        cin>>v[i];

    }

    dp[0]=0;

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

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

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

    }

    cout<<dp[n-1];



    return 0;

}




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



using namespace std;

    int N;

     vector<int>dp(2e5 , -1);   

     vector<int>H(2e5);

      int so(int index){

            if(index == N) return 0;

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

          if(index == N-1) return so(index+1) + abs(H[index] - H[index+1]);

        int result = 1e9;

        result = min(so(index+1) + abs(H[index] - H[index+1]),so(index+2) + abs(H[index] - H[index+2]));

        dp[index] = result ;

        return result;

      }





    void solve(){

        cin>>N;

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

        cout<<so(1)<<'\n';

    }



int main(){

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

    int tc = 1;

    //cin>>tc;

    while (tc--)

    {

        solve();

    }

    

    return 0;

}

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



using namespace std;

  

     

    





    void solve(){

          int N;

           cin>>N;

     vector<int>dp(N+1, -1);   

     vector<int>H(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] - H[i-1]) , dp[i-2] + abs(H[i] - H[i-2]));

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

    }



int main(){

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

    int tc = 1;

    //cin>>tc;

    while (tc--)

    {

        solve();

    }

    

    return 0;

}

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


    #include <bits/stdc++.h>

    using namespace std;

    const int inf=1e5+9;

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



    int solve(int pos){

        if(pos==n)

            return 0;

        if(pos>n)

            return 1e9+9;

        long long  &ret=dp[pos];

        if(ret!=-1)

            return ret;

        ret=min(abs(a[pos]-a[pos+1])+solve(pos+1),abs(a[pos]-a[pos+2])+solve(pos+2)  );

        return ret;

    }



    int main(){



        cin>>n;

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

            cin>>a[i];

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

        cout<<solve(1)<<endl;

    }


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


#include <bits/stdc++.h>

using namespace std;

const int inf=1e5+9;

long long  dp[inf],a[inf];

 

int main(){

 

    int n;

    cin>>n;

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

        cin>>a[i];

    

    dp[1]=0;

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

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

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

        long long  y=dp[i-2]+abs(a[i-2]-a[i]);

        dp[i]=min(x,y);

    }

    cout<<dp[n]<<endl;

}


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

using namespace std;

#define endl '\n'

#define pb push_back

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

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

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

typedef long long ll;

typedef vector<int> vi;

typedef vector<ll> vl;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int INF = 0x3f3f3f3f;

const ll LINF = 0x3f3f3f3f3f3f3f3fLL;



int n;

int h[100010];

int memo[100010];



int dp(int i) {



  if( i < 1 ) return INF;

  if( i == 1 ) return 0;

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



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

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



  memo[i] = min(a1, a2);



  return memo[i];

}



signed main()

{

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



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



  cin >> n;



  reps(i, 1, n) cin >> h[i];



  cout << dp(n) << endl;



  return 0;

}


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



using namespace std;



#ifndef DEBUG

#define dump(...)

#endif



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);



    size_t N;

    cin >> N;



    vector<int64_t> h(N);

    for (auto &hi: h) {

        cin >> hi;

    }



    vector<int64_t> dp(N);

    for (size_t i = 1; i < N; ++i) {

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

        else {

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

            int64_t value2 = dp[i - 2] + abs(h[i] - h[i - 2]);

            dp[i] = min(value1, value2);

        }

    }



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



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
/* Code by : Suraj (@suraj1611) */



#include<bits/stdc++.h>

#include <string>



using namespace std;



#define ll long long int

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

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

#define mx INT_MAX

#define mn INT_MIN

#define md 1000000007

#define pb push_back

#define mp make_pair

#define pf printf

#define sc scanf

#define maxsize 1100005

#define lb cout<<endl;

#define F first

#define S second

#define print(i) cout<<i<<endl

#define print1(i,j) cout<<i<<" "<<j<<endl

#define label cout<<"hello!"<<endl

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);



ll dp[maxsize];



ll power(ll x, ll  y) 

{ 

    if (y == 0) 

        return 1; 

    else if (y%2 == 0) 

        return power(x, y/2)*power(x, y/2); 

    else

        return x*power(x, y/2)*power(x, y/2); 

} 



int main()

{

	IOS

	

	/*#ifndef ONLINE_JUDGE   

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

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

	#endif*/



	    

	    rep(i,maxsize)

	    dp[i]=mx;

	    ll n;

		cin>>n;

		ll a[n];

		rep(i,n)

		cin>>a[i];

		

		dp[0]=0;



		rep(i,n)

		{

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

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

		}



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



	/*

	#ifndef ONLINE_JUDGE

    	cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";

    #endif*/



    return 0;

}

// Optimized solution to the same problem (faster):
/* Code by : Suraj (@suraj1611) */



#include<bits/stdc++.h>

#include <string>



using namespace std;



#define ll long long int

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

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

#define mx INT_MAX

#define mn INT_MIN

#define md 1000000007

#define pb push_back

#define mp make_pair

#define maxsize 1100005

#define lb cout<<endl;

#define endl "\n"

#define F first

#define S second

#define label cout<<"hello!"<<endl

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);





ll power(ll x, ll  y) 

{ 

	ll m=md;

   	ll ans=1;

    while (y > 0) 

    {

        if (y & 1)

            ans = (ans * x) % m;

        x = (x * x) % m;

        y >>= 1;

    }

    return ans;

} 



int main()

{

	IOS

	







		ll n;

		cin>>n;

		ll a[n];

		ll dp[n];

		rep(i,n)

		cin>>a[i];

		dp[0]=a[0];

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

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

		{

			if(i==2)

			{

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

				continue;

			}

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

		}

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



	



	



    return 0;

}

// Fastest known solution for this problem: