stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
//g++ -std=gnu++14 a.cpp

#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <iostream>

#include <istream>

#include <iterator>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <vector>

#include <tuple>

#include <iomanip>

#include <random>

using namespace std;



#define ll long long

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

ll MOD = 1e9 + 7;

int INF = 1 << 30;

ll INFL = 1LL << 60;



int main() {

  ll N;

  cin >> N;

  ll dp[1000010];

  rep(i,N){

    dp[i] = INF;

  }

  dp[0] = INF;

  vector<ll> h(N);

  rep(i,N){

    cin >> h[i];

  }

  dp[1] = 0;

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

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

  }

/*

  rep(i,N){

    cout << dp[i] <<endl;

  }

  */



  cout << dp[N] <<endl;

}


// Optimized solution to the same problem (faster):
//g++ -std=gnu++14 a.cpp

#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <iostream>

#include <istream>

#include <iterator>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <vector>

#include <tuple>

#include <iomanip>

#include <random>

using namespace std;



#define ll long long

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

ll MOD = 1e9 + 7;

int INF = 1 << 30;

ll INFL = 1LL << 60;



int main(){



  ll N;

  cin >> N;

  vector<ll> h(N+1);



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

    cin >> h[i];

  }

  h[0]=INFL;

  vector<ll> dp(N+1, 0);

  dp[0] = 0;

  dp[1] = 0;



  for(int i=2;i<N+1;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] <<endl;





}


// Fastest known solution for this problem:
// Original C++ solution (slower):
//g++ -std=gnu++14 a.cpp

#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <iostream>

#include <istream>

#include <iterator>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <vector>

#include <tuple>

#include <iomanip>

#include <random>

using namespace std;



#define ll long long

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

ll MOD = 1e9 + 7;

int INF = 1 << 30;

ll INFL = 1LL << 60;



//int N;

vector<ll> h(100010);

vector<ll> dp(100010, INFL);



ll rec(ll i){

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



  if(i==0) return 0;



  ll res = INF;

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

  if(i>1)res = min(res,rec(i-2)+abs(h[i]-h[i-2]));

  return dp[i]=res;

}



int main(){

  ll N;

  cin >> N;

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

    cin >> h[i];

  }



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



}


// Optimized solution to the same problem (faster):
//g++ -std=gnu++14 a.cpp

//#include <bits/stdc++.h>

#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <iostream>

#include <istream>

#include <iterator>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <vector>

#include <tuple>

#include <iomanip>

#include <random>

#include <math.h>



using namespace std;



#define ll long long

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

ll MOD = 1e9 + 7;

int INF = 1 << 30;

ll INFL = 1LL << 60;



int main(){

  int N;

  cin >> N;

  vector<ll> h(N+10);

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

    cin >> h[i];

  }

  vector<ll> sum(N+10, INFL);

  sum[0] = INFL;

  sum[1] = 0;

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

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

  }

  //rep(i,N+1){

    cout << sum[N] << endl;

  //}





}


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

#define LL long long int 

#define LD long double

#define PI 3.14159265358979323846

#define MOD ((LL)1e9+7)

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const LL N=1e5+10;

vector<LL>A(N),dp(N);

vector<bool>f(N);

LL n;





LL DP(LL I)

{

	if(f[I])return dp[I];

	if(I==1)dp[I]=0;

	else if(I==2)dp[I]=abs(A[1]-A[2]);

	else

	{

		dp[I]=min(DP(I-1)+abs(A[I-1]-A[I]),DP(I-2)+abs(A[I]-A[I-2]));

	}

	f[I]=true;

	return dp[I];

	

}



int main()

{

	IOS

	cin>>n;

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

	cout<<DP(n)<<endl;

	

}

			

				

			

	

	

	

			

		




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

using namespace std;

#define MOD ((int)(1e9+7))

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define int long long

#define float long double



int ans=0,c=0;



int32_t main()

{

	IOS

	int n;cin>>n;

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

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

	dp[0]=1e17;

	dp[1]=0;

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

		

}

			

	

	

	

	

	



	



	



	

		


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

#include <vector>

using namespace std;

int n;

vector<int> h(100000);

vector<int> cost(100000);



int ans(int n)

{

    if (cost.at(n) != -1)

        return cost.at(n);

    cost.at(n) = min(ans(n - 1) + abs(h.at(n) - h.at(n - 1)),

                     ans(n - 2) + abs(h.at(n) - h.at(n - 2)));

    return cost.at(n);

}



int main()

{

    cin >> n;

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

    {

        cin >> h.at(i);

        cost.at(i) = -1;

    }

    cost.at(0) = 0;

    cost.at(1) = abs(h.at(1) - h.at(0));

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

}

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

using namespace std;



typedef pair<int,int> P;

#define ll long long

#define ld long double

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

#define PI 3.14159265358979323846

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

#define chmin(x,y) x = min(x,y)



const int INF = 1e9;

const int MOD = 1e9 + 7;

const ll LINF = 1e18;

ll dp[150000];

ll h[150000];

int main()

{

    int n;

    cin >> n;

    rep(i,n)

    {

        cin >> h[i];

    }

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

    rep(i,n)

    {

        dp[i] = LINF;

    }

    dp[0] = 0;

    for (int i = 0; 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;

}


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

using namespace std;

#define ll long long

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define si size()

#define bk back()

#define popb pop_back()

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

#define endl "\n"

#define lb lower_bound

#define ub upper_bound

#define emp empty()

#define beg begin()

#define en end()

#define ump unordered_map

#define forl(i,a,n) for(int i=a;i<n;i++)

#define rfor(i,n,a) for(int i=n;i>=a;i--)

#define fore(i,a,n) for(int i=a;i<=n;i++)

#define len length()

#define N 100001 

int dp[N];

int func(int arr[],int i,int n)

{

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

	if(dp[i]>=0) return dp[i];

	if(i==n-2) return dp[i]=abs(arr[i+1]-arr[i])+func(arr,i+1,n);

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

}

int main()

{

	int n;

	cin>>n;

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

	int arr[n];

	forl(i,0,n) cin>>arr[i];

	cout<<func(arr,0,n)<<endl;

	

	

}

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

using namespace std;

#define ll long long

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define si size()

#define bk back()

#define popb pop_back()

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

#define endl "\n"

#define lb lower_bound

#define ub upper_bound

#define emp empty()

#define beg begin()

#define en end()

#define ump unordered_map

#define forl(i,a,n) for(int i=a;i<n;i++)

#define rfor(i,n,a) for(int i=n;i>=a;i--)

#define fore(i,a,n) for(int i=a;i<=n;i++)

#define len length()

#define N 200000

int main()

{

	int n;

	cin>>n;

	int arr[n];

	forl(i,0,n) cin>>arr[i];

	int dp[n];

	dp[0]=0;

	forl(i,1,n) dp[i]=INT_MAX;

	forl(i,1,n)

	{

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

		{

			if(j>=0)

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

		}

	}

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

	

	

}

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

///---Code Written by----///

///-----Al-Shahreyaj-----///

///----------------------///

#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define endl "\n"

#define vin vector<int>

#define vll vector<long long>

#define pii pair<int,int>

#define pil pair<int,ll>

#define pll pair<ll,ll>

#define ff first

#define ss second

#define pb push_back

#define pq priority_queue

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

#define mod 1000000007

#define cone __builtin_popcount

#define conel __builtin_popcountll

typedef vector<vector<ll> > matrixl;

typedef vector<vector<int> > matrix;

#define N 100009



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



int solve(int i)

{

    if(i > n) return 0;

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

    int k = (n - i == 1? 1 : 2);

    return dp[i] = min(solve(i + 1) + (i + 1 <= n? abs(h[i+1] - h[i]) : 0), solve(i + k) + (i + k <= n? abs(h[i+k] - h[i]) : 0));

}



int main()

{

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

    cin >> n;

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

    cout << solve(1) << endl;

}


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

using namespace std;



int a[100009], dp[100009];



int main()

{

    int n;

    cin >> n;

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

    {

        cin >> a[i];

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

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

    }

    cout << dp[n] << endl;

}




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

#include <vector>

#include <algorithm>

#include <cstring>

#include <map>

#include <set>

#include <unordered_map>

#include <queue>

#include <stack>

#include <cmath>

#include <functional>

#include <deque>

#include <bitset>

#include <climits>

#include <cstdio>

#include <list>

#include <iomanip>

using namespace std;



#define ll long long int

#define mp make_pair

#define pb push_back

#define fi first

#define si second

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

#define F(a,n) for(int i=0;i<n;i++){cin>>a[i];}

#define F1(a,n) for(int i=1;i<=n;i++){cin>>a[i];}

#define P(a,n) for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;

#define P1(a,n) for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;

#define NF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}

#define NF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}

#define PNF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;

#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;

#define AS 200001

#define mod 1000000007

ll x[110000];

ll dp[110000];

ll ABS(double a) {return max(a, -a);}

int main() {

	fastIO

	int n;

	cin >> n;

	F(x, n);

	memset(dp, mod, sizeof dp);

	dp[0] = 0;

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

		if (i + 1 < n) dp[i + 1] = min(dp[i + 1], dp[i] + ABS(x[i] - x[i + 1]));

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

	}

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

}

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

using namespace std;



#define ll long long int

#define mp make_pair

#define pb push_back

#define fi first

#define si second

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

#define F(a,n) for(int i=0;i<n;i++){cin>>a[i];}

#define F1(a,n) for(int i=1;i<=n;i++){cin>>a[i];}

#define P(a,n) for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;

#define P1(a,n) for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;

#define NF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}

#define NF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}

#define PNF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;

#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;

#define AS 200001

#define mod 1000000007

#define inf 1e9

int solve(vector<int>ar, int n) {

	vector<int>dp(n + 1);

	dp[0] = 1;

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

		int option1 = abs(ar[i] - ar[i - 1]) + dp[i - 1];

		int option2 = (i == 2) ? inf : abs(ar[i] - ar[i - 2]) + dp[i - 2];

		dp[i] = min(option1, option2);

	}

	return dp[n];

}

int main() {

	fastIO



	int n;

	cin >> n;

	vector<int>ar;

	ar.resize(n + 1);

	F1(ar, n);

	cout << solve(ar, n) << endl;

}

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

#include<algorithm>



using namespace std;

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

template<class T> inline bool chmax(T& a, T b);



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;

}



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; 

}

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

using namespace std;



int main()

{

    int N;

    cin >> N;

    long long dp[100000];

    long long  h[100000];

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

    {

        cin >> h[i];

        dp[i] = 10000000000;

    }

    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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
/* BISMILLAHIR RAHMANIR RAHIM */

#include <bits/stdc++.h>

using namespace std;



const int mxn = 100005;

int n, h[mxn], ff[mxn];



int dfs( int pos ) 

{

  if( pos == 0 ) return 0;

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

  

  ff[pos] = 0;

  if( pos > 1 ) 

    ff[pos] = abs(h[pos - 1] - h[pos]) + dfs( pos - 1 );

  if( pos > 2 )

    ff[pos] = min(ff[pos], abs(h[pos - 2] - h[pos]) + dfs( pos - 2 ));

    

  return ff[pos];

}



int main()

{

  scanf("%d", &n);

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

  {

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

  }  

  memset(ff, -1, sizeof ff);

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

  return 0;

}

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

#include <bits/stdc++.h>

using namespace std;



const int mxn = 100005;

int n, h[mxn], ff[mxn];



int main()

{

  scanf("%d", &n);

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

  {

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

  } 

  h[n + 1] = 0;

  ff[n] = 0, ff[n + 1] = 1e6; 

  for(int i = n - 1; i >= 1; i--)

  {

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

  }

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

  return 0;

}

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

using namespace std;



typedef long long int ll;

#define    mod      1000000007

#define    speed    ios_base::sync_with_stdio(false);

#define    up       cin.tie(NULL);

#define    pb       push_back

#define    mp       make_pair

#define    T        int t; cin >> t; while(t--)

ll dp[100005] , arr[100005];

int n;



ll solve(int i){

    if(i > n){

        return 100000;

    }

    if(i==n){

        return 0;

    }

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

        return dp[i];

    }

    ll temp1 = abs(arr[i+1] - arr[i]) + solve(i+1);

    ll temp2 = abs(arr[i+2] - arr[i]) + solve(i+2);

    return (dp[i] = min(temp1 , temp2));

}



int main(){

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

      dp[i] = -1;

  }

  cin >> n;

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

      cin >> arr[i];

  }

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

}

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

using namespace std;

 

typedef long long int ll;

#define    mod      1000000007

#define    speed    ios_base::sync_with_stdio(false);

#define    up       cin.tie(NULL);

#define    pb       push_back

#define    mp       make_pair

#define    T        int t; cin >> t; while(t--)



int main(){

    speed up

    int n; cin >> n;

    int arr[n+5] , dp[n+5];

    cin >> arr[1]; dp[0] = dp[1] = 0;

    arr[0] = 100000;

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

        cin >> arr[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] << '\n';

}

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

using namespace std;



using ll = long long;

#define pb push_back

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

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

#define file freopen("in.txt", "r", stdin);

#define pii pair<int, int>

#define pll pair<ll, ll>



const int maxn = 1e5 + 5;

int arr[maxn];

ll dp[maxn];

int n;

ll call(int i){

	if(i >= n-1){

		return 0;

	}

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

	ll ret = 1e11;

	if(i+1 <= n-1)ret = min(ret, abs(arr[i] - arr[i+1])+call(i+1));

	if(i+2 <= n-1)ret = min(ret, abs(arr[i] - arr[i+2]) + call(i+2));

	return dp[i] = ret;

}



int main(){

	//file

	scanf("%d", &n);

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

	memset(dp, -1, sizeof dp);

	cout<<call(0)<<endl;

}

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

using namespace std;



const int maxn = 1e5 + 5; 

int a[maxn];

long long dp[maxn];



int main(){

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

	int n;

	scanf("%d", &n);

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

		scanf("%d", &a[i]);

	}

	for(int i=0; i<=n; i++)dp[i] = 1e17;

	dp[1] = 0;

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

		if(i+1 <= n){

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

		}

		if(i+2 <= n){

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

		}

	}printf("%lld", dp[n]);

}

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

#include <algorithm>

using namespace std;



int main() {

  const long long INF = 1LL << 60;

  int h[100010];

  long long dp[100010];

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

  dp[0] = 0LL;



  int N;

  cin >> N;

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

    cin >> h[i];

  }



  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;

}


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

#include <algorithm>

using namespace std;



static const int INF = (1 << 30);

static const int MAX = 100010;



int main()

{

  int N;

  int DP[MAX + 1];

  int A[MAX];



  cin >> N;

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

  {

    cin >> A[i];

    DP[i] = INF;

  }



  DP[0] = 0;

  DP[N] = INF;



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

  {

    DP[i + 1] = min(DP[i + 1], DP[i] + abs(A[i + 1] - A[i]));

    DP[i + 2] = DP[i] + abs(A[i + 2] - A[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 rep(i,n) for(int i=0;i<n;i++)

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

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



int main() {

	

	

	

	int n; cin >> n;

	

	vector<int> a(n);

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

	//sort(a.begin(),a.end());

	

	

	//vector<int> cost(n,10000000);

	

	ll cost[100010];

	rep(i,100010) cost[i]=10000000000000;

	

	

	cost[0]=0;

	

	

	/*

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

		

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

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

	}

	*/

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

        chmin(cost[i], cost[i - 1] + abs(a[i] - a[i - 1]));

        if (i > 1) chmin(cost[i], cost[i - 2] + abs(a[i] - a[i - 2]));

    }







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

	return 0;



}

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

using namespace std;

#define ll long long

#define repl(i,n) for(ll i=0;i<n;i++)

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



const long double PI = (acos(-1));

const long double EPS = 0.0000000001;

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



int main() {

	

	

	cin.tie(0);

	ios::sync_with_stdio(false);

	

	int n; cin >> n;

	int ans;

	

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

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

	

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

	

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

		

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

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

		

		chmin(dp[i+1],dp[i]+d1);

		chmin(dp[i+2],dp[i]+d2);

	}

	

	ans=dp[n-1];

	

	cout << ans << "\n";

	

	return 0;

}





//vector<int> a(n);  sort(a.begin(),a.end());

//cout << "test" << "\n";





//g++ -o a a.cpp


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

using namespace std;

#define int long long



int memo[100005];



int f(int a[],int n)

{

    if(memo[n]!=-1)

       return memo[n];

       

    if(n==2)

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

    if(n==3)

        return min(abs(a[n-1]-a[n-3]),(abs(a[n-1]-a[n-2]) + abs(a[n-2]-a[n-3])));

    else

    {

        int res=min((f(a,n-1) + abs(a[n-1]-a[n-2])) , (f(a,n-2) + abs(a[n-1]-a[n-3])));

        memo[n]=res;

        return res;

    }

}

#undef int

int main()

{

 #define int long long

    int n;

    cin >> n;

    int a[n];

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

       cin >> a[i];



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

    cout << f(a,n) << endl;   

}

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

using namespace std;



int main() {

#define int long long

    int n;

    cin >> n;

    int h[n+1],dp[n+1];

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

    {

        cin >> h[i];

    }

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

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

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

}

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

using namespace std;

int main()

{

  int n,h[100005],dp[100005]={};

  cin>>n;

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

    cin>>h[i];

  }



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

    if(i==1){

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

    }else{

      if(abs(h[i]-h[i-1])+dp[i-1] > abs(h[i]-h[i-2])+dp[i-2]){

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

      }else{

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

      }

    }

  }

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

  return 0;

}


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

using namespace std;

int main()

{

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

  cin>>n;

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

    cin>>h[i];

  }

  dp[0]=0;

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

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

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

  }



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

  return 0;

}


// Fastest known solution for this problem: