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

using namespace std;

int h[100500],n,mem[100500];

#define INF 1000000000

int dp(int i){

    if(i==1) return 0;

    if(i<1) return INF;

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

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

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

    return  mem[i]=min(a1,a2);

}

int main(){

    int n;

    cin >> n;

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

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

        cin >> h[i];

    }

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

    return 0;

}




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

#include <iostream>

#include <vector>

#include <algorithm>

#include <string>

#include <deque>

#include <list>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <cstring>

#include <iomanip>

#include <tuple>



using namespace std;

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

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

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

#define pii pair<int,int> 

#define int long long

#define setout(n,x) setw(n) << setfill(x)

#define Fixed fixed << setprecision(10)

const int INF = 0x3f3f3f3f;

const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

const long long mod = 1e9+7;



int gcd(int a,int b){ return b ? gcd(b,a % b) : a; }

int lcm(int a,int b){ return a / gcd(a,b) * b; }



inline double sqrt( const double &x) 

{

	double         xHalf = 0.5 * x;

	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);

	double         xRes  = * (double*)&tmp;



	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );

	return xRes * x;

}

// }}}



signed main(){

	cin.tie(0);

	ios::sync_with_stdio(false);

	int n;

	cin >> n;

	vector<int> h(n),dp(n);

	rep(i,n){

		cin >> h[i];

	}

	reps(i,n-1){

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

		else 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:
// Original C++ solution (slower):
#include <iostream>

#include <cmath>

#include <cstring>



using namespace std;



const long int INF=1L<<60;

int N;

long int h[100001];

long int memo[100001];



void swap(long int* a, long int* b) {

    long int tmp;

    tmp = *a;

    *a = *b;

    *b = tmp;

}



void swmin(long int* origin, long int comp) {

    if(*origin > comp) {

        swap(origin, &comp);

    }

}



long int rec(int i) {

    if(i==0) return 0;

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

    

    long int res=INF;

    swmin(&res, rec(i-1)+abs(h[i]-h[i-1]));

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

    memo[i] = res;

    return res;

}



int main() {

    cin >> N;

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

        cin >> h[i];

    }



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

    

    long int ans;

    ans = rec(N-1);

    cout << ans << endl;



    return 0;

    

}

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

#include <cmath>

#include <algorithm>



using namespace std;



int main() {

    int N;

    cin >> N;

    

    int h[N];

    long int dp[N];

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

        cin >> h[i];

        dp[i]=0;

    }

    

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

    

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

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

        dp[i] = min(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):
/************

* 	@Just Another Source code by: ankit.sangwan1999

*	@created on: 23 Apr 2020

*/



#include<bits/stdc++.h>

using namespace std;

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

#define ll long long



int DP[100005];



int fun(vector<int>&H, int ind){

	if(DP[ind] != -1){

		return DP[ind];

	}

	if(ind==0){

		return 0;

	}

	int pos1=INT_MAX, pos2 = INT_MAX;

	if(ind-1>=0){

		int val1 = abs(H[ind] - H[ind-1]);

		pos1 = val1 + fun(H,ind-1);

	}

	if(ind-2>=0){

		int val2 = abs(H[ind] - H[ind-2]);

		pos2 = val2 + fun(H,ind-2);

	}



	return DP[ind] = min(pos1, pos2);

}





signed main(){

    fastio;

    int t=1;

    // cin>>t;

    while(--t>=0){

    	int n;

    	cin>>n;

    	vector<int>H(n);

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

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

    	cout<<fun(H,n-1);





    }





    return 0;

}

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

* 	@Just Another Source code by: ankit.sangwan1999

*	@created on: 23 Apr 2020

*/



#include<bits/stdc++.h>

using namespace std;

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

#define ll long long



int DP[100005];

int fun(vector<int>&H, int ind){

	if(DP[ind] != -1){

		return DP[ind];

	}

	if(ind==0){

		return 0;

	}

	int pos1=INT_MAX, pos2 = INT_MAX;

	if(ind-1>=0){

		int val1 = abs(H[ind] - H[ind-1]);

		pos1 = val1 + fun(H,ind-1);

	}

	if(ind-2>=0){

		int val2 = abs(H[ind] - H[ind-2]);

		pos2 = val2 + fun(H,ind-2);

	}



	return DP[ind] = min(pos1, pos2);

}



/* MEMO



signed main(){

    fastio;

    int t=1;

    // cin>>t;

    while(--t>=0){

    	int n;

    	cin>>n;

    	vector<int>H(n);

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

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

    	cout<<fun(H,n-1);

    }



    return 0;

}



*/



/* BOTTOM-UP */



signed main(){

    fastio;

    int t=1;

    // cin>>t;

    while(--t>=0){

    	int n;

    	cin>>n;

    	vector<int>H(n);

    	int dp[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++){

    		int val1 = INT_MAX;

    		int val2 = INT_MAX;

    		if(i-1>=0){

    			val1 = abs(H[i] - H[i-1]);

    		}

    		if(i-2>=0){

    			val2 = abs(H[i] - H[i-2]);

    		}

    		dp[i] = min(dp[i-1] + val1, dp[i-2] + val2);

    	}

    	cout<<dp[n-1];

    }



    return 0;

}


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

using namespace std;

int n;

vector <int> v(100005);

int dp[100005];

int solve(int i){

    if(i==n){

        return 0;

    }

    if(i>n){

        return 2e9;

    }

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

        return dp[i];

    }

    int q = min(abs(v[i]-v[i+1])+solve(i+1), abs(v[i]-v[i+2])+solve(i+2));

    dp[i]=q;

    return q;

}

void initialize(){

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

        dp[i]=-1;

    }

}

int main(){

    initialize();

    cin>>n;

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

        cin>>v[i];

    }

    cout<<solve(1)<<endl;

}


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

using namespace std;

int main(){

	int n;

  	cin>>n;

  	vector <int> v(n);

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

    	cin>>v[i];

	}

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

	dp[0]=0;

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

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

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

	}

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

}

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

#define ll long long int

#define M 1000000007

#define mod 998244353

#define mp(x,y) make_pair(x,y)

#define pb(x) push_back(x)

#define pi pair<ll,ll>

using namespace std;

const ll N=1e5+10;



ll n;

ll ar[N];

ll dp[N];



ll func(ll i)

{

    if(i==n){return(INT_MAX);}

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

    if(dp[i]==-1)

    {

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

    }

    return(dp[i]);

}



int main()

{

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);



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

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



	cin>>n;

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

    {

        cin>>ar[i];

    }

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

    cout<<func(0);



	return(0);

}


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

#define ll long long int

#define M 1000000007

#define mod 998244353

#define mp(x,y) make_pair(x,y)

#define pb(x) push_back(x)

#define pi pair<ll,ll>

using namespace std;

const ll N=100010;





int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    ll n;

    cin>>n;

    ll ar[n];

    for(ll i=0;i<n;++i){cin>>ar[i];}

    ll dp[n];

    dp[0]=0;

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

    {

        if(i==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-2]-ar[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    sz    100110

#define    ll    long long int

ll n,c=0,p,q;

ll num[sz];

ll vis[sz];

ll dp[sz];



ll tani(int pos)

{



  if(pos>=n)return 0;

  if(vis[pos]==1)return dp[pos];

  vis[pos]=1;



  return  dp[pos]=min(abs(num[pos]-num[pos+1])+tani(pos+1),abs(num[pos]-num[pos+2])+tani(pos+2));



}



int main()

{

    ll t,i;



    for(i=1;i<sz;i++)num[i]=1000000;



    cin>>n;

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

    {

        cin>>num[i];

    }

    t=tani(1);

    cout<<t<<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<iostream>

#include<algorithm>



using namespace std;



int h[1000000];

int dp[1000000];



int main()

{

    int n;

    cin>>n;



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

        cin>>h[i];

    dp[1] = 0;

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



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

    {

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

    }

    cout<<dp[n];

}

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

#include <algorithm>

#include <list>

#include <map>

#include <queue>

#include <stack>

#include <string>

#include <vector>



using namespace std;



int main() {

    vector<int> stones;

    vector<int> energyReq;

    int n;

    cin >> n;

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

        int h;

        cin >> h;

        stones.push_back(h);

    }

    energyReq.push_back(0);

    energyReq.push_back(abs(stones[1] - stones[0]));

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

        energyReq.push_back(min(energyReq[i - 2] + abs(stones[i] - stones[i - 2]), energyReq[i - 1] + abs(stones[i] - stones[i - 1])));

    }

    cout << energyReq.at(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;

long long n,x;

long long h[100005],f[100005];

int main(){

	cin>>n;

	h[0]=0;

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

		cin>>h[i];

	}

	f[1]=0;

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

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

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

	}

	cout<<f[n];

}


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

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

int main()

{

	cin>>n;

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

		cin>>a[i];

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

	{

		if(i==1)

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

		else

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

	}

	cout<<f[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 <cstdio>

#include <algorithm>

using std::min;

 

int m_abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}

 

int main(void)

{

    int *a,*dp,N,i,j;

    scanf("%d",&N);

    a=new int [N];

    dp=new int [N];

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

    {

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

    }

    dp[N-1]=0;

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

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

    {

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

    }

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

 

    delete [] a;

 

}

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

int arr[100009];

int main()

{

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

    int n,crr[100009],res1,res2;

    cin>>n;

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

    {

        cin>>crr[i];

    }

    arr[1] = 0;

    arr[2] = abs(crr[1]-crr[2]);

    if(n==2){cout<<abs(crr[1]-crr[2])<<endl;return 0;}

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

    {

        res1 = abs(crr[i] - crr[i-1]) + arr[i-1];

        res2 = abs(crr[i] - crr[i-2]) + arr[i-2];

        if(res1<res2)

        {

            if(i-1!=1)

            {

                arr[i] = abs(crr[i] - crr[i-1]) + arr[i-1];

            }

            else

            {

                arr[i] = abs(crr[i] - crr[i-1]);

            }

        }

        else

        {

            if(i-2!=1)

            {

                arr[i] = abs(crr[i] - crr[i-2]) + arr[i-2];

            }

            else

            {

                arr[i] = abs(crr[i] - crr[i-2]);

            }

        }

    }

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

//    {

//        cout<<arr[i]<<" ";

//    }

    cout<<arr[n]<<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;

int main()

{

    int n;

    cin>>n;

    int a[n],cal[n];

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

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

    {

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

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

    }

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

}


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





int main()

{

    int n;

    cin>>n;



    int ar[n+10],ans[n+10];



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

        {

            cin>>ar[i];

        }



    ans[0]=0;

    ans[1]=abs(ar[1]-ar[0]);



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

    {

       int r1,r2;



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

       r2=abs(ar[i]-ar[i-2])+ans[i-2];



       ans[i]=min(r1,r2);



    }



    cout<<ans[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 <cstring>

#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

#include <sstream>

#include <queue>

#include <deque>

#include <bitset>

#include <iterator>

#include <list>

#include <stack>

#include <map>

#include <set>

#include <functional>

#include <numeric>

#include <utility>



using namespace std;

int abs(int a){

	if (a < 0) {

		return -a;

	} else {

		return a;

	}

}

int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	int n;

	cin >> n;

	vector<int> costs = {0};

	vector<int> heights = {};

	int t;

	cin >> t;

	heights.push_back(t);

	cin >> t;

	heights.push_back(t);

	costs.push_back(abs(heights[0] - heights[1]));

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

		cin >> t;

		costs.push_back(min(costs[i - 2] + abs(heights[i - 2] - t),

			costs[i - 1] + abs(heights[i - 1] - t)));

		heights.push_back(t);

	}

	cout << costs.back();

	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 fr(i,n) _back

#define pb	push_back

#define eb	emplace_back

#define mk	make_pair

#define fi	first

#define se	second

#define endl	'\n'



typedef long long ll;

typedef pair<int,int> ii;

typedef vector<ii> vii;

const int INF = 0x3f3f3f3f;

const double PI = acos(-1.0);

const int N = 1e5 + 3;

int h[N];

int dp[N];



int main() {

    ios_base::sync_with_stdio(false);

    memset(dp, INF, sizeof dp);

    int n; cin >> n;

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



    dp[0] = 0;

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

        for(int j = max(0,i-2); j < i; j++)

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



    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;



int N, a[100100], dp[100100];



int f(int n) {

	if (n==1) return 0;

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

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

	dp[n] = min(

				f(n-1) + abs(a[n] - a[n-1]),

				f(n-2) + abs(a[n] - a[n-2])

				);

	return dp[n];

}



int main() {

	cin >> N;

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

		cin >> a[i];

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

	cout << f(N) << 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;

typedef long long LL;



int arr[100007];

int dp[100007];



int Solve(int idx, int n){

//	cout<<cost<<" "<<idx<<endl;

	if(idx >= n)return 1e9;

	if(idx == n - 1){

		return 0;	

	}

	

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

	

	

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

}



int main(){

	int n; cin>>n;

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

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

		

	cout<<Solve(0,n)<<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: