stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
// Created by ahmed_drawy on 10/09/19.

///dp educational contest atcoder - vjudge

#include <bits/stdc++.h>

#include <string.h>

#pragma clang diagnostic push

#pragma ide diagnostic ignored "OCUnusedMacroInspection"

using namespace std;

#define lp(i,start , end)       for(int i = start ; i<end ; ++i)

#define lllp(i,start , end)       for(ll i = start ; i<end ; ++i)

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

#define Rlp(i,start , end)      for(int i = start ; i>end ; --i)

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

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

#define clr(v,d)                memset(v , d , sizeof(v))

#define inf 0x3f3f3f3f

//#define dbg (v)    for(auto it : v)cout<<it<<' ';

typedef long long               ll;

typedef vector<int>             vi;

typedef vector  <ll>            vll;

typedef vector<vector<int> >    adj;

typedef pair<int ,int>          pii;

const double EPS =1e-7;

const int OO = 1e6;

#define endl '\n'

#define cint(c) (int)c -'0';

#define itc(c) (char)c +'A';

bool sortpair( const pair<int , int> & x, const pair<int , int> & y){

    return  x.first != y.first ? x.first < y.first : x.second > y.second ;

}

int dcomp(double x , double y){

    return fabs(x-y) <= EPS? 0: x>y?1:-1;

}



void smile() {

    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);

#ifndef ONLINE_JUDGE

//    freopen("/home/tw3/Desktop/Desktop/training/in.txt", "r", stdin);

//    freopen("/home/tw3/Desktop/Desktop/training/out.txt" , "w" , stdout);

#endif

}

#define fastin smile()



int n ;

const int N = 1e5 +3;

ll dp[N];

int h[N];

//ll solve(int indx , int state){

//    if(indx == n-1 )return 0 ;

//    ll &ret = dp[indx  ] [ state];

//    if(~ret )

//        return ret;

//    ret=  INT_MAX;

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

//        ret = min(ret , abs(h[indx]  - h[indx+ i])+solve(indx + i , i ));

//    }

//    return ret ;

//}

int main() {

    fastin;

    cin >> n;

    inN(h,  n );

    clr(dp , 0);

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

        if(j>=2){

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

        }

        else if(j ==1){

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

        }

    }

    cout << dp[n-1];

//

//    clr(dp , -1);

//    cout << solve(0, 1)<<endl;

}

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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

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

	

	return 0;

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

using namespace std;

typedef long long int ll;

const int MAX=1e5+10;

int N,A[MAX],dp[MAX];

int solve(int idx)

{

    if(idx==N)return 0;

    if(idx>N)return 1e9;

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

    return dp[idx]=min(abs(A[idx+1]-A[idx])+solve(idx+1),abs(A[idx+2]-A[idx])+solve(idx+2));

}

int  main ()

{

    memset(dp,-1,sizeof dp);

    cin >> N;

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

        cin >> A[i];

    }

    cout<<solve(1)<<endl;

    return 0;

}


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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

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

	

	return 0;

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

#include <cstdint>

#include <cinttypes>

#include <algorithm>

#include <cstring>



using i32 = std::int_fast32_t;

using i64 = std::int_fast64_t;



inline i32 diff(i32 x, i32 y) {

	return x > y ? x - y : y - x;

}



const int MaxN = 100001;



i32 A[MaxN], dp[MaxN];



signed main(signed argc, char **argv) {

	i32 n;

	scanf("%" SCNdFAST32, &n);



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

		scanf("%" SCNdFAST32, A + i);

	}



	memset(dp, 0x3f, sizeof dp);



	dp[0] = 0;

	dp[1] = diff(A[0], A[1]);

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

		dp[i] = std::min(dp[i - 1] + diff(A[i], A[i - 1]), dp[i - 2] + diff(A[i], A[i - 2]));

	}



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

	return 0;

}

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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

	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>



#include <cmath>

#include <iomanip>



using namespace std;



int main()

{

  ios::sync_with_stdio(false);

  cin.tie(0);

  int n;

  cin >> n;

  int h[n];

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

    int cur;

    cin >> cur;

    h[i] = cur;

  }

  int minCosts[n];

  minCosts[0] = 0;

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

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

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

  }

  cout << minCosts[n-1] << "\n";

  return 0;

}

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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

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

	

	return 0;

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

#define LL long long

using namespace std;



//int cnt[26],cnt1[26];

int dp[100005];

int main(){

	int n;

	cin>>n;

	int ar[n];

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

		cin>>ar[i];

	}

	dp[0]=0;

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

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

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

	}

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

	return 0;

}


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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

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

	

	return 0;

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

using namespace std;

typedef vector<int> vi;

typedef vector<long long> vll;

typedef pair<int,int> pii;

typedef vector< pii > vii;



#define ll          long long

#define ff          first

#define ss          second

#define pb          push_back

#define mkp         make_pair

#define sz          size()



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

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

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

#define mem(a,b)    memset(a,b,sizeof(a))

#define pi          2*acos(0.0)

#define End         return 0;

#define nl endl



#define scan1(a)    scanf("%d",&a)

#define scan2(a,b)  scanf("%d %d",&a,&b)

#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)

#define scanl(a)    scanf("%lld",&a)

#define scanll(a,b) scanf("%lld %lld",&a,&b)

#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)



#define print1(a)    printf("%d",a)

#define print2(a,b)  printf("%d %d",a,b)

#define print3(a,b,c)  printf("%d %d %d",a,b,c)

#define printl(a)    printf("%lld",a)

#define printll(a,b) printf("%lld %lld",a,b)

#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)



#define MAXN        100000007

#define INF 0x3f3f3f3f

int main()

{

   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

   int n;

   cin>>n;

   vll v(n+3),vv(n+3);

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



   vv[1]=0;vv[2]=abs(v[2]-v[1]);

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

    vv[i]=min(vv[i-1]+abs(v[i]-v[i-1]), vv[i-2]+abs(v[i]-v[i-2]));

   }

   cout<<vv[n]<<endl;

   return 0;

}


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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

	printf("%d\n", dp[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]);		//nyari dp

	}

	

	cout << dp[n] << endl;

}

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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

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

	

	return 0;

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

using namespace std;



int n,h[100005],c[100005];



int main()

{

    cin>>n;

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

        cin>>h[i];

    c[1] = abs(h[0] - h[1]); c[2] = abs(h[0] - h[2]);

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

    {

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

    }

    cout<<c[n-1];

}


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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

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

	

	return 0;

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

using namespace std;



#define mp make_pair

#define pb push_back

#define st first

#define nd second

#define lb lower_bound

#define ub upper_bound



typedef long long ll;

typedef long double ld;

typedef pair<int,int> pi;

typedef pair<ll,ll> pll;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef vector<pi> vpi;

typedef vector<pll> vpll;



const ll oo=1e18;

const int MOD=1000000007;

const int INF=1000000000;

const ld EPS=0.000000001;



int dp[100005],h[100005],n,k=2;



signed main() {

    ios_base::sync_with_stdio(NULL);

    cin.tie(NULL);

    cout.tie(NULL);

    memset(dp,0x3f3f,sizeof dp);

    dp[1]=0;

    h[0]=0;

    cin>>n;

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

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

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

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

        }

    }

    cout<<dp[n];

    return 0;

}


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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

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

	

	return 0;

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

using namespace std;

long long n,h[100010],dp[100010];



int main()

{

	scanf("%lld",&n);

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

	{

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

	}

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

	{

		if(i-1>=0) dp[i] = dp[i-1]+abs(h[i-1]-h[i]);

		if(i>2)

		{

			

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

		}

	}

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

	return 0;

}

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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

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

	

	return 0;

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

#include<iostream>

#include<cmath>

#include<stack>

#include<cstring>

#include<algorithm>

using namespace std;

int n;

int h[100005];

int dp[100005];



int main()

{

memset(dp, 0x3f ,sizeof dp);

scanf("%d",&n);

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

dp[1] = 0;

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

{

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

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

}

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



	return 0;

}






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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

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

	

	return 0;

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

using namespace std;

#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'

const int N = 1e5;

const int inf = 1e9;

int A[N+7], dp[N+7];

int n;



int solve(int i) {

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

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

	int res1 = solve(i+1) + abs(A[i]-A[i+1]);

	int res2 = inf;

	if(i+2<=n-1) res2 = solve(i+2)+abs(A[i]-A[i+2]);

	return dp[i] = min(res1, res2);

}

int main(){

	ios_base::sync_with_stdio(0);

	int a,b,T,cas=0;

	cin>>n;

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

	fill(dp,dp+n,-1);

	int res=solve(0);

	cout<<res<<endl;

	return 0;

}

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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

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

	

	return 0;

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

#define ll long long

#define ull unsigned ll

#define ld long double

#define pll pair<ll, ll>

#define pii pair<int, int>

#define f first

#define se second

#define pb push_back

#define ft fflush(stdout)

 

 

using namespace std;

 

 

const int N = 2e5 + 123;

const int PLS = 3e5 + 123;

const int mod = 1e9 + 7;

const ll inf = 1e16;





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





int main() {

    ios_base::sync_with_stdio(NULL);

    cin.tie(NULL); cout.tie(NULL);

    cin >> n;

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

        cin >> a[i];

    dp[1] = 0;

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

    cout << dp[n];

}

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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

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

	

	return 0;

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

#include<cstdio>

#include<string>

#include<cstring>

#include<algorithm>

#include<queue>

#include<stack>

#include<map>

#include<vector>

#include<set>

#include<list>

#define ll long long

using namespace std;

ll h[200050],dp[200050];

int main()

{

	ll n;

	cin>>n;

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

		cin>>h[i];

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

	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.409634825902252x):
#include<stdio.h>

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

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

	

	return 0;

}
// Slower C++ solution:
//#pragma GCC target("avx2")

//#pragma GCC optimize("O3")

   

//#include <x86intrin.h>

#include <bits/stdc++.h>   

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

 

using namespace __gnu_pbds;

using namespace std;



template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

     

#define F first

#define S second           

#define lb lower_bound               

#define ub upper_bound

#define pb push_back

#define pf push_front    

#define ppb pop_back

#define mp make_pair                                     

#define bpp __builtin_popcountll                                                                                        

#define sqr(x) ((x) * (x)) 

#define al 0x3F3F3F3F

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

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

#define in insert

#define ppf pop_front

#define endl '\n'

//#define int long long

 

typedef unsigned long long ull;

typedef long long ll;

typedef long double ld;

typedef pair <int, int> pii;

 

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

const int N = (int)3e5 + 123;

const ll inf = (ll)1e18 + 1;



const double pi = acos (-1.0);

const double eps = 1e-7;                  

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

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



int n;

ll h[N];

ll dp[N];



inline void boost () {                    

   ios_base :: sync_with_stdio (NULL);

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

}                                                     



inline void Solve () {

   cin >> n;

   dp[1] = 0;

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

   for (int i = 2; i <= n; i ++) dp[i] = inf;

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

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

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

   }

   cout << dp[n];

}



main () {                                       

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

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

   boost ();

   int tt = 1;

   //cin >> tt;   

   while (tt --) {

      Solve ();

   }                                               

   return 0;      

}

                          

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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

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

	

	return 0;

}