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



#define MAX 101010

#define EPS 1e-6

#define MOD 1000000007

#define inf 0x3f3f3f3f

#define llinf 0x3f3f3f3f3f3f3f3f



#define fi first

#define se second

#define pb push_back

#define ende '\n'



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

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

#define mset(x, y) memset(&x, (y), sizeof(x))



using namespace std; 



using ll = long long;

using ii = pair<int,int>;



int n;

ll dp[MAX][3];

ll v[MAX];



ll solve(int i, int last) {

  if (i == n - 1)

    return 0;



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

    return dp[i][last];



  ll op1 = llinf, op2 = llinf;

  if (i < n - 1)

    op1 = solve(i+1, 1) + abs(v[i+1] - v[i]);

  if (i < n - 2)

    op2 = solve(i+2, 2) + abs(v[i+2] - v[i]);



  return dp[i][last] = min(op1, op2);

}



int main() {

  ios::sync_with_stdio(0);

  cin.tie(0);



  cin >> n;

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

    cin >> v[i];



  mset(dp, -1);

  cout << solve(0, 0) << ende;

  return 0;

}


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



#define MAX 101010

#define EPS 1e-6

#define MOD 1000000007

#define inf 0x3f3f3f3f

#define llinf 0x3f3f3f3f3f3f3f3f



#define fi first

#define se second

#define pb push_back

#define ende '\n'



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

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

#define mset(x, y) memset(&x, (y), sizeof(x))



using namespace std; 



using ll = long long;

using ii = pair<int,int>;



ll dp[MAX];



int main() {

  ios::sync_with_stdio(0);

  cin.tie(0);



  int n; cin >> n;

  vector<ll> v(n);

  for (auto &i : v) cin >> i;



  mset(dp, inf);

  dp[0] = 0;

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

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

      if (j < n)

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



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

  return 0;

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

#include <ext/pb_ds/assoc_container.hpp>

#define F first

#define S second

#define PB push_back

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

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

using namespace __gnu_pbds;

using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef pair<int,int> pi;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;



const int OO = 1e9+7;

const int MOD = 1e9+7;

const int N = 1e5+7;



int mem[N];

int n;

int h[N];

int dp(int i)

{

    int &ret = mem[i];

    if (ret != -1) return ret;

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

    else if (i >= n) return OO;

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

    cerr << i << ' ' << ret << endl;

    return ret;

}



int main()

{

    //ios::sync_with_stdio(0);

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

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

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

    memset(mem,-1,sizeof mem);

    scanf("%d",&n);

    REP(i,0,n-1) scanf("%d",&h[i]);

    printf("%d\n",dp(0));



    return 0;

}


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

#include <ext/pb_ds/assoc_container.hpp>

#define F first

#define S second

#define PB push_back

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

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

using namespace __gnu_pbds;

using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef pair<int,int> pi;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;



const int OO = 1e9+7;

const int MOD = 1e9+7;

const int N = 1e5+7;



ll dp[N];

int n;

ll h[N];



int main()

{

    //ios::sync_with_stdio(0);

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

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

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



    scanf("%d",&n);

    REP(i,0,n-1) scanf("%lld",&h[i]);



    REP(i,0,n-1)

    {

        if (i >= 1) 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]));

    }

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



    return 0;

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

#include <cmath>

using namespace std;

 

int N, cost[100005], memo[500005];

 

int minCost(int v) {

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

  if (v <= 0) return 0;

  

  int a = minCost(v - 1) + abs(cost[v] - cost[v - 1]);

  int b;

  if (v == 1) {

    b = 1000000000;

  }

  else {

    b = minCost(v - 2) + abs(cost[v] - cost[v - 2]);

  }

  

  

  memo[v] = min(a, b);

  

  return (min(a, b));

}

 

int main() {

  cin >> N;

  for (int i = 0; i < N; i++) cin >> cost[i];

  

  for (int i = 0; i < 500005; i++) memo[i] = -1;

  

  cout << minCost(N - 1) << "\n";

  return 0;

}


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

using namespace std;

int main(){



  int n;

  cin>>n;

  int a[n];

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

    cin>>a[i];}

  

  long long int max[n];

  max[0]=0;

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

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

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

  }

  

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

  

  return 0;

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

#include <cmath>

using namespace std;

 

int N, cost[100005], memo[500005];

 

int minCost(int v) {

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

  if (v <= 0) return 0;

  

  int a = minCost(v - 1) + abs(cost[v] - cost[v - 1]);

  int b;

  if (v == 1) {

    b = 1000000000;

  }

  else {

    b = minCost(v - 2) + abs(cost[v] - cost[v - 2]);

  }

  

  

  memo[v] = min(a, b);

  

  return (min(a, b));

}

 

int main() {

  cin >> N;

  for (int i = 0; i < N; i++) cin >> cost[i];

  

  for (int i = 0; i < 500005; i++) memo[i] = -1;

  

  cout << minCost(N - 1) << "\n";

  return 0;

}


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

using namespace std;



int main(){

    int n;cin>>n;

    int a[n];

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



    int dp[n];

    dp[0]=0;

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



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

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

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

    }



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



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

#include <cmath>

using namespace std;

 

int N, cost[100005], memo[500005];

 

int minCost(int v) {

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

  if (v <= 0) return 0;

  

  int a = minCost(v - 1) + abs(cost[v] - cost[v - 1]);

  int b;

  if (v == 1) {

    b = 1000000000;

  }

  else {

    b = minCost(v - 2) + abs(cost[v] - cost[v - 2]);

  }

  

  

  memo[v] = min(a, b);

  

  return (min(a, b));

}

 

int main() {

  cin >> N;

  for (int i = 0; i < N; i++) cin >> cost[i];

  

  for (int i = 0; i < 500005; i++) memo[i] = -1;

  

  cout << minCost(N - 1) << "\n";

  return 0;

}


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

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

using namespace std;



int main() {

	// your code goes here

	int n;cin>>n;

	int a[n],dp[n];

	FOR(i,0,n)cin>>a[i];

	FOR(i,0,n)dp[i]=-1;

	dp[0]=0;

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

	FOR(i,2,n){

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

	}

//	FOR(i,0,n)cout<<dp[i]<<" ";

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

	return 0;

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

using namespace std;

const int N = 1e5 + 1;

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

int calc(int i){

    if(i == n - 1)

        return 0;

    if(i >= n)

        return 1e9 + 10;

    int &ret = dp[i];

    if(ret != -1)return ret;

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

}

int main(){

    scanf("%d", &n);

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

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

    }

    memset(dp , -1 , sizeof dp);

    cout<<calc(0);

    return 0;

}

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

using namespace std;

const int N = 1e5 + 1;

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

int main(){

    scanf("%d", &n);

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

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

    }

    dp[0] = 0;

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

    for(int i = 2 ; 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 - 1];

    return 0;

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

using namespace std;

const int N = 1e5 + 1;

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

int calc(int i){

    if(i == n - 1)

        return 0;

    if(i >= n)

        return 1e9 + 10;

    int &ret = dp[i];

    if(ret != -1)return ret;

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

}

int main(){

    scanf("%d", &n);

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

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

    }

    memset(dp , -1 , sizeof dp);

    cout<<calc(0);

    return 0;

}

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

using namespace std;

const int N = 1e5 + 1;

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

int main(){

    cin >> n;

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

		cin >> a[i];

    dp[0] = 0;

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

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

    	// dp[idx] is equal how i came to this (idx) from min(idx - 1 , idx - 2) + the cost !

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

    }

    cout<<dp[n - 1];

    return 0;

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

using namespace std;

const int N = 1e5 + 1;

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

int calc(int indx){

    if(indx == n - 1)

        return 0;

    if(indx >= n)

        return 1e9 + 10;

    if(dp[indx] != -1)

    	return dp[indx];

    // try to go to i + 1

	int val1 = calc(indx + 1) + abs(a[indx] - a[indx + 1]);

	// try to go to i + 2

	int val2 =  calc(indx + 2) + abs(a[indx] - a[indx + 2]);

    return dp[indx] = min( val1 , val2 ); 

}

int main(){

    cin >> n;

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

        cin >> a[i];

    }

    memset(dp , -1 , sizeof dp);

    cout<<calc(0);

    return 0;

}

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

using namespace std;

const int N = 1e5 + 1;

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

int main(){

    cin >> n;

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

		cin >> a[i];

    dp[0] = 0;

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

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

    	// dp[idx] is equal how i came to this (idx) from min(idx - 1 , idx - 2) + the cost !

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

    }

    cout<<dp[n - 1];

    return 0;

}
// Slower C++ solution:


    #include <bits/stdc++.h>

    using namespace std;

    #define INF 2000000000

    typedef long long int ll;

    typedef pair<ll,ll> ii;

    typedef pair<ii,ll> iii;

    typedef vector<ll> vi;

    typedef vector<ii> vii;

    #define getbit(n,i) (((n)&(1<<(i)))!=0)

    #define setbit0(n,i) ((n)&(~(1<<(i))))

    #define setbit1(n,i) ((n)|(1<<(i)))

    #define togglebit(n,i) ((n)^(1<<(i)))

    #define lastone(n) ((n)&(-(n)))

    #define read freopen("debug\\in.txt","r",stdin)

    #define write freopen("debug\\out.txt","w",stdout)

    #define fi first

    #define se second

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

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

    #define PI (acos(-1))

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

    #define mod (1000000007)

    #define asz 500005

    #define pb push_back

    #define ppf pop_front

    #define ppb pop_back

    #define pf push_front

    ll k=2,n;

    ll dp[200005];

    ll h[200005];

   // ll mini=1e9;

    ll recurse(ll pos){

      if(pos==n)

      return 0;

      ll i;

      if(dp[pos]!=-1)

      return dp[pos];

      ll mini=1e9;

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

        mini=min(mini,recurse(pos+i)+abs(h[pos]-h[pos+i]));

      }

      return dp[pos]=mini;

    }

    int main()

    {

        fastread;

        ll i,j,l,m,t,q,r,c;

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

        dp[i]=-1;

        cin>>n;

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

        cin>>h[i];

        cout<<recurse(1);

        return 0;

    }

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

using namespace std;

#define INF 2000000000

typedef long long int ll;

typedef pair<ll,ll> ii;

typedef pair<ii,ll> iii;

typedef vector<ll> vi;

typedef vector<ii> vii;

#define getbit(n,i) (((n)&(1<<(i)))!=0)

#define setbit0(n,i) ((n)&(~(1<<(i))))

#define setbit1(n,i) ((n)|(1<<(i)))

#define togglebit(n,i) ((n)^(1<<(i)))

#define lastone(n) ((n)&(-(n)))

#define read freopen("debug\\in.txt","r",stdin)

#define write freopen("debug\\out.txt","w",stdout)

#define fi first

#define se second

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

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

#define PI (acos(-1))

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

#define mod (1000000007)

#define asz 500005

#define pb push_back

#define ppf pop_front

#define ppb pop_back

#define pf push_front

ll a[500005];

ll dp[500006];

int main()

{

    ll n,i,j,k,l,m;

    scanf("%lld",&n);

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

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

	}

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

		if(i==2){

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

		}

		else{

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

		}

	}

	cout<<dp[n];

    return 0;

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

using namespace std;

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

#define trav(a, x) for(auto& a : x)

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

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

typedef long long ll;

typedef pair<int, int> pii;

typedef vector<int> vi;

#define MAXN 100009

int dp[MAXN], h[MAXN];



int solve(int i){

    if (dp[i] != -1)

        return  dp[i];

    if (i == 1)

        return dp[i] = 0;

    if (i == 2)

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

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

}



int main() {

    cin.sync_with_stdio(0); cin.tie(0);

    cin.exceptions(cin.failbit);

    int n;

    cin >> n;

    memset(dp, -1, sizeof dp);

    

    rep(i, 1, n + 1)

        cin >> h[i];

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

    return 0;   

}


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

using namespace std;

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

#define trav(a, x) for(auto& a : x)

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

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

typedef long long ll;

typedef pair<int, int> pii;

typedef vector<int> vi;

#define MAXN 100009

int dp[MAXN], h[MAXN];



int solve(int i){

    if (dp[i] != -1)

        return  dp[i];

    if (i == 1)

        return dp[i] = 0;

    if (i == 2)

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

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

}



int main() {

    cin.sync_with_stdio(0); cin.tie(0);

    cin.exceptions(cin.failbit);

    int n;

    cin >> n;

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

    

    

    rep(i, 1, n + 1)

        cin >> h[i];

    dp[1] = 0;

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

    rep(i, 3, n + 1){

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

    }

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

    return 0;   

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

using namespace std;

typedef long long ll;

#define endl '\n'

int n,a[100005];

int dp[100005];

int fun(int pos)

{

    if (pos==n-1)

    {

        return 0;

    }

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

    int ret1=1e7;

    int ret2=1e7;



    ret1=abs(a[pos]-a[pos+1])+fun(pos+1);

    if (pos+2<=n-1)

    ret2=abs(a[pos]-a[pos+2])+fun(pos+2);



    return dp[pos]=min(ret1,ret2);



}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

//    cout<<fixed;

//    cout<<setprecision(10);



    cin>>n;

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

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

    int ans=fun(0);

    cout<<ans<<endl;



    return 0;

}


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

using namespace std;

typedef long long ll;

#define endl '\n'

int n,a[100005];

int dp[100005];

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

//    cout<<fixed;

//    cout<<setprecision(10);



    cin>>n;

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

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

    dp[0]=0;

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

    {

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

        if (i>1)

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

    }

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



    return 0;

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long

#define boost() ios_base :: sync_with_stdio(0); cin.tie(); cout.tie(); cout << fixed; cout << setprecision(15); srand(time(NULL))

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

using namespace __gnu_pbds;

using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;



int n, h[100010];

int dp[100010][5];



int sol (int idx, int jump) {

  if (idx >= n) return INT_MAX;

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

  int &ret = dp[idx][jump];

  if (ret != -1) return ret;

  ret = INT_MAX;

  ret = min (ret, sol (idx + 1, 1) + abs (h[idx] - h[idx + 1]));

  ret = min (ret, sol (idx + 2, 2) + abs (h[idx] - h[idx + 2]));

  return ret;

}



signed main () {

  cin >> n; memset (dp, -1, sizeof dp);

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

  cout << sol (0, 0) << endl;

  return 0;

}


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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long

#define boost() ios_base :: sync_with_stdio(0); cin.tie(); cout.tie(); cout << fixed; cout << setprecision(15); srand(time(NULL))

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

using namespace __gnu_pbds;

using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;



int n, h[100010];

int dp[100010][5];



signed main () {

  cin >> n;

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

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

  dp[1][2] = INT_MAX;

  dp[1][3] = dp[1][1];

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

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

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

    dp[i][3] = min (dp[i][1], dp[i][2]);

  }

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

  return 0;

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

#include <ctime>

#include <unordered_map>

#include <stdlib.h>

using namespace std;

#define ll  long long int

#define mod 1000000007

#define modd 998244353

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

// #include<boost/multiprecision/cpp_int.hpp>

// using boost ::multiprecision::cpp_int;

/*__builtin_clz();

__builtin_ctz();

__builtin_popcount();*/

ll n;

ll a[100002] ={0};

ll dp[100002];

ll fun(ll idx)

{

    if(idx >=n)

    return 0;

    if(idx==n-1)

    {

        dp[idx] =0;

        return 0;

    }

    if(dp[idx] != -1)

    {

        return dp[idx];

    }

    ll k1 =fun(idx +1);

    ll k2 = fun(idx+2);

    ll x1 =  abs(a[idx] - a[idx+1])+k1;

    ll x2= abs(a[idx] - a[idx+2])+k2;

    ll k;

    if(idx+2 < n)

    {

        k =min(x1,x2);

    }

    else 

    {

        k=x1;

    }

    // cout<<idx<<" "<<x1<<" "<<x2<<"\n";

    return dp[idx] = k;

    



}

int main()

{

    boost;

    cin>>n;

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

    cin>>a[i];

    memset(dp,-1,sizeof dp);

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



    cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";

}

/* AnsHuman_7 || Anshuman Gaur */

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

#include <ctime>

#include <unordered_map>

#include <stdlib.h>

using namespace std;

#define ll  long long int

#define mod 1000000007

#define modd 998244353

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

// #include<boost/multiprecision/cpp_int.hpp>

// using boost ::multiprecision::cpp_int;

/*__builtin_clz();

__builtin_ctz();

__builtin_popcount();*/

int main()

{

    boost;

    ll n;

    cin>>n;

    ll a[n];

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

    cin>>a[i];

    ll ans[n]={0};

    ans[0]= 0;

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

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

    {

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

    }

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

    cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";

}

/* AnsHuman_7 || Anshuman Gaur */
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll a[100005],dp[100005];

ll n;

ll ans=0;

ll recur(ll i)

{

	if(dp[i]!=-1)

	{	

		return dp[i];

	}	

	if(i==n-1)

	{

		return 0;

	}

	ll q,w=LONG_LONG_MAX;

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

	if(i+2<n)

	w=abs(a[i]-a[i+2])+recur(i+2);

	dp[i]=min(q,w);

	return(min(q,w));

}

int main()

{

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

dp[i]=-1;

cin>>n;	

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

cin>>a[i];

cout<<recur(0);

return 0;

}

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

using namespace std;

typedef long long ll;

#define endl '\n'

#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

#define pb push_back

#define mp make_pair

int main()

{

	ll n;

	fastio;	

	cin>>n;

	ll a[n];

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

	{

		cin>>a[i];

	}

	ll dp[n]={0};

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

	{

		ll f=0,s=LONG_LONG_MAX;

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

		if(i+2<n)

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

		dp[i]=min(s,f);

	}

	cout<<dp[0];

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

using namespace std;

int dp[100001];

int minCost(vector<int>&v,int n){

    if(n==0) return 0;

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

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

    int oneJump=abs(v[n]-v[n-1])+minCost(v,n-1);

    int twoJump=abs(v[n]-v[n-2])+minCost(v,n-2);

    return dp[n]=min(oneJump,twoJump);

}

int main()

{  ios::sync_with_stdio(false);

   cin.tie(0);  

   

   int n;

   cin>>n;

   vector<int>v(n);

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

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

   cout<<minCost(v,n-1);

     return 0;

}


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

using namespace std;

int main()

{  ios::sync_with_stdio(false);

   cin.tie(0);  

   int n;

   cin>>n;

   vector<int>v(n);

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

     int d1=0,d2=abs(v[1]-v[0]),ans=0;

     if(n==1) {cout<<d1; return 0;}

     if(n==2) {cout<<d2; return 0;}

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

         ans=min(abs(v[i]-v[i-1])+d2,abs(v[i]-v[i-2])+d1);

         d1=d2;

         d2=ans;

     }

     cout<<ans;

     return 0;

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

using namespace std;



int dp[101010];



int main() {

	int n;

	cin >> n;

	vector< int > h(n);

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



	fill_n(dp, 101010, 1e9+1);

	dp[0] = 0;

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

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

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

	}



	int ans = dp[n-1];

	cout << ans << endl;

	

  return 0;

}


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

using namespace std;







int main() {

	int n; cin >> n;

	vector< int > h(n);

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



	vector< int > dp(n+1, 1e9+1);



	dp[0] = 0;

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

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

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

	}

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

	

  return 0;

}