stablegradients/pie-gem5-pairs huggingface dataset:
// 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.4033288478529804x):
#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 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.402622273247125x):
#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<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];

}

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

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

}


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

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

}


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

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

}


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

}
// 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.846695081242323x):
#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;

}
// 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.265719109345424x):
#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;

}
// 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.41892900168285x):
#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;

}
// 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.2275722936384925x):
#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;

}
// 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.227571844208187x):
#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;

}
// 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.346324406575384x):
#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;

}
// 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.405450825576084x):
#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;

}
// 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.322652336543919x):
#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;

}
// 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.325768264942424x):
#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;

}
// 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.3220797482898154x):
#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;

}
// 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.160702288784224x):
#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;

}
// 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.231258900212301x):
#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;

}
// 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.240912578909604x):
#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;

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

}

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

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

}

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

}
// 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.269035646012839x):
#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";

}
// 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.7769103960931176x):
#include <bits/stdc++.h>

using namespace std;

 

typedef long long lld;

const int NN = 1e5 + 5;

lld aa[NN], dp[NN];

int nn;

 

int main() {

    ios::sync_with_stdio(0);

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

        cin >> nn;

        for (int ii = 1; ii <= nn; ++ii)

            cin >> aa[ii];

        dp[1] = 0;

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

        for (int ii = 3; ii <= nn; ++ii)

            dp[ii] = min(dp[ii - 1] + abs(aa[ii] - aa[ii - 1]), dp[ii - 2] + abs(aa[ii] - aa[ii - 2]));

        cout << dp[nn];

    return 0;

}