stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

 

#define DEBUG if(1)

#define MAX INT_MAX

#define MAXLL INT_MAX

#define MAXU ULLONG_MAX

#define MIN -2000000

#define endl "\n"

#define INF INT_MAX

#define MOD 1000000007

#define s(n) scanf("%d", &n)

#define ss(a,b) scanf("%d %d",&a,&b)

#define pb push_back

#define mp make_pair

#define M_PI 3.14159265358979323846

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

#define lli long long int

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

#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef pair<lli,lli> ii;

#define DEBUG if(1)

#define F first

#define S second

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

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

int ddx[] = {1, 0};

int ddy[] = {1, 1};

#define MAXN 200010

#define MAXL 20



int n;

vi vec;



lli pd[MAXN][2];



lli solve(int i, int last){

	if(i == sz(vec) - 1) return 0;



	lli &ans = pd[i][last];

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



	lli a = INT_MAX, b = INT_MAX;

		a = solve(i+1, 1) + abs(vec[i] - vec[i+1]);



		if(i < sz(vec) - 2)

		b = solve(i+2, 2) + abs(vec[i] - vec[i+2]);



	return ans = min(a, b);

}



int main(){

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);



  cin >> n;

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

  	int a;

  	cin >> a;

  	vec.pb(a);

  }



  memset(pd, -1, sizeof pd);



  cout << solve(0, 0) << endl;



  return 0;

}

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

using namespace std;

 

#define DEBUG if(1)

#define MAX INT_MAX

#define MAXLL INT_MAX

#define MAXU ULLONG_MAX

#define MIN -2000000

#define endl "\n"

#define INF INT_MAX

#define MOD 1000000007

#define s(n) scanf("%d", &n)

#define ss(a,b) scanf("%d %d",&a,&b)

#define pb push_back

#define mp make_pair

#define M_PI 3.14159265358979323846

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

#define lli long long int

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

#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef pair<lli,lli> ii;

#define DEBUG if(1)

#define F first

#define S second

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

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

int ddx[] = {1, 0};

int ddy[] = {1, 1};

#define MAXN 200010

#define MAXL 20



int n;

vector<lli> vec;



lli pd[MAXN][2];



int main(){

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);



  cin >> n;

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

  	int a;

  	cin >> a;

  	vec.pb(a);

  }



  for(int i=0;i<=n;i++) for(int j=0;j<=2;j++) pd[i][j] = INT_MAX;



  pd[1][1] = abs(vec[1] - vec[0]);

	pd[2][2] = abs(vec[2] - vec[0]);



  for(int i=1;i<sz(vec);i++){



  	pd[i+1][1] = min(pd[i+1][1], pd[i][1] + abs(vec[i] - vec[i+1]));

  	pd[i+1][1] = min(pd[i+1][1], pd[i][2] + abs(vec[i] - vec[i+1]));

  	pd[i+2][2] = min(pd[i+2][2], pd[i][2] + abs(vec[i] - vec[i+2]));

  	pd[i+2][2] = min(pd[i+2][2], pd[i][1] + abs(vec[i] - vec[i+2]));



  }



 // for(int i=0;i<sz(vec);i++){

  //	for(int j=1;j<=2;j++) cout << pd[i][j] << " ";

  	//	cout << endl;

  //}



  cout << min(pd[n-1][1], pd[n-1][2]);



  return 0;

}

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

// vim:filetype=cpp:foldmethod=marker:foldmarker={{{,}}}



#include <cassert>

#include <cctype>

#include <cmath>

#include <climits>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <ctime>



#include <algorithm>

#include <deque>

#include <functional>

#include <iterator>

#include <list>

#include <map>

#include <numeric>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <utility>

#include <vector>



#include <fstream>

#include <iostream>

#include <sstream>



using namespace std;

// }}}



typedef long long int64;

const int INF = 0x3f3f3f3f;

template <class T> inline int len (const T &a) { return a.size (); }

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



const int MX = 100 * 1000 + 5;

int a [MX];

int dp [MX];



int

main () {

    int N;

    scanf ("%d", &N);

    for (int i = 0; i < N; i++) scanf ("%d", a + i);

    memset (dp, INF, sizeof (dp));

    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], dp [i - j] + abs (a [i] - a [i - j]));

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



#ifdef LOCALHOST

	cerr << "time: " << (int64) clock () * 1000 / CLOCKS_PER_SEC << " ms" << endl;

#endif

    return 0;

}




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

// vim:filetype=cpp:foldmethod=marker:foldmarker={{{,}}}



#include <cassert>

#include <cctype>

#include <cmath>

#include <climits>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <ctime>



#include <algorithm>

#include <deque>

#include <functional>

#include <iterator>

#include <list>

#include <map>

#include <numeric>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <utility>

#include <vector>



#include <fstream>

#include <iostream>

#include <sstream>



using namespace std;

// }}}



typedef long long int64;

const int INF = 0x3f3f3f3f;

template <class T> inline int len (const T &a) { return a.size (); }

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



const int MX = 100 * 1000 + 5;

int a [MX];

int dp [MX];



int

main () {

    int N;

    scanf ("%d", &N);

    for (int i = 0; i < N; i++) scanf ("%d", a + i);

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

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

        if (i >= 2)

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

    }

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



#ifdef LOCALHOST

	cerr << "time: " << (int64) clock () * 1000 / CLOCKS_PER_SEC << " ms" << endl;

#endif

    return 0;

}




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

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>

// #include <ext/pb_ds/tree_policy.hpp>

// #include <ext/pb_ds/assoc_container.hpp>

//#include <boost/multiprecision/cpp_int.hpp>

using namespace std;

//using namespace boost::multiprecision;

// using namespace __gnu_pbds;



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

#define endl "\n"

#define ff first

#define ss second

#define allr(c) (c).rbegin(),(c).rend()

#define fr(x,in,n,r) for(x=in;x<n;x+=r)

#define ifr(x,n) for(x=0;x<n;x++)

#define dfr(x,n) for(x=n;x>=1;x--)

#define pb(a) push_back(a)

#define pf(a) push_front(a)

#define pof(a) pop_front(a)

#define pob(a) pop_back(a)

#define eb(a) emplace_back(a)

#define ef(a) emplace_front(a)

typedef long long ll;

typedef map<ll,ll> mll;

typedef map<string,ll> msll;

typedef vector<ll> vll;

typedef pair<ll,ll> pll;

typedef long double ld;

#define mod 1000000007

#define N 100001



ll dp[N+2];



ll fun(ll a[],ll n)

{

	if(n==0 || n==1)

		return dp[n];

	if(dp[n]!=-1)

		return dp[n];

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

	return dp[n];

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

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

    ll n,i,j;

    cin>>n;

	ll a[n];

	ifr(i,N) dp[i]=-1;

	ifr(i,n)

		cin>>a[i];

	dp[0]=0;

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

	fun(a,n-1);

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

	return 0;

}

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

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>

// #include <ext/pb_ds/tree_policy.hpp>

// #include <ext/pb_ds/assoc_container.hpp>

//#include <boost/multiprecision/cpp_int.hpp>

//using namespace boost::multiprecision;

// using namespace __gnu_pbds;

using namespace std;



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

#define endl "\n"

#define ff first

#define ss second

#define allr(c) (c).rbegin(),(c).rend()

#define fr(x,in,n,r) for(x=in;x<n;x+=r)

#define ifr(x,n) for(x=0;x<n;x++)

#define dfr(x,n) for(x=n-1;x>=0;x--)

#define pb(a) push_back(a)

#define pf(a) push_front(a)

#define pof(a) pop_front(a)

#define pob(a) pop_back(a)

#define eb(a) emplace_back(a)

#define ef(a) emplace_front(a)

typedef long long ll;

typedef map<ll,ll> mll;

typedef map<string,ll> msll;

typedef vector<ll> vll;

typedef pair<ll,ll> pll;

typedef long double ld;

#define mod 1000000007



struct chash{ 

    ll operator()(ll x) const {return hash<ll>{}(x);}

};



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

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

    ll n,i,j;

    cin>>n;

    ll a[n];

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

    if(n==1){

       	cout<<"0\n";

       	return 0;

    }

    ll dp[n];

    dp[0]=0;

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

    fr(i,2,n,1)

    	dp[i]=min(dp[i-2]+abs(a[i-2]-a[i]),dp[i-1]+abs(a[i-1]-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 INF 1000000000

int dp(int i);

int n;

int h[100009],memo[100009];



int main(){

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

  cin>>n;

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

  cout<<dp(0)<<endl;

  return(0);

}



int dp(int i){

  int rec=INF;

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

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

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

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

  return memo[i]=rec;

}


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

using namespace std;

int dp[100009];



int main(){

  int n;

  int h[100009];

  cin>>n;

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

    cin>>h[i];

  }

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

    if(i-2>=0){

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

    }

    else if(i-1>=0){

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

    }

  }

  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 int 

const ll ARR = 1e5 + 2;

const ll INF = 1e4+2;

#define pb(x) push_back(x)

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

#define gof for(long long int i = 0 ; i < n ; i++)



void solve(){



	ll n;

	cin >> n;

	ll a[ARR];

	gof cin >> a[i];

	ll dp[ARR] = {INF};

	dp[0] = 0;

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

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

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

	}

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

	return;

}



int main(){

	ll t = 1;

	//cin >> t;

	while(t--){

		solve();

	}

	return 0;

}


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

using namespace std;



#define ll 				long long int

#define gof 			for(long long int i = 0 ; i < n ; i++)

#define for1(i,s,e) 	for(long long int i = s ; i < e ; i++)

#define forr(i,e,s) 	for(long long int i = e ; i >= s; i--)

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

#define vi 				vector<long long int>

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

#define pb(x) 			push_back(x)

#define maxv(x) 		*max_element(x)

#define minv(x) 		*min_element(x)

#define mkvec(type,a,n) vector<type> a(n)



const ll ARR = 1e5;

const ll INF = 1e9;

const ll mod = 1e9+7;



void IO()

{

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

#ifndef ONLINE_JUDGE

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

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

#endif

}



void solve(){



	int n;

	cin >> n;

	ll a[ARR+2];

	gof cin >> a[i];



	ll dp[ARR+2];

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



	for1(i,2,n){

		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] << "\n";



}



int main(){

	IO();

    ll t = 1;

    //cin >> t;

    while(t--) solve();

    return 0;

}






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

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

using namespace std;

typedef long long ll;

typedef pair<int,int> P;

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 = 1000000000;



ll dp[100001];



int main(void){

  int n; cin >> n;

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

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

  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;

  return 0;

}


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

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

using namespace std;

typedef long long ll;

typedef pair<int,int> P;



ll f[100005];



void saisho(ll h[],ll n){

  int i;

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

    if(i == 0){

      f[0] = 0;

    }

    else if(i == 1){

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

    }

    else{

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

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

      }

      else{

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

      }

    }

  }

}



int main(void){

  ll n; cin >> n;

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

  saisho(h,n);

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

  return 0;

}


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

using namespace std;

long long int dp[1000000];

int main(void)

{

	long long int n;

	cin>>n;

	long long int a[n], i;

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

	{

		cin>>a[i];

	}

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

		dp[i]=-1;

	if(n==2)

	{

		cout<<abs(a[0]-a[1])<<endl;

		return 0;

	}

	dp[0]=a[0];

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

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

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

	{

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

	}

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

	return 0;

	



}

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

#define ll long long int

#define pb push_back

#define mp make_pair

#define ff first

#define ss second

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

using namespace std;

int main(void)

{

	ll n;

	cin>>n;

	ll a[n], i;

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

		cin>>a[i];

	ll ans[n];

	ans[n-1] = 0;

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

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

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

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

}		

// Fastest known solution for this problem:
// Original C++ solution (slower):
// 10/06/19 // 10:03 AM //



#include <iostream>

#include <cmath>

#include <cstring>



using namespace std;



#define MAXN 100010



int n;

int h[MAXN];

int memo[MAXN];



int funcao(int i){

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



    if(i>=n) return 0;



    if(i==n-1)

        return memo[i] = abs(h[i]-h[i+1])+funcao(i+1);



    return memo[i] = min(abs(h[i]-h[i+1])+funcao(i+1),abs(h[i]-h[i+2]) + funcao(i+2));

}



int main(){



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



    cin >> n;



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



    cout << funcao(1) << "\n";



    return 0;

}


// Optimized solution to the same problem (faster):
// 14/06/19 // 02:02 AM //



#include <iostream>

#include <cmath>



using namespace std;



#define MAXN 100010



int n;

int h[MAXN];

int memo[MAXN];



int bottom_up(){



    memo[0] = MAXN;



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

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

    }



    return memo[n];

}



int main(){



    cin >> n;



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



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



    return 0;

}




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

using namespace std;

int n;

int dpt[100001];

vector<int> h;

int frog(int i){

	if(i<=1)

		return 0;

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

			return dpt[i];

		}

	if(i>2)

		return dpt[i]=min(frog(i-1)+abs(h[i]-h[i-1]),frog(i-2)+abs(h[i]-h[i-2]));

	if(i==2){

		return dpt[i]=frog(i-1)+abs(h[i]-h[i-1]);

	}

}



int main(){

	cin>>n;

	h.push_back(0);

	int k;

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

		cin>>k;

		h.push_back(k);

	}

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

		dpt[i]=-1;

	cout<<frog(n);

}

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

using namespace std;

int main(){

  int n; cin>>n;

  int arr[n];

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

  int ans[n]; ans[0]=0; ans[1]=abs(arr[1]-arr[0]);

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

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

  }

  cout<<ans[n-1];

  return 0;

}

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

using namespace std;

int main()

{

  int n;

  int h[100005] = {};

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

  }

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

  return 0;

}


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

using namespace std;

#define ll long long

int main()

{

  int dp[100005],h[100005];

  int n;

  cin >> n;

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

  

  dp[0] = 0;

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



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

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

  }



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

  return 0;

}


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

#include <bits/c++io.h>

#include <vector>

#include <tuple>

#include <queue>

#define N 100

#define INF 1e9 + 5

using namespace std;



int solve(int k, vector<int> &c,vector<int> &dp){

    

    if(k==1){

        return 0;

    }

    if(k<1){

        return INF;

    }

    if(dp[k]) return dp[k];

    return dp[k] = min( solve(k-1,c,dp)+abs(c[k]-c[k-1]), solve(k-2,c,dp)+abs(c[k]-c[k-2]));

}





int main()

{

    int n;

    scanf("%d", &n);

    vector<int> v(n+1);

    vector<int> dp(100001,INF);

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

    {

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

    }

    //재귀로 풀어봅시다. 

    //solve 는 n일 때 최소가 되는 값을 반환하는 함수라고 합시다. 

    

    // printf("%d",solve(n, v, dp));



    //선형으로 풀어봅시다.

    dp[0]=0; 

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

        for(auto j:{i+1,i+2}){

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

        }

    }

    cout<<dp[n-1];

    return 0;

}

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

#include <bits/c++io.h>

#include <vector>

#include <tuple>

#include <queue>

#define N 100

#define INF 1e9 + 5

using namespace std;



#include <iostream>

#include <bits/c++io.h>

#include <vector>

#include <tuple>

#include <queue>

#define N 100

#define INF 1e9 + 5

using namespace std;

 

int solve(int k, vector<int> &c,vector<int> &dp){

    

    if(k==1){

        return 0;

    }

    if(k<1){

        return INF;

    }

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

    

    return dp[k] = min( solve(k-1,c,dp)+abs(c[k]-c[k-1]), solve(k-2,c,dp)+abs(c[k]-c[k-2]));

}

//20          10

//10 30     20



int main()

{

    int n;

    scanf("%d", &n);

    vector<int> c(n+1);

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

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

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

    }

    //재귀로 풀어봅시다. 

    //solve 는 n일 때 최소가 되는 값을 반환하는 함수라고 합시다. 

    dp[0]=INF;

    printf("%d",solve(n, c, dp));

    //선형으로 풀어봅시다.

    // dp[0]=0; 

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

    //     for(auto j:{i+1,i+2}){

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

    //     }

    // }

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



    return 0;

}


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



using namespace std;



#define el				'\n'

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

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

#define clr(v, d)		memset(v, d, sizeof(v))



double const EPS = 1e-8, PI = acos(-1);

const int N = 1e5 + 9, M = 1e5 + 9, OO = (int) 1e6 + 1;

const long long MOD = 1e9 + 7;



typedef long long ll;



void OUTPUT() {

	cout << fixed << setprecision(0);

	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

}



void READ() {

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

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

}

int n, heights[N], mem[N];



ll dp(int i) {

	if (i >= n)

		return OO;

	if (i == n - 1)

		return 0;

	if (mem[i] != -1)

		return mem[i];

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

	ll b = dp(i + 2) + abs(heights[i] - heights[i + 2]);

//	cout << i << " " << a << " " << b << el;

	mem[i] = min(a, b);

	return mem[i];



}



int main() {

//	READ();

	OUTPUT();

	clr(mem, -1);

	cin >> n;

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

		cin >> heights[i];

	}

	cout << dp(0);



	return 0;



}


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

#include <bits/c++io.h>

#include <vector>

#include <tuple>

#include <queue>

#define N 100

#define INF 1e9 + 5

using namespace std;



#include <iostream>

#include <bits/c++io.h>

#include <vector>

#include <tuple>

#include <queue>

#define N 100

#define INF 1e9 + 5

using namespace std;

 

int solve(int k, vector<int> &c,vector<int> &dp){

    

    if(k==1){

        return 0;

    }

    if(k<1){

        return INF;

    }

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

    

    return dp[k] = min( solve(k-1,c,dp)+abs(c[k]-c[k-1]), solve(k-2,c,dp)+abs(c[k]-c[k-2]));

}

//20          10

//10 30     20



int main()

{

    int n;

    scanf("%d", &n);

    vector<int> c(n+1);

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

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

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

    }

    //재귀로 풀어봅시다. 

    //solve 는 n일 때 최소가 되는 값을 반환하는 함수라고 합시다. 

    dp[0]=INF;

    printf("%d",solve(n, c, dp));

    //선형으로 풀어봅시다.

    // dp[0]=0; 

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

    //     for(auto j:{i+1,i+2}){

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

    //     }

    // }

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



    return 0;

}


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

using namespace std;

#define ll long long

#define ld  double

#define mod 998244353

//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int n;

int arr[100000+9];

ll dp[100000][2];

ll solve(int ind , int last) {

    if (ind+1 == n) {

        return 0;

    }

    if(dp[ind][last] != -1)

        return dp[ind][last];

    ll a = 1e10;

    if (ind + 1 < n)

        a = min(a, solve(ind + 1, 0) + abs(arr[ind] - arr[ind + 1]));

    if (ind + 2 < n) {

        a = min(a, solve(ind + 2, 1) + abs(arr[ind + 2] - arr[ind]));

    }

    return dp[ind][last] = a;

}

int main() {

    cin>>n;

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

        cin>>arr[i];

    }

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

    cout<<solve(0,0);

    return 0;

}


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

#define ll long long

using namespace std;

int dp[100000+9];

int main(){

    int n;

    scanf("%d",&n);

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

    }

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

    return 0;

}

// Fastest known solution for this problem: