stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

 

}

// Faster C++ solution for the same problem (measured speedup: 4.851438028100068x):
//动态规划青蛙跳

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

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.270872110614289x):
//动态规划青蛙跳

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

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 9.428146309345706x):
//动态规划青蛙跳

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

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.232687964661353x):
//动态规划青蛙跳

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

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.2326875147912375x):
//动态规划青蛙跳

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

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.351556287706672x):
//动态规划青蛙跳

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

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 7.412697755522078x):
//动态规划青蛙跳

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

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 7.329818240383092x):
//动态规划青蛙跳

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

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 7.332937218010517x):
//动态规划青蛙跳

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

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 7.329245091797543x):
//动态规划青蛙跳

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

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.165752521219741x):
//动态规划青蛙跳

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

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.236378178926335x):
//动态规划青蛙跳

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

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.24604130465595x):
//动态规划青蛙跳

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

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.7788756490033328x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.398606586922492x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.3829691173240615x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.3835575970918939x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.3828609772900995x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.8042960554997165x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.4185928900617861x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.402731958618797x):
#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;

}