stablegradients/pie-gem5-pairs huggingface dataset:
// 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: 1.38262700595126x):
#include <bits/stdc++.h>

using ll = long long;

using namespace std;



int n, k = 2;

int arr[100100], dp[100100];

bool vis[100100];



int func( int pos ) {

  if (pos == n) return 0;

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

  vis[pos] = 1;

  int res = INT_MAX;

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

    if (pos + i > n) break;

    res = min(res, func(pos + i) + abs(arr[pos] - arr[pos + i]));

  }

  return dp[pos] = res;

}



int main() {

  ios::sync_with_stdio(false);

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



  cin >> n;

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

  cout << func(1) << endl;

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

using ll = long long;

using namespace std;



int n, k = 2;

int arr[100100], dp[100100];

bool vis[100100];



int func( int pos ) {

  if (pos == n) return 0;

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

  vis[pos] = 1;

  int res = INT_MAX;

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

    if (pos + i > n) break;

    res = min(res, func(pos + i) + abs(arr[pos] - arr[pos + i]));

  }

  return dp[pos] = res;

}



int main() {

  ios::sync_with_stdio(false);

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



  cin >> n;

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

  cout << func(1) << endl;

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

using ll = long long;

using namespace std;



int n, k = 2;

int arr[100100], dp[100100];

bool vis[100100];



int func( int pos ) {

  if (pos == n) return 0;

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

  vis[pos] = 1;

  int res = INT_MAX;

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

    if (pos + i > n) break;

    res = min(res, func(pos + i) + abs(arr[pos] - arr[pos + i]));

  }

  return dp[pos] = res;

}



int main() {

  ios::sync_with_stdio(false);

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



  cin >> n;

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

  cout << func(1) << endl;

  return 0;

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

using namespace std;

int arr[100010],n;

int dp[100010];

int f(int pos){

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

	int &ret=dp[pos];

	if(ret^-1)return ret;

	if(pos+1==n-1)return ret=abs(arr[pos+1]-arr[pos]);

	return ret=min(f(pos+1)+abs(arr[pos]-arr[pos+1]),f(pos+2)+abs(arr[pos]-arr[pos+2]));

}



int main(int argc, char const *argv[])

{

	memset(dp,-1,sizeof dp);

	cin>>n;

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

		cout<<f(0)<<endl;

	return 0;

}

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

using ll = long long;

using namespace std;



int n, k = 2;

int arr[100100], dp[100100];

bool vis[100100];



int func( int pos ) {

  if (pos == n) return 0;

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

  vis[pos] = 1;

  int res = INT_MAX;

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

    if (pos + i > n) break;

    res = min(res, func(pos + i) + abs(arr[pos] - arr[pos + i]));

  }

  return dp[pos] = res;

}



int main() {

  ios::sync_with_stdio(false);

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



  cin >> n;

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

  cout << func(1) << endl;

  return 0;

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

#define ll long long

using namespace std;

const int maxn = 1e5+5;

int a[maxn], dp[maxn];



int main(){

	int n; cin >> n;

	memset(dp, 0x3f, sizeof dp);

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

	dp[1] = 0;

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

		dp[i] = min(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;

}

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

using ll = long long;

using namespace std;



int n, k = 2;

int arr[100100], dp[100100];

bool vis[100100];



int func( int pos ) {

  if (pos == n) return 0;

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

  vis[pos] = 1;

  int res = INT_MAX;

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

    if (pos + i > n) break;

    res = min(res, func(pos + i) + abs(arr[pos] - arr[pos + i]));

  }

  return dp[pos] = res;

}



int main() {

  ios::sync_with_stdio(false);

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



  cin >> n;

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

  cout << func(1) << endl;

  return 0;

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

using namespace std;

int dif(int a, int b)

{

    int ans=a-b;

    if(ans<0) ans*=-1;

    return ans;

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int N, h[100005],i,j;

    int f1,f2;

    cin>>N;

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

        cin>>h[i];

    int M[100005]={0};

    M[N-2]=dif(h[N-1],h[N-2]);

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

    {

        f1=dif(h[i+1],h[i])+M[i+1];

        f2=dif(h[i+2],h[i])+M[i+2];

        M[i]=min(f1,f2);

    }

    cout<<M[0]<<endl;

    return 0;

}


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

#include<time.h>

#include<math.h>

#include<stdlib.h>

#include<iostream>

#include<iomanip>

#include<utility>

#include<algorithm>

#include<stack>

#include<queue>

#include<map>

#include<set>

#define ll long long

#define fi first

#define sec second

#define pb push_back

#define mp make_pair

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

#define repp(a,b,c,d) for(int a=b;a<=c;a+=d)



const double PI=acos(-1);

const double EPS=1e-12;

const int MOD=1e9+7;

const int INF=1<<30;





using namespace std;



int dat[100005];

int minn[100005];



int main(){

	int in;

	cin>>in;

	rep(i,in,1){

		cin>>dat[i];

	}

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

		if(i==in-1){

			minn[i]+=abs(dat[i]-dat[i+1]);

		}

		else{

			minn[i]+=min(abs(dat[i]-dat[i+1])+minn[i+1],abs(dat[i]-dat[i+2])+minn[i+2]);

		}

	}

	cout<<minn[1]<<endl;	

	return 0;

}

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

#define ll long long

using namespace std;



int main(){

    ll n,a[100009],dp[100009],k;

    cin >> n ;

    k=2;

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

    dp[n]=0;

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

        ll z=1e15;

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

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

        }

        dp[i]=z;

    }

    cout << dp[1] << endl;

}




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

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

	scanf("%lld", &n);

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

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

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

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

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

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

	}

	printf("%lld", b[n-1]);

}


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



long long absdif(long long a, long long b){

	return ( a > b ) ? a-b: b-a;

}



int main(){

	int N;

	std::vector<long long> h, dp;

	std::cin >> N;

	h.resize(N);

	dp.resize(N+1);

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

		std::cin >> h[i];

	}



	dp[0] = 0;

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

		dp[i] = 1e9+9;

		if( i-1 >= 0 )

			dp[i] = std::min(dp[i], dp[i-1] + absdif(h[i], h[i-1]) );

		if( i-2 >= 0 )

			dp[i] = std::min(dp[i], dp[i-2] + absdif(h[i], h[i-2]) );

	}

	std::cout << dp[N-1] << '\n';

	return 0;

}

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

#include<iostream>

#include<algorithm>

#include<queue>

#define inf 0x3f3f3f3f

using namespace std;

typedef long long LL;

const int maxn = 1e5+5;



int a[maxn],dp[maxn];



int main(){

	int n;

	scanf("%d",&n);

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

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

	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-2] -a[i]));

	}

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

}

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

int h[1000005], memo[1000005];

int f(int n) {

    if(n == 1) {                        // bisa juga base case nya n = 0, f(0) harus tinggi, misal 1e9;

        return 0;

    }

    if(n == 2) {

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

    } 

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

        return memo[n];

    }

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

    return memo[n];

}



int main() {

    scanf("%d", &n);

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

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

    }

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

    f(n);

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

}

// Faster C++ solution for the same problem (measured speedup: 23.654139169342923x):
#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 db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'

const int N = 1e6;

const int inf = 1e9;



int main(){

	ios_base::sync_with_stdio(0);

	int a,b,n,T,cas=0;

	cin>>n;

	vector<int> A(n);

	for(int &x: A) {

		cin>>x;

	}

	vector<int> dp(n, inf);

	dp[0]=0;

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

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

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

		}

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.736841419950621x):
#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 N = 2e5 + 100;

#define pb push_back

#define mp make_pair

#define f first

#define s second

#define ull unsigned long long

#define ll long long

#define pii pair <int,int>

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

#define FOR(l,i,n) for(int i = l;i < n;++i)

#define all(v) v.begin(), v.end()

#define pll pair <ll,ll>

const ll inf = 1e9 + 7;

const ll ll_inf = 1e17 + 100;   

const double pi = 3.14159265358979323;

inline void fr(){

    freopen("gcd.in", "r", stdin);

    freopen("gcd.out", "w", stdout);

}

void boost()

{

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);

}

 

ll binpow (ll a, ll n)

{

    ll res = 1;

    while (n) {

        if (n & 1)

        {

            res *= a;

            res %= inf;

        }

        a *= a;

        n >>= 1;

        a %= inf;

    }

    return res;

}

        

int n;

int h[N];

int dp[N];

 

main()	

{                                                                        

	cin >> n;

	dp[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];

}	 


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

 

#define mp make_pair

#define pb push_back

#define f first

#define s second

#define ll long long

#define int ll

#define forn(i, a, b) for(int i = (a); i <= (b); ++i)

#define forev(i, b, a) for(int i = (b); i >= (a); --i)

#define VAR(v, i) __typeof( i) v=(i)

#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)

#define all(x) (x).begin(), (x).end()

#define sz(x) ((int)(x).size())

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);

 

using namespace std;

 

const int maxn = (int)1e5 + 100;

const int mod = (int)1e9 + 7;

 

#define inf mod

 

typedef long double ld;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;   

typedef vector<ll> Vll;               

typedef vector<pair<int, int> > vpii;

typedef vector<pair<ll, ll> > vpll;

 

int n, dp[maxn];

int h[maxn];

main () {

	cin >> n;

	forn(i, 1, n)

		cin >> h[i];

	dp[1] = 0;

	forn(i, 2, n){

		dp[i] = inf * inf;

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

		if(i > 2)

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

	}

	cout << dp[n];



}

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

typedef long double ld;

typedef unsigned long long ull;

 

#define nl '\n'

 

#define y1 aza_ibagaliev

 

#define f first

#define s second

	

#define ed end()

#define bg begin()

#define rbg rbegin()

 

#define rv reverse

#define mp make_pair

#define pb push_back

#define ppb pop_back

#define ppf pop_front

 

#define sz size()

#define all(x) x.bg, x.ed

 

#define pll pair < ll, ll >

#define pii pair < int, int >

 

#define sqr(x) ((x) * 1ll * (x))

#define sqrd(x) ((x) * 1.0 * (x))

 

#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

 

#define rnl cout << "----------------------------------------" << nl

 

#define bit __builtin_popcount

 

inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}

        	

const int ppr = 257;

const ll INF = 2e18;

const int inf = 998244353;

const int mod = 1e9 + 7;

const int N = 1e5 + 123;

const ld pi = 3.1741592653589793238462643;

 

const int dx[] = {1, 0, -1, 0};

const int dy[] = {0, 1, 0, -1};



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



main() {             	

//  freopen(".in", "r", stdin);

//  freopen(".out", "w", stdout);



//	srand(time(NULL));



	scanf("%d", &n);



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

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



		if(i == 1) continue;



		dp[i] = inf;

		dp[i] = min(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];

             

    return 0;                                        

}

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

}