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

}


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

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

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

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

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

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

}
// 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.218698133945004x):
#include <cstdio>

#include <algorithm>

#include <cmath>



using namespace std;



const int MaxN = 1e5 + 5;

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

int main(){

	scanf("%d",&n);

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

	dp[1] = 0;

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

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

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

	}

	printf("%d\n",dp[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.28327440761373x):
#include <cstdio>

#include <algorithm>

#include <cmath>



using namespace std;



const int MaxN = 1e5 + 5;

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

int main(){

	scanf("%d",&n);

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

	dp[1] = 0;

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

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

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

	}

	printf("%d\n",dp[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.174201842587118x):
#include <cstdio>

#include <algorithm>

#include <cmath>



using namespace std;



const int MaxN = 1e5 + 5;

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

int main(){

	scanf("%d",&n);

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

	dp[1] = 0;

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

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

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

	}

	printf("%d\n",dp[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.226362846799387x):
#include <cstdio>

#include <algorithm>

#include <cmath>



using namespace std;



const int MaxN = 1e5 + 5;

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

int main(){

	scanf("%d",&n);

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

	dp[1] = 0;

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

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

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

	}

	printf("%d\n",dp[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.845657502642962x):
#include <cstdio>

#include <algorithm>

#include <cmath>



using namespace std;



const int MaxN = 1e5 + 5;

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

int main(){

	scanf("%d",&n);

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

	dp[1] = 0;

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

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

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

	}

	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.2645918262449785x):
#include <cstdio>

#include <algorithm>

#include <cmath>



using namespace std;



const int MaxN = 1e5 + 5;

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

int main(){

	scanf("%d",&n);

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

	dp[1] = 0;

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

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

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

	}

	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.416912601022766x):
#include <cstdio>

#include <algorithm>

#include <cmath>



using namespace std;



const int MaxN = 1e5 + 5;

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

int main(){

	scanf("%d",&n);

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

	dp[1] = 0;

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

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

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

	}

	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.226453176993528x):
#include <cstdio>

#include <algorithm>

#include <cmath>



using namespace std;



const int MaxN = 1e5 + 5;

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

int main(){

	scanf("%d",&n);

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

	dp[1] = 0;

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

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

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

	}

	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.226452727659435x):
#include <cstdio>

#include <algorithm>

#include <cmath>



using namespace std;



const int MaxN = 1e5 + 5;

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

int main(){

	scanf("%d",&n);

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

	dp[1] = 0;

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

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

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

	}

	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.345179867524234x):
#include <cstdio>

#include <algorithm>

#include <cmath>



using namespace std;



const int MaxN = 1e5 + 5;

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

int main(){

	scanf("%d",&n);

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

	dp[1] = 0;

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

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

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

	}

	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.403865469541418x):
#include <cstdio>

#include <algorithm>

#include <cmath>



using namespace std;



const int MaxN = 1e5 + 5;

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

int main(){

	scanf("%d",&n);

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

	dp[1] = 0;

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

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

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

	}

	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.321084705977605x):
#include <cstdio>

#include <algorithm>

#include <cmath>



using namespace std;



const int MaxN = 1e5 + 5;

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

int main(){

	scanf("%d",&n);

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

	dp[1] = 0;

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

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

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

	}

	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.2857257643211675x):
#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;

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

}