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

using namespace std;

int dp[100005];

int H[100005];

void memo(int i,int n)

{

	if(i==n) return;

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

	memo(i+1,n);

}

int main()

{

	int N;cin>>N;

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

	{

        cin>>H[i];

	}

	memset(dp,0,sizeof(dp));

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

	memo(2,N);

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

	return 0;

}

// Optimized solution to the same problem (faster):
//动态规划青蛙跳

#include <stdio.h>

#include <math.h>

#include <algorithm>



using namespace std;



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



int main()

{

	scanf("%d",&n);

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

	{

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

	}

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

	{

		if(i == 1)

		{

			dp[i] = 0;

		}

		else if(i == 2)

		{

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

		}

		else

		{

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

		}

	}

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

	return 0;

}

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

using namespace std;

#define ff first

#define ss second

#define ll long long int

#define pii pair<int,int>

#define pll pair<ll,ll>

#define mem(x) memset(x, 0, sizeof x)

#define mem1(x) memset(x, -1, sizeof x)

#define MX 100005

ll arr[MX], dp[MX],n;

//ll rec(ll i, ll score)

//{

//    if(i==n-1) return score;

//    else if(i>=n) return 1e9;

//    else if(dp[i]<score && dp[i]!=-1) return dp[i];

//    else if(!i || dp[i]==-1 || score<dp[i])

//    {

//        ll ret1=1e9, ret2=1e9;

//        if(i+1<=n-1) ret1= rec(i+1, score+llabs(arr[i+1]-arr[i]));

//        if(i+2<=n-1) ret2= rec(i+2, score+llabs(arr[i+2]-arr[i]));

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

//    }

//}

int main()

{

    ll i,j,k,l, m;

    scanf("%lld",&n);

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

    for(i=1; i<n; i++) dp[i]=1e9;

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

    {

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

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

    }

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

    return 0;

}


// Optimized solution to the same problem (faster):
//动态规划青蛙跳

#include <stdio.h>

#include <math.h>

#include <algorithm>



using namespace std;



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



int main()

{

	scanf("%d",&n);

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

	{

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

	}

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

	{

		if(i == 1)

		{

			dp[i] = 0;

		}

		else if(i == 2)

		{

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

		}

		else

		{

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

		}

	}

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

	return 0;

}

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

using namespace std;



int a[110000];

int m[110000];

int n;



int dp(){

	m[0] = 0;

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

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

		m[i] = min(

			(m[i-1] + abs(a[i] - a[i-1])),

			(m[i-2] + abs(a[i] - a[i-2]))

		);	

	}

	return m[n-1];

}



int main(){

	cin>>n;

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

		cin>>a[i];

	}

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

	return 0;

}

// Optimized solution to the same problem (faster):
//动态规划青蛙跳

#include <stdio.h>

#include <math.h>

#include <algorithm>



using namespace std;



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



int main()

{

	scanf("%d",&n);

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

	{

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

	}

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

	{

		if(i == 1)

		{

			dp[i] = 0;

		}

		else if(i == 2)

		{

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

		}

		else

		{

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

		}

	}

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

	return 0;

}

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

#include<iostream>

#include<algorithm>

#include<cstring>

#include<queue>

#include<cmath>

using namespace std;

const int maxn = 1e5 + 5;

int main()

{

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

	scanf("%d",&n);

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

	dp[1] = 0,dp[2] = fabs(a[1] - a[2]),dp[3] = fabs(a[1] - a[3]);

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

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

		else dp[i + 2] = dp[i + 1] + fabs(a[i + 2] - a[i +1]);

	}

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

	return 0;

}

// Optimized solution to the same problem (faster):
//动态规划青蛙跳

#include <stdio.h>

#include <math.h>

#include <algorithm>



using namespace std;



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



int main()

{

	scanf("%d",&n);

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

	{

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

	}

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

	{

		if(i == 1)

		{

			dp[i] = 0;

		}

		else if(i == 2)

		{

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

		}

		else

		{

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

		}

	}

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

	return 0;

}

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



using namespace std;



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

int arr[(int)1e5 + 1];



int main() {

	

	ios_base::sync_with_stdio(0);

	cin.tie(0);



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

	}



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



	return 0;

}

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

#include <cstring>

#include <algorithm>

#include <cmath>

using namespace std;

int n,a[100005],f[100005];

int main()

{

	scanf("%d",&n);

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

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

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

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

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

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

	return 0;

}

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

using namespace std;

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

int main(){

	cin>>n;

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

	f[1]=0;

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

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

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

	}

	cout<<f[n];

	return 0;

}

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

#include <cstring>

#include <algorithm>

#include <cmath>

using namespace std;

int n,a[100005],f[100005];

int main()

{

	scanf("%d",&n);

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

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

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

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

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

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

	return 0;

}

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



using namespace std;



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

int main()

{



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







    fill(dp, dp+(int)1e5+5 , INT_MAX );



    dp[1] = 0;

    int n;

    cin>>n;

    vector <int> v(n+3,0);

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



        cin>>v[i];



    }

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



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

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



    }

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

}


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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

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

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

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

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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



using namespace std;



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

#define DB( x ) cout << #x << " = " << x << endl;

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

#define endl '\n'



typedef long long ll;

typedef unsigned long long ull;

typedef pair<ll, ll> pii;

typedef pair<int, pii> tri;

typedef vector <vector <ll>> matrix;

typedef pair<string, string> pss;



const ll mod = (ll)1e9 + 7;

const int MAX = (int)1e6 + 100;



const ll oo = 0x3f3f3f3f3f3f3f3f;



ll dp[MAX], a[MAX];



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    memset(dp, oo, sizeof(dp));



    int n; cin >> n;



    dp[1] = 0;



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

        cin >> a[i];

    }



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

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

        if(i - 2 >= 1){

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

        }

    }



    cout << dp[n] << endl;

}


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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

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

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

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

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
/*|In The Name Of Allah|*/



#include <bits/stdc++.h>



using namespace std;



const int N = 1e5+5;



int n;

int h[N];

int mem[N];



int go(int idx){

    if(idx >= n)

        return 0;

    if(mem[idx] != -1)

        return mem[idx];

    int best = 1e9;

    if(idx + 1 <= n)

        best = go(idx + 1) + abs(h[idx] - h[idx + 1]);

    if(idx + 2 <= n)

        best = min(best , go(idx + 2)  + abs(h[idx] - h[idx + 2]));

    return mem[idx] = best;

}



int main(){

    scanf("%d" , &n);

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

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

    }

    memset(mem , -1 , sizeof mem);

    printf("%d\n" , go(1));

}

//1 2 3


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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

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

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

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

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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

#include <queue>

typedef long long ll;



using namespace std;



const int N=1e5+5;





int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

   int n,k=2;

   cin>>n;

   int arr[N]={},dp[N]={};

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

    cin>>arr[i];

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

   dp[0]=0;

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

   {



     for(int j=1;j<=k;j++)

     {

         if(i-j>=0)

         {

             if(dp[i]==-1)

             {

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

             }

             else

             {

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





             }





         }



     }









   }

   cout<<dp[n-1];



   return 0;

}


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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

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

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

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

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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

#define pii pair<int,int>

#define vi vector<int>

#define ppii pair<pii>



using namespace std;

const int maxn=1e5+5;



int n;

vi arr;

int dp[maxn];



int dfs(int pos)

{

    if(pos==n){return 0;}



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



    int ans=(1<<29);



    if(pos<n)

        ans=min(ans,dfs(pos+1) + abs(arr[pos]-arr[pos+1]));

    if(pos<n-1)

        ans=min(ans,dfs(pos+2) + abs(arr[pos]-arr[pos+2]));

    dp[pos]=ans;



    return ans;

}



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);cout.tie(0);



    cin>>n;



    arr=vi(n+1);



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

        cin>>arr[i];



    memset(dp,-1,sizeof dp);



    cout<<dfs(1);



    return 0;

}


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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

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

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

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

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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

using namespace std;



typedef long long ll;

#define mp make_pair

#define f first

#define s second

#define pb push_back



const int inf = 1e7;

const int N  = 1e5 + 5;



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

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



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



int solve(int idx) {



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



  int &ret = dp[idx];



  if(ret!=-1) return ret;



  ret = solve(idx+1) + abs(h[idx]-h[idx+1]);



  if(idx!=n-2)

    ret = min(ret,solve(idx+2) + abs(h[idx]-h[idx+2]));



  return ret;



}



int main() {



    ios_base::sync_with_stdio(false);

    cin.tie(0);



    cin >> n;



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



      cin >> h[i];



    }



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



    cout << solve(0) << endl;



    return 0;

}


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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

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

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

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

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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

using namespace std;



const int nax = 1e5+3;

int n;

int dp[nax];

int a[nax];

int f(int i){

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

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

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

	if(i!=n-2) ans = min(ans, abs(a[i]-a[i+2])+f(i+2));

	return dp[i]=ans;

}

int main(){

	cin>>n;

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

	memset(dp, -1, sizeof dp);

	cout<<f(0)<<endl;

	return 0;

}

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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

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

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

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

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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

using namespace std;

int a,b,c,d,dp[100000],cost[100000],weight[100];



void func(int a)

{

    dp[1]=0;

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

    for(int i=3; i<=a; i++)

    {

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

    }

}



int main()

{

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

    cin>>a;

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

    {

        cin>>cost[i];

    }

    func(a);

    cout<<dp[a]<<endl;

    //cout<<nCr(a,b)<<endl;



}


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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

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

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

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

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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

				" اللهم صلي و سلم علي سيدنا محمد و علي اله وصحبه اجمعين "

*/





#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

#define f for

#define ll long long

#define ull unsigned long long

#define endl "\n"

using namespace std;

#define BI  acos(-1)

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

void Open()

{

#ifndef ONLINE_JUDGE

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

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

#endif

}

ll gcd(ll a, ll b)

{

	return b == 0 ? a : gcd(b, a % b);

}

void madesetprobblem()

{

	//$ $

	//less than or equal => $ 1 \leq 100 $

	//  $(1 \le A,B \le 10^5 )$

	// a[i] => $a_i$

	// a[i][j] => $a_{i,j}$

	// double qoutes ''yext''

	/*

		image

		\begine{center}

		\includegraphics{image.jpg}

		\end{center}

	*/

	/*

		list

		\begin{itemize}

			\item first one

			\item second one

		\end{itemize}

	*/

}

int n;

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

int ans(int c = 0)

{

	if (c == n-1)

		return 0;

	int ans1 = INT_MAX, ans2 = INT_MAX;

	if (dp[c] != -1)

		ans1 = dp[c];

	else

	{

		if (c + 1 < n)

			ans1 = (abs(a[c] - a[c + 1]) + ans(c + 1));

		if (c + 2 < n)

			ans2 = (abs(a[c] - a[c + 2]) + ans(c + 2));

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

	}

	//cout <<c<<" "<< ans1 << " " << ans2 << endl;

	return min(ans1,ans2);

}

int main()

{

	// توكلت علي الله 

//Open();

	ios::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);

	cin >> n;

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

	{

		cin >> a[i];

	}

	cout << ans();

}

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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

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

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

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

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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

#define F first

#define S second

#define T second.first

#define C second.second

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

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<int,pair<int,int>> piii;



const int N= 1e5+5, L = 14, OO = 0x3f3f3f3f;

const ll M=10 ;

const double ESP = 1e-8;



int n;

int A[N], dp[N];

int main(){

    FIO

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

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

    cin>>n;

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

    memset(dp, OO, 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(A[i]-A[i+1]));

        }

        if(i+2<n){

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

        }

    }

    cout<<dp[n-1];



}


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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

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

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

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

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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



using namespace std;

typedef long long ll;

typedef double dd;

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

#define endl "\n"

#define clr(n, r) memset(n,r,sizeof(n));



void fast() {



    cin.tie(0);

    cin.sync_with_stdio(0);

}



const int N = 1e5 + 9;

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



int sol(int i){

    if(i<0) return 1e9;

    if(i==0) return 0;



    if(~dp[i]) return dp[i];



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

}





int main() {



    cin >> n;



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



    memset(dp, -1, sizeof dp);



    cout << sol(n - 1);

}

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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

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

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

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

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




// Fastest known solution for this problem: