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

using namespace std;

const int N = 1e5 + 100;

int n, h[N], mem[N];



int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);



	cin >> n;



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

		cin >> h[i];

	}



	mem[n - 2] = abs(h[n - 1] - h[n - 2]);



	for (int i = n - 3; i >= 0; i--) {

		int a1 = mem[i + 1] + abs(h[i] - h[i + 1]);

		int a2 = mem[i + 2] + abs(h[i] - h[i + 2]);

		mem[i] = min(a1, a2);

	}



	cout << mem[0] << '\n';

	

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

using namespace std;

const int N = 1e5 + 100;

int n, h[N], mem[N];



int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);



	cin >> n;



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

		cin >> h[i];

	}



	mem[n - 2] = abs(h[n - 1] - h[n - 2]);



	for (int i = n - 3; i >= 0; i--) {

		int a1 = mem[i + 1] + abs(h[i] - h[i + 1]);

		int a2 = mem[i + 2] + abs(h[i] - h[i + 2]);

		mem[i] = min(a1, a2);

	}



	cout << mem[0] << '\n';

	

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

using namespace std;

const int N = 1e5 + 100;

int n, h[N], mem[N];



int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);



	cin >> n;



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

		cin >> h[i];

	}



	mem[n - 2] = abs(h[n - 1] - h[n - 2]);



	for (int i = n - 3; i >= 0; i--) {

		int a1 = mem[i + 1] + abs(h[i] - h[i + 1]);

		int a2 = mem[i + 2] + abs(h[i] - h[i + 2]);

		mem[i] = min(a1, a2);

	}



	cout << mem[0] << '\n';

	

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

using namespace std;

const int N = 1e5 + 100;

int n, h[N], mem[N];



int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);



	cin >> n;



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

		cin >> h[i];

	}



	mem[n - 2] = abs(h[n - 1] - h[n - 2]);



	for (int i = n - 3; i >= 0; i--) {

		int a1 = mem[i + 1] + abs(h[i] - h[i + 1]);

		int a2 = mem[i + 2] + abs(h[i] - h[i + 2]);

		mem[i] = min(a1, a2);

	}



	cout << mem[0] << '\n';

	

	return 0;

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

using namespace std;

#define ll long long

ll dp[100009];

ll n,x;

vector<ll>v;

ll frog(ll pos)

{

    if(pos<=0)

        return 0;

    if(pos==1)

        return abs(v[0]-v[1]);

        if(dp[pos]==-1)

        {

            dp[pos]= min(abs(v[pos]-v[pos-1])+frog(pos-1),abs(v[pos]-v[pos-2])+frog(pos-2));

        }

    return dp[pos];

}



int main()

{

    cin>>n;

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

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

    {

        cin>>x;

        v.push_back(x);

    }

    cout<<frog(n-1)<<endl;

}


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

using namespace std;

const int N = 1e5 + 100;

int n, h[N], mem[N];



int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);



	cin >> n;



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

		cin >> h[i];

	}



	mem[n - 2] = abs(h[n - 1] - h[n - 2]);



	for (int i = n - 3; i >= 0; i--) {

		int a1 = mem[i + 1] + abs(h[i] - h[i + 1]);

		int a2 = mem[i + 2] + abs(h[i] - h[i + 2]);

		mem[i] = min(a1, a2);

	}



	cout << mem[0] << '\n';

	

	return 0;

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



using namespace std;

int v[1000010];

int memo[1000010];

int c;



int f(int i)

{



    if(memo[i]!=-1)

        return memo[i];



    if(i == 0)

        return memo[0] = 0;



    if(i == 1)

        return memo[1] = abs(v[0] - v[1]);



    return memo[i] = min(abs(v[i] - v[i-1]) + f(i-1), abs(v[i] - v[i-2]) + f(i-2));

}



int main()

{



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

    cin>>c;



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

    {

        cin>>v[i];

    }



    cout<<f(c-1)<<endl;



    return 0;

}

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

using namespace std;

const int N = 1e5 + 100;

int n, h[N], mem[N];



int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);



	cin >> n;



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

		cin >> h[i];

	}



	mem[n - 2] = abs(h[n - 1] - h[n - 2]);



	for (int i = n - 3; i >= 0; i--) {

		int a1 = mem[i + 1] + abs(h[i] - h[i + 1]);

		int a2 = mem[i + 2] + abs(h[i] - h[i + 2]);

		mem[i] = min(a1, a2);

	}



	cout << mem[0] << '\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: 1.3842482116778778x):
#include <bits/stdc++.h>

using namespace std;

const long long mk=100005;

long long arr[mk];

long long n, dp[mk];

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	dp[0]=0;

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

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

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

	}

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

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

using namespace std;

const long long mk=100005;

long long arr[mk];

long long n, dp[mk];

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	dp[0]=0;

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

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

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

	}

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

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

using namespace std;

const long long mk=100005;

long long arr[mk];

long long n, dp[mk];

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	dp[0]=0;

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

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

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

	}

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

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

using namespace std;

const long long mk=100005;

long long arr[mk];

long long n, dp[mk];

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	dp[0]=0;

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

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

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

	}

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

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

using namespace std;

const long long mk=100005;

long long arr[mk];

long long n, dp[mk];

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	dp[0]=0;

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

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

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

	}

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

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

using namespace std;

const long long mk=100005;

long long arr[mk];

long long n, dp[mk];

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	dp[0]=0;

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

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

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

	}

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

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

using namespace std;

const long long mk=100005;

long long arr[mk];

long long n, dp[mk];

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	dp[0]=0;

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

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

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

	}

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

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

using namespace std;

const long long mk=100005;

long long arr[mk];

long long n, dp[mk];

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	dp[0]=0;

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

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

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

	}

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

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

using namespace std;

#define ll long long

ll dp[100009];

ll n,x;

vector<ll>v;

ll frog(ll pos)

{

    if(pos<=0)

        return 0;

    if(pos==1)

        return abs(v[0]-v[1]);

        if(dp[pos]==-1)

        {

            dp[pos]= min(abs(v[pos]-v[pos-1])+frog(pos-1),abs(v[pos]-v[pos-2])+frog(pos-2));

        }

    return dp[pos];

}



int main()

{

    cin>>n;

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

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

    {

        cin>>x;

        v.push_back(x);

    }

    cout<<frog(n-1)<<endl;

}


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

using namespace std;

const long long mk=100005;

long long arr[mk];

long long n, dp[mk];

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	dp[0]=0;

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

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

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

	}

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

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



using namespace std;

int v[1000010];

int memo[1000010];

int c;



int f(int i)

{



    if(memo[i]!=-1)

        return memo[i];



    if(i == 0)

        return memo[0] = 0;



    if(i == 1)

        return memo[1] = abs(v[0] - v[1]);



    return memo[i] = min(abs(v[i] - v[i-1]) + f(i-1), abs(v[i] - v[i-2]) + f(i-2));

}



int main()

{



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

    cin>>c;



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

    {

        cin>>v[i];

    }



    cout<<f(c-1)<<endl;



    return 0;

}

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

using namespace std;

const long long mk=100005;

long long arr[mk];

long long n, dp[mk];

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	dp[0]=0;

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

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

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

	}

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

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

using namespace std;

int h[100001];

int dp[100001];

int n;

int solve(int stone)

{

    if(stone+1==n) return dp[stone]=abs(h[stone]-h[stone+1]);

    if(stone+2==n) return dp[stone+2]=abs(h[stone]-h[stone+2]);

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

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

}



int main()

{

    int i;

    scanf("%d",&n);



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

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



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

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





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

using namespace std;

int h[100001];

int dp[100001];

int n;

int solve(int stone)

{

    if(stone+1==n) return dp[stone]=abs(h[stone]-h[stone+1]);

    if(stone+2==n) return dp[stone+2]=abs(h[stone]-h[stone+2]);

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

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

}



int main()

{

    int i;

    scanf("%d",&n);



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

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



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

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





    return 0;

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

using namespace std;

#define ll long long

ll dp[100009];

ll n,x;

vector<ll>v;

ll frog(ll pos)

{

    if(pos<=0)

        return 0;

    if(pos==1)

        return abs(v[0]-v[1]);

        if(dp[pos]==-1)

        {

            dp[pos]= min(abs(v[pos]-v[pos-1])+frog(pos-1),abs(v[pos]-v[pos-2])+frog(pos-2));

        }

    return dp[pos];

}



int main()

{

    cin>>n;

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

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

    {

        cin>>x;

        v.push_back(x);

    }

    cout<<frog(n-1)<<endl;

}


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

using namespace std;

int h[100001];

int dp[100001];

int n;

int solve(int stone)

{

    if(stone+1==n) return dp[stone]=abs(h[stone]-h[stone+1]);

    if(stone+2==n) return dp[stone+2]=abs(h[stone]-h[stone+2]);

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

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

}



int main()

{

    int i;

    scanf("%d",&n);



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

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



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

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





    return 0;

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



using namespace std;

int v[1000010];

int memo[1000010];

int c;



int f(int i)

{



    if(memo[i]!=-1)

        return memo[i];



    if(i == 0)

        return memo[0] = 0;



    if(i == 1)

        return memo[1] = abs(v[0] - v[1]);



    return memo[i] = min(abs(v[i] - v[i-1]) + f(i-1), abs(v[i] - v[i-2]) + f(i-2));

}



int main()

{



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

    cin>>c;



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

    {

        cin>>v[i];

    }



    cout<<f(c-1)<<endl;



    return 0;

}

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

using namespace std;

int h[100001];

int dp[100001];

int n;

int solve(int stone)

{

    if(stone+1==n) return dp[stone]=abs(h[stone]-h[stone+1]);

    if(stone+2==n) return dp[stone+2]=abs(h[stone]-h[stone+2]);

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

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

}



int main()

{

    int i;

    scanf("%d",&n);



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

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



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

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





    return 0;

}