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

using namespace std;

typedef long long ll;

const int N=1e6;

const ll inf=1e6;

int n,a[N];

ll dp[N];

ll f(int i)

{

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

    if(i==n) return 0;

    ll p1=inf,p2=inf;

    if(i<=(n-1)) p1=abs(a[i]-a[i+1])+f(i+1);

    if(i<=(n-2)) p2=abs(a[i]-a[i+2])+f(i+2);

    dp[i]=min(p1,p2);

    return dp[i];

}

int main()

{

    scanf("%d",&n);

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

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

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

    printf("%lld",f(1));

    //while(1);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 9.175677349711675x):
/*

#include "stdafx.h"

#include<iostream>

#include<vector>

#include<algorithm>

#include<queue>

#include<stack>

#include<cmath>

#include<complex>

*/



#include<bits/stdc++.h>



#define X real()

#define Y imag()

#define pb push_back

#define ppb pop_back

#define mp make_pair

#define ff first

#define ss second

#define FastF freopen("in.txt","r",stdin); freopen("out.txt","w",stdout)

#define Fast cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0)

using ll = long long;

using namespace std;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;

typedef vi::iterator vii;

typedef vector<ll> vl;

typedef vl::iterator vli;

typedef long double C;

typedef complex<C> P;

const int INF = 1e9 + 5;

const ll INFF = 1e18 + 5;

const int M = 1e9 + 7;

const double pi = acos(-1);



int main()

{

	//FastF;

	Fast;

	int n; cin >> n;

	vi h(n + 2);

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

		cin >> h[i];

	}

	vi dp(n + 2,INF);

	dp[0] = 0;

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

		for (int j : {i + 1, i + 2}) {

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

		}

	}

	cout << dp[n - 1] << '\n';

	return 0;

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

using namespace std;

const int N=1e5+1;

vector<int> h(N);

const int INF=1e9+5;

vector<int> dp(N,-1);

int n;

int f(int i){

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

    if(i>n) return INF;

    if(i==n) return 0;

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

}

int main(){

    scanf("%d",&n);

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

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

    }

    cout<<f(1)<<'\n';

    //while(1);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.7713211080902487x):
/*

#include "stdafx.h"

#include<iostream>

#include<vector>

#include<algorithm>

#include<queue>

#include<stack>

#include<cmath>

#include<complex>

*/



#include<bits/stdc++.h>



#define X real()

#define Y imag()

#define pb push_back

#define ppb pop_back

#define mp make_pair

#define ff first

#define ss second

#define FastF freopen("in.txt","r",stdin); freopen("out.txt","w",stdout)

#define Fast cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0)

using ll = long long;

using namespace std;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;

typedef vi::iterator vii;

typedef vector<ll> vl;

typedef vl::iterator vli;

typedef long double C;

typedef complex<C> P;

const int INF = 1e9 + 5;

const ll INFF = 1e18 + 5;

const int M = 1e9 + 7;

const double pi = acos(-1);



int main()

{

	//FastF;

	Fast;

	int n; cin >> n;

	vi h(n + 2);

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

		cin >> h[i];

	}

	vi dp(n + 2,INF);

	dp[0] = 0;

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

		for (int j : {i + 1, i + 2}) {

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

		}

	}

	cout << dp[n - 1] << '\n';

	return 0;

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

using namespace std;

const int N=1e5+1;

vector<int> h(N);

const int INF=1e9+5;

vector<int> dp(N,INF);

int n;

int main(){

    scanf("%d",&n);

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

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

    }

    dp[1]=0;

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

        for(int j:{i+1,i+2}){

            if(j<=n){

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

            }

        }

    }

    cout<<dp[n];

    // while(1);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.761978668149235x):
/*

#include "stdafx.h"

#include<iostream>

#include<vector>

#include<algorithm>

#include<queue>

#include<stack>

#include<cmath>

#include<complex>

*/



#include<bits/stdc++.h>



#define X real()

#define Y imag()

#define pb push_back

#define ppb pop_back

#define mp make_pair

#define ff first

#define ss second

#define FastF freopen("in.txt","r",stdin); freopen("out.txt","w",stdout)

#define Fast cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0)

using ll = long long;

using namespace std;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;

typedef vi::iterator vii;

typedef vector<ll> vl;

typedef vl::iterator vli;

typedef long double C;

typedef complex<C> P;

const int INF = 1e9 + 5;

const ll INFF = 1e18 + 5;

const int M = 1e9 + 7;

const double pi = acos(-1);



int main()

{

	//FastF;

	Fast;

	int n; cin >> n;

	vi h(n + 2);

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

		cin >> h[i];

	}

	vi dp(n + 2,INF);

	dp[0] = 0;

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

		for (int j : {i + 1, i + 2}) {

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

		}

	}

	cout << dp[n - 1] << '\n';

	return 0;

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

#include<vector>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

typedef long long ll;

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

#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";

#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define MAX 100005



int main(){

    int n;

    cin>>n;

    int height[n+1];

    ip(height, n);

    

    ll dp[MAX]={0};

    

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

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

    }

    cout<<dp[n]<<endl;

    return 0;

}

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

#include<vector>

#include<cstring>

using namespace std;

typedef long long ll;

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

#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";

#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define MAX 100005



int n;

ll arr[MAX], dp[MAX]={0};;



void bottomUp(){

    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;

}



// ll topDown(int pos){

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



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



// }

int main(){

    cin>>n;

    ip(arr, n);

    bottomUp();

    return 0;

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

using namespace std;

typedef long long ll;

ll sum=0;

vector<ll> sl;

ll dp[100000];

ll func(ll a[],ll n,ll size)

{

	if(dp[n]>=0)

	return dp[n];

	else

	{



		//cout<<"fghjrtghj";

	ll sum=dp[n-1]+abs(a[n]-a[n-1]);

	ll su=dp[n-2]+abs(a[n]-a[n-2]);

	dp[n]=min(sum,su);

	if(n+1==size)

	return dp[n];

	else

	return func(a,n+1,size);

}

}

main()

{

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

	cin>>n;

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

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

	cin>>a[i];

	dp[0]=0;

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

	if(n>2)

	cout<<func(a,2,n);

	else

	cout<<dp[n-1];

	

}

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

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;

#define lb lower_bound

#define ub upper_bound

#define pb push_back

#define mp make_pair

const ll inf=1e9+2;

int32_t main()

{

	IOS

	ll n,i,j;

	cin>>n;

	vector<ll>v(n),dp(n,inf);

	for(auto &x:v)

		cin>>x;

	dp[0]=0;

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

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

	{

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

	}

	cout<<dp[n-1];

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

#include<cstdio>

#include<algorithm>

#include<cmath>

#include<vector>

#include<map>

#include<set>

#include<string>

#include<queue>

#include<stack>

using namespace std;

#define MOD 1000000007

#define INF (1<<29)

#define EPS (1e-10)

typedef long long Int;

typedef pair<Int, Int> P;



#define max(x, y) ((x)>(y)?(x):(y))

#define min(x, y) ((x)<(y)?(x):(y))



Int n;

Int h[108000];

Int dp[108000];

int main(){

  cin >> n;

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

  fill(dp, dp + 108000, INF);

  dp[1] = 0;

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

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

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

  }

  cout << dp[n] << endl;

  return 0;

}

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

#include<cstdio>

#include<algorithm>

#include<cassert>

#include<cmath>

#include<vector>

#include<map>

#include<set>

#include<string>

#include<queue>

#include<stack>

using namespace std;

#define MOD 1000000007

#define MOD2 998244353

#define INF ((1<<30)-1)

#define LINF (1LL<<60)

#define EPS (1e-10)

typedef long long Int;

typedef pair<Int, Int> P;





Int dp[110000];

Int n, h[110000];



int main(){

    cin >> n;

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



    dp[0] = 0;

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

        if(i == 1){

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

        }

        else{

            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;

    return 0;

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

#define ll long long

#define PI 3.141592653589

#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define EPS 1e-9

#define f first

#define s second

using namespace std;

int n;

int arr[100005];

ll memo[100005];

ll solve(int idx){

    if (idx==n-1)

        return 0;

    ll &res = memo[idx];

    if(res != -1)

        return res;

    if(idx==n-2)

        return res = abs(arr[n-1]-arr[n-2]);

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

}

int main(){

    IO;

    cin >> n;

    memset(memo, -1, sizeof memo);

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

        cin >> arr[i];

    cout << solve(0);



    return 0;

}


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

#define ll long long

#define PI 3.141592653589

#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define EPS 1e-7

#define f first

#define s second

using namespace std;

int main() {

    IO;

    int n;

    cin >> n;

    int arr[n];

    int dp[3];

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

        cin >> arr[i];

    dp[0] = 0;

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

    int itr = 2;

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

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

        itr = (itr+1)%3;

    }

    cout << dp[(itr+2)%3];

    return 0;

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

#define int long long int

#define pb push_back

#define pp pop_back

#define pii pair<int,int>

#define vec vector<int>

#define mp make_pair

using namespace std;

int dp[100001],h[100001];

int ans(int n)

{

  if(n==1)

    return 0;

  if(dp[n]!=-1)

        return dp[n];

  if(n==2)

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

  else

  {

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

  }

}

int32_t main()

{

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);

  cout.tie(NULL);

  int t=1;

  //cin>>t;

  while(t--)

  {

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

    int n;

    cin>>n;

    int i;

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

        cin>>h[i];

    cout<<ans(n);

  }

}

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

#define int long long int

#define pb push_back

#define pp pop_back

#define pii pair<int,int>

#define vec vector<int>

#define mp make_pair

using namespace std;

int32_t main()

{

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);

  cout.tie(NULL);

  int t=1;

  //cin>>t;

  while(t--)

  {

    int n;

    cin>>n;

    int h[n+1],i;

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

        cin>>h[i];

    int dp[n+1]={0};

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

    {

      if(i==2)

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

      else

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

    }

    cout<<dp[n];

  }

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

#define fr first

#define sc second

#define memset(X,Y) memset(X,Y,sizeof X)

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

#define sz size()

#define pb push_back

#define ve vector<int>

#define pii pair < int,int >

#define pll pair < ll,ll >

#define ll long long

#define Graph vector<vector < int > >

#define Fp cout << fixed <<  setprecision(9)

#define Fast  ios::sync_with_stdio(0); cin.tie(0);

using namespace std;

const int M = 1e6+30 , N= 1e5+20 , MOD = 1e9+7 , OO = 1e7;

int m ,n ,k , x, y , dp[N] , bla ,c=1,cnt ,ans,sum , a[N] , ok=1 ;

pii p[N];

ve v;

set <ll> ss;

string s[N] ,t;

map < int , int > mp;

Graph G ;

int Dp(int i){



if(i>=n) return OO;

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

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

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







}



int main() {

memset(dp , -1);

cin >> n ;

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

cout << Dp(0);

return 0;

}


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

#define fr first

#define sc second

#define memset(X,Y) memset(X,Y,sizeof X)

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

#define sz size()

#define pb push_back

#define ve vector<int>

#define pii pair < int,int >

#define pll pair < ll,ll >

#define ll long long

#define Graph vector<vector < int > >

#define Fp cout << fixed <<  setprecision(9)

#define Fast  ios::sync_with_stdio(0); cin.tie(0);

using namespace std;

const ll M = 1e3+30 , N= 1e5+30 , MOD = 1e9+7 , OO = 1e7;

ll m ,n ,k , x, y , dp[N] , bla ,c=1,cnt ,ans,sum , a[N] , ok=1 ;

int main(){



cin >> n  ;

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

  cin >> a[i];

}

for(int i=0;i<=n;i++) dp[i] = OO;

dp[1] = 0;

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

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

     }



cout << dp[n];

return 0;

}

/*

6 15= max

6 5

5 6

6 4

6 6

3 5

7 2

*/
// Slower C++ solution:


#include<bits/stdc++.h>

using namespace std;



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

#define ll long long

#define ld long double

#define pb push_back

#define fe first

#define se second

#define nl "\n"

#define pp pair < ll , ll > 

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

#define st(x) sort(x.begin(),x.end())

#define rst(x) sort(x.rbegin(), x.rend())

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

long double pi = 3.14159265358979323;

 

const double EPS = 1e-12;

const int N = 1e5 + 5;

const int mod = 1e9 + 7;

 

ll dp[N] , h[N];

ll n;

ll fun(ll i){



  if(i == n - 1){

    return abs(h[i] - h[n]);

  }

  if(i >= n){

    return 0;

  }

  if(dp[i] != -1){

    return dp[i];

  }



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

  //return dp[n];

}

 

 

int main()

{

    fast;

    //ll n;

    cin >> n;

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

      cin >> h[i];

    }

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

    cout << fun(1); 

    











































    

    return 0;

    

}

// Faster C++ solution for the same problem (measured speedup: 1.793889645188273x):


#include<bits/stdc++.h>

using namespace std;



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

#define ll long long

#define ld long double

#define pb push_back

#define fe first

#define se second

#define nl "\n"

#define pp pair < ll , ll > 

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

#define st(x) sort(x.begin(),x.end())

#define rst(x) sort(x.rbegin(), x.rend())

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

long double pi = 3.14159265358979323;

 

const double EPS = 1e-12;

const int N = 1e5 + 5;

const int mod = 1e9 + 7;

 

ll dp[N] , h[N];

ll n;

ll fun(ll i){



  if(i == n - 1){

    return abs(h[i] - h[n]);

  }

  if(i >= n){

    return 0;

  }

  if(dp[i] != -1){

    return dp[i];

  }



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

  //return dp[n];

}

 

 

int main()

{

    fast;

    //ll n;

    cin >> n;

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

      cin >> h[i];

    }



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

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











































    

    return 0;

    

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

using namespace std;

typedef long long ll;

ll cost[100002], n;

ll dp[100002];

ll jump(ll pos)

{

    if(dp[pos]!=-1)

    return dp[pos];

    if(pos == n)

    return 0;

    if(pos > n)

    return INT_MAX;



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



}







int main(){

    cin >> n;

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

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

        cin >> cost[i];

    ll ans = jump(1);

    cout << ans << endl;

return 0;

}

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

using namespace std;

typedef long long ll;

typedef double dd;

const int INF = 1e9 + 5;

void solve()

{

		int n;

		cin >> n;

		vector <int> h(n, 0);

		

		for(int &x : h)

			cin >> x;

			

		vector <int> dp(n, INF);

		dp[0] = 0;

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

		{

			for(int j = i+1; j<i+3; j++)

			{

				if(j < n)

				{

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

				}

			}

		}

		

		cout << dp[n-1];

		

}



int main()

{

		ios::sync_with_stdio(false);

		cin.tie(nullptr);

		ll t = 1;

	//	cin >> t

		while(t--)

		{

			solve();

		}

	return 0;

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

using namespace std;

const int MAX = 1000099;

const int OO = 0x3f3f3f3f;



int n, h[MAX];

int dp[MAX];



int solve(int x)

{

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

	if(x > n) return OO;

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

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

}



int main()

{

	cin >> n;

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

		cin >> h[i];

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

	cout << solve(0) << '\n';



	return 0;

}

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

using namespace std;

const int MAX = 1000099;

const int OO = 0x3f3f3f3f;



int n, h[MAX];

int dp[MAX];



int main()

{

	cin >> n;

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

		cin >> h[i];

	dp[0] = 0;

	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] << '\n';



	return 0;

}
// Slower C++ solution:


#include <bits/stdc++.h>



#define pb push_back

#define fst first

#define snd second

#define INF 0x7fffffff

#define INFLL 0x7FFFFFFFFFFFFFFF

#define lenA(ar) sizeof(ar)/sizeof(*ar)

#define lenrows(mat) sizeof(mat)/sizeof(*mat)

#define lencols(mat) sizeof(*mat)/sizeof(**mat)

#define fill(a,c) memset(&a, c, sizeof(a))

#define fore(i,x,y) for(ll i=x;i<y;i++)

#define foreI(i,x,y) for(ll i=x-1;i>=y;i--)

#define max2(a,b) max(a, b)

#define max3(a,b,c) max2(max2(a,b),c)

#define min2(a,b) min(a, b)

#define min3(a,b,c) min2(min2(a,b),c)

#define MOD 1000000009

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

#define rall(x) (x).rbegin(), (x).rend()

#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)



typedef long long ll;

typedef unsigned long long ull;



using namespace std;

ll arr[200010];

ll dp[200010];

int n;

ll solve(int pos){

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

    if(dp[pos]>-1) return dp[pos];

    ll &r = dp[pos];



    ll a=solve(pos+1)+abs(arr[pos]-arr[pos+1]);

    ll b=INFLL;



    if(pos!=n-2){

        b =solve(pos+2)+abs(arr[pos]-arr[pos+2]);

    }

    return r=min(a,b);



}



int main() {

    



    cin>>n; arr[n];

    fill(dp,-1);

    fore(i,0,n)cin>>arr[i];

    cout<<solve(0)<<"\n";

    return 0;

}




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



#define pb push_back

#define fst first

#define snd second

#define fill(a,c) memset(&a, c, sizeof(a))

#define fore(i,x,y) for(ll i=x;i<y;i++)

#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)



typedef long long ll;

typedef unsigned long long ull;



using namespace std;

ll const mxn = 1e5+1;

ll n;

ll dp[mxn];

ll arr[mxn];



ll solve(int pos){

    if(pos==0)return 0;

    if(pos==1)return abs(arr[1]-arr[0]);

    if(dp[pos]>-1){

        return dp[pos];

    }

    ll dif = solve(pos-2)+(abs(arr[pos]-arr[pos-2]));

    ll dif1 = solve(pos-1)+(abs(arr[pos]-arr[pos-1]));

    dp[pos] = min(dif,dif1);

    return dp[pos];

}



int main() {FIN;



    cin>>n;arr[n];

    fore(i,0,n)cin>>arr[i];

    fill(dp,-1);

    cout<<solve(n-1)<<"\n";





    return 0;

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

#include <iostream>

#include <vector>

using namespace std;

typedef long long ll;

#define MAX_N 100100

vector<ll> dp(MAX_N);



int main() {

  //入力部

  int N;

  cin >> N;

  vector<int> h;

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

    int H;

    cin >> H;

    h.push_back(H);

  }



  // ここだけ調整

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

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

    dp[i + 2] =

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

  }

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

  return 0;

}

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

#include <iostream>

#include <vector>

using namespace std;



int main() {

  int N;

  cin >> N;

  vector<int> h(N + 1, 0);

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



  vector<int> dp(N + 1);

  dp[0] = 0;

  dp[1] = 0;

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

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

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

  }

  cout << dp[N] << endl;

}
// Slower C++ solution:
/**

 *   Author: praveen_ojha

 *   Created: 17 January 2019

 *   Time: 11:50:41

**/

#include <bits/stdc++.h>

using namespace std;

#define mod 1000000007

#define PI 3.141592653589793238510

typedef long long ll;

typedef long double ld;

typedef pair<int,int> pii;

typedef vector<int> vi;

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

int solve(int ind){

	if(ind==n-2){

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

	}

	if(ind==n-1){

		return 0;

	}

	if(dp[ind]!=-1)

		return dp[ind];

	int ans1,ans2;

	dp[ind+1]=solve(ind+1);

	dp[ind+2]=solve(ind+2);

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

	ans2=abs(a[ind]-a[ind+2])+dp[ind+2];

	dp[ind]=min(ans1,ans2);

	return dp[ind];



}

int main(){

    ios_base::sync_with_stdio(false); 

    cin.tie(NULL);

    memset(dp,-1,sizeof dp);

    cin>>n;

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

    	cin>>a[i];

    cout<<solve(0);

return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3889554919599663x):
/**

 *   Author: Praveen Ojha

 *   Created: 27 January 2019

 *   Time: 00:49:24

**/

#include <bits/stdc++.h>

using namespace std;

#define mod 1000000007

#define PI 3.141592653589793238510

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

#define rall(x) (x).rbegin(),(x).rend()

typedef long long ll;

typedef long double ld;

typedef pair<int,int> pii;

int dp[100005],a[100005];

int main(){

    ios_base::sync_with_stdio(false); 

    cin.tie(NULL);

    int n;

    cin>>n;

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

    	cin>>a[i];

    dp[n-1]=0;

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

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

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

    }

    cout<<dp[0]<<"\n";

return 0;

}