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

using namespace std;

#define ll long long

#define vi vector<int>

#define pb push_back

#define pii pair<int , int>

#define fast ios_base::sync_with_stdio(0)

#define mx 100005

#define inf 100000000000000000LL

ll arr[mx], dp[mx];

int n;

ll solve(int pos)

{

    if(pos==n) return 0;

    ll&ret = dp[pos];

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

    ret = inf;

    ret = min(ret, llabs(arr[pos] - arr[pos+1]) + solve(pos+1));

    if(pos+1 != n)ret = min(ret, llabs(arr[pos] - arr[pos+2]) + solve(pos+2));

    return ret;

}

int main()

{

    //fast;

    while(scanf("%d",&n)){

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

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

        memset(dp, -1, sizeof dp);

        printf("%lld\n", solve(1));

        return 0;

    }

}




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

using namespace std;

#define ll long long

#define vi vector<int>

#define pb push_back

#define pii pair<int , int>

#define fast ios_base::sync_with_stdio(0)

#define mx 100005

#define inf 100000000000000000LL

ll arr[mx], dp[mx];

int main()

{

    int n;

    while(scanf("%d",&n)){

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

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

        dp[n] = 0;

        dp[n-1] = llabs(arr[n] - arr[n-1]);

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

            dp[i] = min(dp[i+1] + llabs(arr[i]-arr[i+1]), dp[i+2] + llabs(arr[i] - arr[i+2]));

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

        return 0;

    }

}




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

using namespace std;



const int mx = 1e9+5;

int m[100005];

int T[100005];



// 10 30 40 20

// 0   1  2  3

//    10  20

int minHeightIncurred(int i , int n ,int val , int *res)

{

	if(T[i] != -1)

	{

		if(val + T[i] < *res)

			*res = val + T[i];

				

		return *res;

	}

	else

	{

		int k =0 , t =val; // preserving 

		if(i<n-1)

		{

			k = abs(m[i] - m[i+1]);

			val = minHeightIncurred(i+1 , n , val + k , res);

		}

			

		if(i<n-2)

		{

			k =  abs(m[i] - m[i+2]);

			val = t;	

			val = minHeightIncurred(i+2 , n , val + k , res);

		}

		



		// Here 'val' contains the min. val for each path

		if(*res>val)

		{

			*res =val;

		}

		else

		{

			T[i] = abs(val - t);

		}



		return *res;

	}

}





int main()

{

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);



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



	int n;

	cin>>n;



	int res = mx;	

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

	{

		cin>>m[i];

	}



	minHeightIncurred(0 , n , 0 , &res); // INDEX , SIZE  , JMP_VAL

	cout<<res<<"\n";

}



//END


















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

using namespace std;



const int INF = 1e9+5;



int main()

{

	int n;

	scanf("%d",&n);

	vector<int> h(n);



	for(int &x : h)

		scanf("%d",&x);



	vector<int> dp(n , INF);



	dp[0] = 0;

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

	{

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

		{

			if(j<n)

			{

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

			}

		}

	}



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

}







//END


























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

using namespace std;

#define ll long long



const ll INF= 1LL << 60;



//入力

ll N;

ll h[100010];

//dp

ll dp[100010];





void min(ll& a, ll& b){

  if(a<b){

    a=b;

  }

}



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=1;i<N;i++){

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

    if(i>1) dp[i]=min(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,m,n) for(int (i)=(int)(m);i<(int)(n);i++)

#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)

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

#define REP2(i,n) rep2(i,0,n)

#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)

#define ll long long

#define ull unsigned long long

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

#define en '\n'

template <class T> using vec = vector<T>;

template <class T> using vvec = vector<vec<T>>;

typedef pair<ll, ll> P;

constexpr long long INF = 1LL << 60;

constexpr int INF_INT = 1 << 25;

constexpr long long MOD = (ll) 1e9 + 7;

typedef vector<ll> Array;

typedef vector<Array> Matrix;

constexpr int loose = 0;

constexpr int tight = 1;





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;

}



struct Edge {

	ll to, cap, rev;

	Edge(ll _to, ll _cap, ll _rev) {

	to = _to; cap = _cap; rev = _rev;

	}

};

typedef vector<Edge> Edges;

typedef vector<Edges> Graph;



void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {

	G[from].push_back(Edge(to, cap, (ll)G[to].size()));

	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));

}



void solve(){

	ll n;

	cin>>n;

	Array h(n);

	REP(i,n) cin>>h[i];

	

	Array dp(n+1,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]<<en;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);



    solve();

    return 0;

}

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

using namespace std;

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

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

#define lscn(n) scanf("%lld",&n)

typedef long long ll;

#define pri(n) printf("%d\n",n)

#define lpri(n) printf("%lld\n",n);

#define rep(i,st,ed) for(int i=st;i<ed;i++)

#define F first

#define S second 

#define pb(n) push_back(n)

const int N=2e5+6;

const ll M=1e9+7;

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

void  rec(int i)

{

	// printf("i= %d\n",i);

	if(dp[i]!=-1)

	{

		// printf("reached here1\n");

		return ;

	}

	

	if(i>=n-1)

	{

		dp[i]=0;

		// printf("reached here2 %d %d\n",i,n-1);

		return ;

	}

	ll ans1=1e18;

	ll ans2=1e18;

	if(i+1<n)

	{

		rec(i+1);

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

	}

	

	if(i+2<n)

	{

		rec(i+2);

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

	}

	// printf("for i= %d and n= %lld ans 1 = %lld ans2 = %lld\n",i,n,ans1,ans2);	

	dp[i]=min(ans1,ans2);

}

int main()

{

	lscn(n);

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

		lscn(a[i]);

	

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

	

	rec(0);

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

	// 	printf("%lld ",dp[i]);

	lpri(dp[0]);

}

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

using namespace std;

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

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

#define lscn(n) scanf("%lld",&n)

typedef long long ll;

#define pri(n) printf("%d\n",n)

#define lpri(n) printf("%lld\n",n);

#define rep(i,st,ed) for(int i=st;i<ed;i++)

#define var(n) int n; scn(n)

#define F first

#define S second 

#define pb push_back

const int N=1e6+5;

// const ll M = 998244353;

const ll M=1e9+7;

const ll inf=1e18;







int main()

{

	var(n);

	int a[n],dp[n];

	rep(i,0,n)

	{		

		scn(a[i]);

	}

	dp[0]=0;

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

	for(int 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]));

	}

	pri(dp[n-1]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/*author  ADITYA BANSAL

         MNNIT ALLAHABAD     */

#include<bits/stdc++.h>

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

//using namespace boost::multiprecision; 

using namespace std;

#define ll long long

ll power(ll,ll);

ll mul(ll a,ll b);

#define watch(x) cerr<<(#x)<<"is"<<x<<nl;

#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define fi(a,b) for(ll i=a; i<b; i++)

#define fk(a,b) for(ll k=a; k<b; k++)

#define fri(a,b) for(ll i=a; i>b; i--)

#define fj(a,b) for(ll j=a; j<b; j++)

#define ffi(a,b) for(ll i=a;i*i<=b;i++)

#define mp make_pair

#define ff first 

#define  tc ll t; cin>>t; while(t--)

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

#define ss second

#define pb push_back

#define mem(v) memset((v),0,sizeof(v));

#define pll pair<ll,ll>

#define mll map<ll,ll>

#define sll set<ll>

#define vll vector<ll>

#define max3(a,b,c) max(a,max(b,c))

#define min3(a,b,c) min(a,min(b,c))

#define ad(a,b)  (a%mod+b%mod+mod)%mod

#define pob pop_back

#define nl endl

const int mod=1e9+7;

const ll  N=100002LL;



signed main(){ fast

  

  

  

   //tc

  // calc();

 {   ll h[100001],n;

	 ll dp[100001];

	 mem(dp)

	 cin>>n;

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

	 

	 dp[1]=0;

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

	

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

	

	fi(1,n+1) cerr<<dp[i]<<" "; 

	 cout<<dp[n]<<nl;

	  

 }

    return 0;

}





/******************************************************************************/



ll mul(ll a,ll b){

    return ((a)*1LL*(b))%13;

}



ll power(ll a,ll n){

  ll res=1;

  while(n){

      if(n&1) res= mul(res,a);

     n>>=1; 

     a= mul(a,a);

  }

    return res;

}


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

using namespace std;



#define ll  int

#define intmax INT_MAX

#define pi 3.14159265358979323846

#define ff first 

#define ss second

#define pb push_back

#define watch(x) cerr<<(#x)<<"  "<<x<<"\n";

const int MOD=998244353;

const int MAXN = 3e5+4;

int dp[MAXN],a[MAXN];



int main(){	

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



int n; cin>>n;

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

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

for(int i=3;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]<<"\n";





return 0;

}


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

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

#define sf2(n,q) scanf("%d %d",&n,&q)

#define f first

#define ss second

#define pb push_back

#define lli long long

#define mem(ar,false) memset(ar,false,sizeof(ar))

#define mpr make_pair

#define endl "\n"

#define mod 1000000007

#define inf 9000000000000000000LL

using namespace std;



int ar[200005];

int n;

int dp[100005];

int func(int i)

{

    if(i==n-1)

        return 0;

    if(dp[i]!=-1)

        return dp[i];

    int ret1 = INT_MAX;

    int ret2 = INT_MAX;



    ret1 = abs(ar[i]-ar[i+1]) + func(i+1);

    if(i+2<n)

        ret2 = abs(ar[i]-ar[i+2]) + func(i+2);

    return dp[i] = min(ret1,ret2);

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    mem(dp,-1);

    cin >> n;

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

        cin >> ar[i];



    int ans = func(0);



    cout << ans << endl;

    return 0;



}


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

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

#define sf2(n,q) scanf("%d %d",&n,&q)

#define f first

#define ss second

#define pb push_back

#define lli long long

#define mem(ar,false) memset(ar,false,sizeof(ar))

#define mpr make_pair

#define endl "\n"

#define mod 1000000007

#define inf 9000000000000000000LL

using namespace std;



int ar[200005];

int n;

int dp[100005];

int func(int i)

{

    if(i==n-1)

        return 0;

    if(dp[i]!=-1)

        return dp[i];

    int ret1 = INT_MAX;

    int ret2 = INT_MAX;



    ret1 = abs(ar[i]-ar[i+1]) + func(i+1);

    if(i+2<n)

        ret2 = abs(ar[i]-ar[i+2]) + func(i+2);

    return dp[i] = min(ret1,ret2);

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

  //  mem(dp,-1);

    cin >> n;

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

        cin >> ar[i];



   // int ans = func(0);

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

    {

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

        int ret2 = INT_MAX;

        if(i-2>=0)

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

        dp[i] = min(ret1,ret2);

    }



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

    return 0;



}


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

#include <cstring>

using namespace std;

int dp[100000];

int n,a[100000];



int ans2(int i)

{

	if(i==n-1)

		return 0;



	if(i==n-2)

		return abs(a[i]-a[i+1]);



	if(dp[i]!=-1)

		return dp[i];



	int p = abs(a[i]-a[i+1]) + ans2(i+1);

	int q = abs(a[i]-a[i+2]) +ans2(i+2);



	return dp[i]=min(p,q);

}



int main()

{

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

	cin>>n;

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

		cin>>a[i];



	cout<<ans2(0);



	return 0;

}

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

using namespace std;

int dp[100000];

int n,a[100000];



int topdown()

{

	dp[n-1]=0;

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



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

	{

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

	}

	return dp[0];

}



int main()

{

	cin>>n;

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

		cin>>a[i];



	cout<<topdown();



	return 0;

}

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

using namespace std;

int dp[int(1e5) + 2];

int main()

  {int N; cin >> N;

  vector<int> hs(N); for (auto &h : hs) cin >> h;

  for (auto &i : dp) i = 1e9;

  dp[1] = 0;

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

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

    if (i + 1 < N) dp[i + 2] = min(dp[i + 2], dp[i] + abs(hs[i - 1] - hs[i + 1]));}

  cout << dp[N] << endl;}

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

using namespace std;

int main()

  {int N; cin >> N;

  vector<int64_t> dp(N, 1e15), hs(N); dp[0] = 0; for (auto &h : hs) cin >> h;

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

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

    if (i + 2 < N) dp[i + 2] = min(dp[i + 2], dp[i] + abs(hs[i] - hs[i + 2]));}

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

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

#include<bits/stdc++.h>

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

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

#define fr(i,a,b) for(i=a;i>=b;i--)

#define endl '\n'

#define ll long long int

#define ff first

#define ss second

#define pb push_back

#define mod 1000000007

#define M 998244353

using namespace std;



ll n,h[100005],dp[100005][2];



ll fun(int i,int p)

{

	if(i==n-1)

		return 0;

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

		return dp[i][p];

	if(i>=n)

		return 1e9;

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

}



int main()

{

    fast; 

    int i;

    cin>>n;

    f(i,0,n)

    	cin>>h[i];

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

    cout<<min(fun(0,1),fun(0,2));

}


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

#include<bits/stdc++.h>

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

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

#define fr(i,a,b) for(i=a;i>=b;i--)

#define endl '\n'

#define ll long long int

#define ff first

#define ss second

#define pb push_back

#define mod 1000000007

#define M 998244353

using namespace std;



int main()

{

    fast; 

    ll n,h[100005],dp[100005],i;

    cin>>n;

    f(i,0,n)

    	cin>>h[i];

    dp[0]=0;

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

    f(i,2,n)

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

#include <stdlib.h>



int min(int val1, int val2)

{

    if (val1 > val2)

        return val2;

    return val1;

}



int main(void)

{

    using namespace std;

    

    int n;

    cin >> n;



    vector<int> vec(n + 1);

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

        cin >> vec.at(i);

    

    vector<int> dp(n + 1);

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

        dp.at(i) = 10000;



    dp.at(0) = 0;

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

    {

        int cost1 = dp.at(i - 1) + abs(vec.at(i - 1) - vec.at(i));

        int cost2 = 10000;

        if (i > 1)

            cost2 = dp.at(i - 2) + abs(vec.at(i - 2) - vec.at(i));

        

        dp.at(i) = min(cost1, cost2);

    }



    cout << dp.at(n - 1) << endl;

}

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

#include<climits>

using namespace std;



/*int memo[1000];

int compute(int a[],int n,int st){

	if(st==n-1)

		return 0;

	if(st>=n)

		return 0;



	int q1=10000,q2=10000;

	if(st-1<=n-1){

		q1=abs(a[st]-a[st+1])+compute(a,n,st+1);

		//cout<<q1<<" "<<st<<endl;

	}

	if(st-2<=n-1)

	{

		q2=abs(a[st]-a[st+2])+compute(a,n,st+2);

		//cout<<q2<<" "<<st<<endl;

	}

	return min(q1,q2);

}

int compute_memo(int a[],int n,int s){

	if(s==0)

	{

		memo[s]=0;

		return 0;

	}

	int q1=10000;

	int q2=10000;

	if(memo[s]!=-1)

		return memo[s];

	if(s-1>=0){

		q1=abs(a[s]-a[s-1])+compute_memo(a,n,s-1);

	}

	if(s-2>=0)

	{

		q1=abs(a[s]-a[s-2])+compute_memo(a,n,s-2);

	}

	cout<<s<<" "<<q1<<" "<<q2<<endl;

	memo[s]=min(q1,q2);

	return memo[s];

}*/

int dp_compute(int a[],int n){

	int dp[100009]={};

	dp[0]=0;

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

		int q1=INT_MAX,q2=INT_MAX;

		if(i-1>=0)

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

		if(i-2>=0)

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

		dp[i]=min(q1,q2);

	}

	return dp[n-1];

}



int main(){

	int n;

	cin>>n;

	int a[100009];

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

		cin>>a[i];

	}

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

	return 0;

}






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

using namespace std;

#define ll  long long

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

#define endl '\n'

#define mod 1000000007



void inp()

{

    #ifndef ONLINE_JUDGE

    // for getting input from input.txt

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

    // for writing output to output.txt

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

    #endif

} 

ll min(ll a,ll b)

{

    if(a<b)

        return a;

    else

        return b;

}

 

ll max(ll a,ll b)

{

    if(a>b)

        return a;

    else

        return b;

}

int main() {

    //inp();

    fio;

    ll n;

    cin>>n;



    vector<int> nums(n);

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

    {

    	cin>>nums[i];

    }



    vector<int> dp(n,INT_MAX);

    dp[0]=0;

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

    {

    	if(i-1>=0)

    	{

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

    	}

    	if(i-2>=0)

    	{

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

    	}

    }

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



    return 0;

}

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

#include <cmath>

#include <cstring>

#include <string>



using namespace std;



#define MAXN 100005



int h[MAXN], dp[MAXN];



int solve(int n) {

	if(n == 1) return 0;

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

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

	if(n > 2) {

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

	}

	return dp[n];

}



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0);

	

	int n;

	cin >> n;

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

		cin >> h[i];

	}

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

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

	

	return 0;

}

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

#include <cmath>

#include <cstring>

#include <string>



using namespace std;



#define MAXN 100005



int h[MAXN], dp[MAXN];



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0);

	

	int n;

	cin >> n;

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

		cin >> h[i];

	}

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

	

	return 0;

}

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

using namespace std;

int n;

int a[100009];

int res[100009];

/*lets try to understand how to write recursive eqn for the current problem

 mincost(i,n)={min(a[i+1]-a[i]+mincost(i+1,n),a[i+2]-a[i]+mincost(i+2,n)) if i<n

                  ,0 if i>=n}         

 */

int mincost(int i)

{

   if(res[i]>=0)

	   return res[i];

  		if(i>=n)

		 return 0;

	

	

  if(i<n-1)

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

  else

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

 return res[i]; 

}

int main()

{  

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

    res[i]=-1;

	cin>>n;

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

		cin>>a[i];

	 cout<<mincost(1);

}


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

using namespace std;

int main()

{

  int n,i,sum=0;

  cin>>n;

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

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

      cin>>a[i];

  dp[1]=0;

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

  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]<<endl;

}


// Fastest known solution for this problem: