stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i, n) for (int i=0; i<(int)(n); i++)

using namespace std;

using ll = long long;

using Graph = vector<vector<int>>;



template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}

template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}



int main() {

  int n; cin >>n;

  vector<ll> h(n);

  rep (i,n) cin >>h.at(i);

  const ll INF = 1LL << 60;

  vector<ll> dp(100010);

  rep (i,100010) dp.at(i) = INF;

  dp.at(0) = 0;

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

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

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

  }



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



}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i, n) for (int i=0; i<(int)(n); i++)

using namespace std;

using ll = long long;

using Graph = vector<vector<int>>;

template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}

template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}



void chmin(int &a, int &b){if (a>b){a = b; return;}return;}

void chmax(int &a, int &b){if (a<b){a = b; return;}return;}





const ll MOD = 1000000007;

const ll INF = 9999999999;



int main() {

  int n; cin >>n;

  vector<int> h(n);

  for (int i=0; i<n; i++) cin >>h.at(i);

  vector<int> dp(n+2, 1500000000);

  dp.at(0) = 0;

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

    chmin(dp.at(i+1), dp.at(i) + abs(h.at(i) - h.at(i+1)));

    if (i==n-2) break;

    chmin(dp.at(i+2), dp.at(i) + abs(h.at(i) - h.at(i+2)));

  }

  cout <<dp.at(n-1) <<endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

const int mxn=1e5;

int  dp[mxn+2];

int h[mxn+2];

int func(int n)

{

    int k;

    if(n==1)return dp[1]=0;

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

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

if(n>2){

k=func(n-2)+abs(h[n]-h[n-2]);

dp[n]=min(k,dp[n]);}

return dp[n];





}





int main()

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

    int n;

    cin>>n;



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

    cout<<func(n)<<endl;





}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

const int inf=1e9;

int main()

{

    int n;

    scanf("%d",&n);

    vector<int> h(n);

    for(int& i:h)

       {



        scanf("%d",&i);}

        vector<int> dp(n,inf);

        dp[0]=0;

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





}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int n,arr[100005],mem[100005];



int dp(int pos){

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

    if(pos>=n)return 100000;

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

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

}



int main(){

    ios_base::sync_with_stdio(0);

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

    cin>>n;

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

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

    cout<<dp(0);

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;



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



int main(){

    ios_base::sync_with_stdio(0);

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

    cin>>n;

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

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

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

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):


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

    }

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;   

}


// Optimized solution to the same problem (faster):
#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;   

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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 */

// Optimized solution to the same problem (faster):
#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 */

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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];

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem: