stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>



using namespace std;



int n, a[(int)2e5], d[(int)2e5];



int main(){

    cin >> n;

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

        cin >> a[i];

    }

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

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

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

    cout << d[n];

}


// Faster C++ solution for the same problem (measured speedup: 4.663100773606804x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <iomanip>

#include <cmath>

#include <cstdio>

#include <cstring>

#include <ctime>

#include <string>

#include <stdio.h>

#include <set>

#include <map>

#include <algorithm>

#include <queue>

#include <vector>

#define ll long long

#define pb push_back

#define mp make_pair

#define f first

#define s second



using namespace std;



const int inf = 1e9 + 7;

const long long INF = 1e18 + 7;

const int maxn = 2e5 + 7;



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



int main(){

	ios_base::sync_with_stdio(NULL);

	cin.tie(0);

	cout.tie(0);

	cin >> n;

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

		cin >> a[i], dp[i] = inf;

	dp[1] = 0;

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

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

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

	}

	cout << dp[n];

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 4.72592510692536x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



typedef signed long long ll;

const int MX = 1e5 + 5;

const int INF = 1e9 + 5;

int n, A[MX], dp[MX];



int solve(int pos) {

    if(pos > n) return INF;

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

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

    int ans = INF;

    if(pos + 1 < n) ans = min(ans, abs(A[pos] - A[pos + 1]) + solve(pos + 1));

    if(pos + 2 < n) ans = min(ans, abs(A[pos] - A[pos + 2]) + solve(pos + 2));

    return dp[pos] = ans;

}



int main() {

    scanf("%d", &n);



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

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

    }

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

    printf("%d\n", solve(0));

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.481748671356262x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    long long n;

    cin >> n;

    long long a[n + 1], dp[n + 1];

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

        cin >> a[i];

        dp[i] = 0;

    }

    if(n == 1)

        cout << 0 << endl;

    else {

        dp[1] = 0;

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

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

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

        }

        cout << dp[n] << endl;

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.728326629557244x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cmath>

#include<algorithm>

#include<cstring>

using namespace std;



int h[100055],dp[100055];

const int inf = 0x3f3f3f;

int main()

{

	int n;

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

	cin>>n;

	h[1]=inf;

	h[0]=inf;

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

		cin>>h[i];

	for(int i=2;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]<<endl;

	return 0;

} 

//max(h[i],h[i-2])-min(h[i],h[i-2])

// Faster C++ solution for the same problem (measured speedup: 6.554634464255756x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define IO ios::sync_with_stdio(false), cin.tie(0)

typedef long long ll;

const int maxn = 1e6 + 5;

const int inf = 0x3f3f3f3f;

ll a[maxn];

ll dp[maxn];



int main()

{

    IO;

    int n, k=2;

    cin >> n ;

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

        cin >> a[i];

    memset(dp, inf, sizeof(dp));

    dp[1] = 0;

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

    {

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

        {

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

        }

    }

    cout << dp[n] << endl;

}


// Faster C++ solution for the same problem (measured speedup: 43.92943342686582x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cmath>



using namespace std;

int i,n,h[100005];

long long dp[100005];

int main()

{

    cin>>n;

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

        cin>>h[i];

    dp[1]=0;

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

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

    {

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

    }

    cout<<dp[n];

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.661259627999072x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std ;



const int nmax = 100010;



int h[nmax];

int dp[nmax];



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    int n;cin>>n;

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

    dp[0]=1000000000;

    dp[1]=0;

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

    {

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

    }

    cout<<dp[n];

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.726351084785902x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



long long n,a,m,b,qq;

string ss;

int main() {

    cin>>n;

    int l[n],l1[n];

    l[n]=0;

    l1[n]=0;

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

        l[i]=0;

        l1[i]=0;

    }

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

        cin>>l[i];

    }

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

        if (i==1){

            l1[i]=abs(l[i]-l[i-1]);

        }

        else{

            l1[i]=min(l1[i-1]+abs(l[i-1]-l[i]), l1[i-2]+abs(l[i-2]-l[i]));

        }

    }

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

}


// Faster C++ solution for the same problem (measured speedup: 4.683193122415711x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;





#define x_ real()

#define y_ imag()

#define cross(a, b) (conj(a)*(b)).imag()

#define dot(a, b) (conj(a)*(b)).real()

#define PI acos(-1)

#define F first

#define S second

#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)

#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)

typedef long double ld;

typedef long long ll;

typedef unsigned long long ull;

typedef complex<ld> point;

typedef tuple<int, int, int> line;

typedef vector<point> polygon;

typedef pair<double, double> pd;

pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };

ll mod = 1e9 + 7;

ld eps = 1e-6;









int main() {

	fastIO;

	int n;

	cin >> n;

	int dp[n+1], arr[n+1];

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

		cin >> arr[i];

	}

	dp[0] = 0;

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

		if (i > 1) {

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

		}

		else {

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

		}

	}



	cout << dp[n-1];



}


// Faster C++ solution for the same problem (measured speedup: 4.726111514576213x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

 

int h[100000], mCost[100000];

int Nstones;

 

int main() {

	scanf("%d", &Nstones);

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

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

	}

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

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

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

	}

	printf("%d", mCost[Nstones - 1]);

}

// Faster C++ solution for the same problem (measured speedup: 4.607545774179951x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

const int nax = 1e5+3;

int number;

int dyn[nax];

int a[nax];

int op1(int i){

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

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

	int res = abs(a[i]-a[i+1])+op1(i+1);

	if(i!=number-2) res = min(res, abs(a[i]-a[i+2])+op1(i+2));

	return dyn[i]=res;

}

int main(){

	cin>>number;

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

	memset(dyn, -1, sizeof dyn);

	cout<<op1(0)<<endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.539217234383336x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define ll long long

ll h[100009];

ll dp[100009];

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]<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.678171355496476x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int n, arr[100005], best, memo[100005];



int dp(int x){

	if(x==1 || x == 0){

		return 0;

	}

	if (x == 2){

		return abs(arr[x] - arr[x-1]);

	}

	if (memo[x] != -1){

		return memo[x];

	}

	best=min(dp(x-1)+abs(arr[x]-arr[x-1]), dp(x-2)+abs(arr[x-2]-arr[x]));

	memo[x] = best;

	return best;

}



int main(){

	ios_base::sync_with_stdio(0);

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

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	cout << dp(n) << endl;

}

// Faster C++ solution for the same problem (measured speedup: 6.613414278409586x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int n, arr[100005], best, memo[100005];



int dp(int x){

	if(x==0 or x==1){

		return 0;

	}

	else if(x==2){

		return dp(x-1)+abs(arr[x]-arr[x-1]);

	}

	else if(memo[x]!=-1){

		return memo[x];

	}

	best=min(dp(x-1)+abs(arr[x]-arr[x-1]), dp(x-2)+abs(arr[x-2]-arr[x]));

	memo[x]=best;

	return best;

}



int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

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

	cin >> n;

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

		cin >> arr[i];

	}

	cout << dp(n) << endl;

}


// Faster C++ solution for the same problem (measured speedup: 6.613414278409586x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

	

using namespace std;

	

#define endl "\n"

#define ll unsigned long long

#define int long long

#define vi vector <int >

#define vii vector < pii >

#define vll vector <ll >

#define pii pair <int, int>

#define pdd pair< double, double>

#define piii pair < pii, int > 

#define pll pair<ll, ll >

#define umap unordered_map

#define pb push_back

#define pq priority_queue

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

#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)

#define a first

#define b second



int32_t main() {

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);



	int dp[100010];

	int n;

	cin >> n;

	vi arr(n);

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

		cin >> arr[i];

	}

	dp[0] = 0;

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

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

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

	}

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



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.849097662781736x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
    #include <iostream>

    #include <cstdio>

    #include <cstring>

    #include <algorithm>

    #include <stack>

    #include <string>

    #include <cstring>

    #include <cmath>

    #include <vector>

    #include <set>

    #define INF  0x3f3f3f3f;

    #define maxn 1000605

    typedef long long LL;

    using namespace std;

    int h[100005];

    int d[100005];

    int get_min(int a,int b){

        if(a<b)

            return a;

        else

            return b;

    }



    int main(){

        int n;

        while(cin>>n){

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

                cin>>h[i];

            d[1]=0;

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

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

                d[i]=get_min(d[i-1]+abs(h[i]-h[i-1]),d[i-2]+abs(h[i]-h[i-2]));

            }

            cout<<d[n]<<endl;

        }

        return 0;

    }


// Faster C++ solution for the same problem (measured speedup: 4.672198633584251x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<algorithm>

int h[100000];

int dp[100000];

int main()

{

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

	int n,temp,dp1,dp2;

	scanf("%d", &n);

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

	{

		scanf("%d", &temp);

		h[i] = temp;

	}

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

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

	{

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

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

		dp[i] = dp1 < dp2 ? dp1 : dp2;

	}

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

}

// Faster C++ solution for the same problem (measured speedup: 2.7738647642348395x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

const int MAXN=100010;

int stones[MAXN];

int mins[MAXN]= {-1};

int main()

{

    int n;

    cin>>n;

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

    {

        cin>>stones[i];

    }

    for(int i=n-2; i>=0; --i)

    {

        if(i==n-2)

        {

            mins[n-2]=abs(stones[i]-stones[i+1]);

        }

        else if(i==n-3)

        {

            int one=abs(stones[i]-stones[i+1])+mins[i+1];

            int two=abs(stones[i]-stones[i+2]);

            mins[i]=min(one,two);

        }

        else

        {

            int one=abs(stones[i]-stones[i+1])+mins[i+1];

            int two=abs(stones[i]-stones[i+2])+mins[i+2];

            mins[i]=min(one,two);

        }

    }

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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.649942513435965x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <queue>

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int maxn = 100010;

int H[maxn];

int main(){

    int n;

    scanf("%d",&n);

    int dp[n+1];

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

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

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

    }

    dp[1]=0;

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

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

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

    }

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

    return 0;



}

// Faster C++ solution for the same problem (measured speedup: 4.609913188978546x):
#include <cstdio>

#include <algorithm>

using std::min;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}