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

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f3f3f3f

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

#define pb push_back

#define ms(a, x) memset(a, x, sizeof(a))

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

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

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

using namespace std;

const int mod = 1e9;

const int N = 1e5+10;

/*=======================================================================*/



int n, h[N], sum;

int f[N];



int main() {

   scanf("%d", &n);

   for1(i, n) {

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

   }

   ms(f, inf);

   f[n] = 0;

   for(int i = n; i > 1; i--) {

      if(i == 2) {

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

      } else {

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

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

      }

      // if(i == 2) {

      //    sum += abs(h[i] - h[1]);

      //    i--;

      // } else {

      //    if(abs(h[i] - h[i-1]) < abs(h[i] - h[i-2])) {

      //       sum += abs(h[i] - h[i-1]);

      //       i -= 1;

      //    } else {

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

      //       i -= 2;

      //    }

      // }

   }

   cout << f[1] << endl;

   return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3914464128412083x):
#include<bits/stdc++.h>

using namespace std;

#define INF 1<<28

#define max 100005

 

 

typedef long long ll;

 

int n, a[100005];

int dp[max];

 

int main()

{

    cin>>n;

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

        cin>>a[i];

    dp[1] = 0;

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

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

        if(i > 2){

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

        }

    }

    cout << dp[n]<<endl;

    return 0;

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

using namespace std;



const int nax = 1e5+3;

int n;

int dp[nax];

int a[nax];

int f(int i){

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

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

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

	if(i!=n-2) ans = min(ans, abs(a[i]-a[i+2])+f(i+2));

	return dp[i]=ans;

}

int main(){

	cin>>n;

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

	memset(dp, -1, sizeof dp);

	cout<<f(0)<<endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.400588828096854x):
#include<bits/stdc++.h>

using namespace std;

#define INF 1<<28

#define max 100005

 

 

typedef long long ll;

 

int n, a[100005];

int dp[max];

 

int main()

{

    cin>>n;

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

        cin>>a[i];

    dp[1] = 0;

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

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

        if(i > 2){

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

        }

    }

    cout << dp[n]<<endl;

    return 0;

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

const int mod = 1e9+9;



const int ppt = 1e5+3;

int n;

int dp[ppt];

int a[ppt];

int f(int i){

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

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

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

	if(i!=n-2) jpr = min(jpr, abs(a[i]-a[i+2])+f(i+2));

	return dp[i]=jpr;

}

int main(){

	cin>>n;

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

	memset(dp, -1, sizeof dp);

	cout<<f(0)<<endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.400588828096854x):
#include<bits/stdc++.h>

using namespace std;

#define INF 1<<28

#define max 100005

 

 

typedef long long ll;

 

int n, a[100005];

int dp[max];

 

int main()

{

    cin>>n;

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

        cin>>a[i];

    dp[1] = 0;

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

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

        if(i > 2){

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

        }

    }

    cout << dp[n]<<endl;

    return 0;

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

const int mod = 1e9+9;



const int nax = 1e5+3;

int n;

int dp[nax];

int a[nax];

int f(int i){

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

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

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

	if(i!=n-2) ans = min(ans, abs(a[i]-a[i+2])+f(i+2));

	return dp[i]=ans;

}

int main(){

	cin>>n;

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

	memset(dp, -1, sizeof dp);

	cout<<f(0)<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.400588828096854x):
#include<bits/stdc++.h>

using namespace std;

#define INF 1<<28

#define max 100005

 

 

typedef long long ll;

 

int n, a[100005];

int dp[max];

 

int main()

{

    cin>>n;

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

        cin>>a[i];

    dp[1] = 0;

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

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

        if(i > 2){

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

        }

    }

    cout << dp[n]<<endl;

    return 0;

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

const int mod = 1e9+9;

/*ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }

*ll lcm(ll x, ll y){return x*(y/gcd(x,y));}

*void exEuclid(int a, int b){

	if(b==0){x = 1; y=0; d=a; return ;}

	exEuclid(b, a%b);

	int x1=y;

	int y1=x-(a/b)*y;

	x=x1;

	y=y1;

} 

* */

//===========================================================//

const int nax = 1e5+3;

int n;

int dp[nax];

int a[nax];

int f(int i){

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

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

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

	if(i!=n-2) ans = min(ans, abs(a[i]-a[i+2])+f(i+2));

	return dp[i]=ans;

}

int main(){

	cin>>n;

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

	memset(dp, -1, sizeof dp);

	cout<<f(0)<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4005651580898943x):
#include<bits/stdc++.h>

using namespace std;

#define INF 1<<28

#define max 100005

 

 

typedef long long ll;

 

int n, a[100005];

int dp[max];

 

int main()

{

    cin>>n;

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

        cin>>a[i];

    dp[1] = 0;

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

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

        if(i > 2){

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

        }

    }

    cout << dp[n]<<endl;

    return 0;

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

using ll = long long;

using namespace std;



int n;

ll dp[100100];

int h[100100];

bool vis[100100];



ll func( int pos ) {

    if (pos == n) return 0;

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

    vis[pos] = 1;



    ll p = 2e9, q = 2e9;

    if ( pos + 1 <= n ) p = abs(h[pos] - h[pos + 1]) + func(pos + 1);

    if ( pos + 2 <= n ) q = abs(h[pos] - h[pos + 2]) + func(pos + 2);



    return dp[pos] = min(p, q);

}





int main() {

    cin >> n;

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

    cout << func(1) << endl;

    return 0;

}


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



using namespace std;



const int maxn = 1e5+5;

int n;

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

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	scanf("%d",&n);

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

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

	}

	f[0] = f[1] = 0;

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

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

	}

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

	return 0;

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

using namespace std;

const int N =1e6;



int dp[N], h[N];



int main(){

    int n;

    cin >> n;

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

        cin >> h[i];

    }

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

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



}


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



using namespace std;



const int maxn = 1e5+5;

int n;

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

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	scanf("%d",&n);

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

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

	}

	f[0] = f[1] = 0;

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

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

	}

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

	return 0;

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



using namespace std;



int main(){

    int n, i;

    scanf("%d",&n);

    int height[n+5];

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

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

    }

    int ans = 1e9;

    int dp[n+5];

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

        dp[i] = 1e9;

    }

    dp[1] = 0;

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

        if(i > 1) dp[i] = min(dp[i], dp[i-1] + abs(height[i] - height[i-1]));

        if(i > 2) dp[i] = min(dp[i], dp[i-2] + abs(height[i] - height[i-2]));

    }

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

    return 0;

}


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



using namespace std;



const int maxn = 1e5+5;

int n;

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

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	scanf("%d",&n);

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

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

	}

	f[0] = f[1] = 0;

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

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

	}

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

	return 0;

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

using namespace std;



const int MAXN = 1e5 + 1;



int n, k, h[MAXN];



int main(){



    cin >> n;

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

    int dp[n + 5];

    for(int i = 1; i <= n; i++) dp[i] = 1e9;

    dp[1] = 0;

    for(int i = 2; i <= n; i++) for(int j = 1; j <= 2 && j < i; j++) if(i > j) dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));

    cout << dp[n] << endl;



    return 0;

}


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



using namespace std;



const int maxn = 1e5+5;

int n;

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

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	scanf("%d",&n);

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

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

	}

	f[0] = f[1] = 0;

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

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

	}

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

	return 0;

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



using namespace std;

typedef long long int ll;

ll dp[100010];

ll arr[100010];



int main(){

    ll n;

    scanf("%lld",&n);



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

        scanf("%lld",arr+i);

    }



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

        dp[i] = 10000000000000;

        if(i-1 >= 1){

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

        }

        if(i-2 >= 1){

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

        }

    }

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

}


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



using namespace std;



const int maxn = 1e5+5;

int n;

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

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	scanf("%d",&n);

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

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

	}

	f[0] = f[1] = 0;

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

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

	}

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

	return 0;

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

using namespace std;



int arr[100010];

int dp[100010];



int main (){

	int n;

	cin >> n;

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

		cin >> arr[i];

	}

	dp[1] = 0;

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

	

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

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

	}

	

	cout << dp[n] << endl;

}

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



using namespace std;



const int maxn = 1e5+5;

int n;

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

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	scanf("%d",&n);

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

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

	}

	f[0] = f[1] = 0;

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

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

	}

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

	return 0;

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

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

#include <queue>

#include <stack>

#include <map>

#include <set>

#include <vector>

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

#define repd(i,x,n) for(int i=x;i<=n;i++)

#define pii pair<int,int>

#define pll pair<long long ,long long>

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

#define MS0(X) memset((X), 0, sizeof((X)))

#define MSC0(X) memset((X), '\0', sizeof((X)))

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define gg(x) getInt(&x)

using namespace std;

typedef long long ll;

inline void getInt(int* p);

const int maxn=1000010;

const int inf=0x3f3f3f3f;



ll n;

ll dp[maxn];

ll a[maxn];

int main()

{

    gbtb;

    cin>>n;

    repd(i,1,n)

    {

        cin>>a[i];

    }

    dp[1]=0;

    dp[0]=0;

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

    repd(i,3,n)

    {

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



    }

    cout<<dp[n];

    return 0;

}



inline void getInt(int* p) {

    char ch;

    do {

        ch = getchar();

    } while (ch == ' ' || ch == '\n');

    if (ch == '-') {

        *p = -(getchar() - '0');

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 - ch + '0';

        }

    }

    else {

        *p = ch - '0';

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 + ch - '0';

        }

    }

}

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



using namespace std;



const int maxn = 1e5+5;

int n;

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

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	scanf("%d",&n);

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

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

	}

	f[0] = f[1] = 0;

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

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

	}

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

	return 0;

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

using namespace std;

const int mx = 100005;

int dp[mx];

int A[mx];

void memo(int i,int n)

{

	if(i>n) return;

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

	memo(i+1,n);

}

int main()

{

     int n;cin>>n;

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

     	cin>>A[i];

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

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

     memo(3,n);

     cout<<dp[n]<<endl;

     return 0;

}

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



using namespace std;



const int maxn = 1e5+5;

int n;

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

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	scanf("%d",&n);

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

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

	}

	f[0] = f[1] = 0;

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

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

	}

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

	return 0;

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

using namespace std;



#define INF 1e18;

#define MAX_N 100005

long long N, h[MAX_N], memo[MAX_N];



long long dp(int pos) {

  if (pos < 1) {

  	return INF;

  }

  if (pos == 1) {

  	return 0;

  }

  if (pos == 2) {

  	return abs(h[2] - h[1]);

  }

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

  	return memo[pos];

  }

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

}



int main() {

  cin >> N;

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

  	cin >> h[i];

  }

  /*

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

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

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

  }

  */

  /*

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

  	cout << i << ' ' << memo[i] << '\n';

  }

  */

  // cout << memo[N] << '\n';

  memset(memo, -1, sizeof memo);

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

}

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



using namespace std;



const int maxn = 1e5+5;

int n;

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

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	scanf("%d",&n);

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

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

	}

	f[0] = f[1] = 0;

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

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

	}

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

	return 0;

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

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

int a[100005],d[100005];

int main()

{

	int n,i;

	memset(a,0,sizeof(a));

	scanf("%d",&n);

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

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

	d[n] = 0;

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

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

	{

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

	}

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

	return 0;

}

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



using namespace std;



const int maxn = 1e5+5;

int n;

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

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	scanf("%d",&n);

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

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

	}

	f[0] = f[1] = 0;

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

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

	}

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

	return 0;

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

using namespace std;

int n , a[1000000] , frog , memo[1000000];



int f(int n){

	if(n == 1)return 0;

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

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

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

	return memo[n];

}

int main(){

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

	scanf("%d" , &n);

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

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

	}

	printf("%d" , f(n));

}

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



using namespace std;



const int maxn = 1e5+5;

int n;

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

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	scanf("%d",&n);

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

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

	}

	f[0] = f[1] = 0;

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

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

	}

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

	return 0;

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



using namespace std;

int main(){

	long long n,a[100000],dp[100000];

	scanf("%lld", &n);

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

		scanf("%lld", &a[i]);

	}

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

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

	for(long long 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("%lld", dp[n-1]);

}


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



using namespace std;



const int maxn = 1e5+5;

int n;

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

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	scanf("%d",&n);

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

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

	}

	f[0] = f[1] = 0;

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

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

	}

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

	return 0;

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

 

#define ll long long

#define X first

#define Y second

#define MP make_pair

#define ld long double

 

using namespace std;

 

const int N = 5e5 + 123;

const ll mod = 1e9 + 7;



ll a[N], dp[N];

int n;



int main (){

	ios::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);



	cin >> n;

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

		cin >> a[i];

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

		int x = i - 1, y = max(1, i - 2);

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

	}

	cout << dp[n];

}

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



using namespace std;



const int maxn = 1e5+5;

int n;

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

int h[maxn],f[maxn];



int abs(int x,int y) {

	if (x - y < 0) return y - x;

	return x - y;

}



int min(int x,int y) {

	if (x < y) return x;

	return y;

}



int main() {

	scanf("%d",&n);

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

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

	}

	f[0] = f[1] = 0;

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

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

	}

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

	return 0;

}