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



using namespace std;

int n;

int h[100005];

int dp[100005];



int main() {

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

    //freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    memset(dp,-1,sizeof dp);

    cin>>n;

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

        cin>>h[i];

    }

    reverse(h,h+n);

    dp[0]=0;

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

        if(i-2>=0){

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

        }

        else{

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

        }

    }

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

    return 0;

}

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



using namespace std;

#define ll long long



const int INF = 1e9+5;



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int n;

    cin>>n;

    int ar[n];

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

        cin>>ar[i];

    }

    vector<int> dp(n,INF);

    dp[0]=0;

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

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

            if(j<n){

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

            }

        }

    }

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



    return 0;

}

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



using namespace std;

#define ll long long

const int N=100005;

int n;

int ar[N];

int mem[N];



int solve(int ind){

    if(ind==n-1){

        return 0;

    }

    if(ind>=n){

        return 1e9;

    }

    if(mem[ind]!=-1){

        return mem[ind];

    }

    int ch1=solve(ind+1)+abs(ar[ind]-ar[ind+1]);

    int ch2=solve(ind+2)+abs(ar[ind]-ar[ind+2]);

    return mem[ind]=min(ch1,ch2);

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    memset(mem,-1,sizeof mem);

    cin>>n;

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

        cin>>ar[i];

    }

    cout<<solve(0)<<endl;

    return 0;

}

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



using namespace std;

#define ll long long



const int INF = 1e9+5;



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int n;

    cin>>n;

    int ar[n];

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

        cin>>ar[i];

    }

    vector<int> dp(n,INF);

    dp[0]=0;

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

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

            if(j<n){

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

            }

        }

    }

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



    return 0;

}

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

using namespace std;

#define ll long long

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

#define dcm(a) setprecision(a)<<fixed

#define MOD 1000000007

#define clr(memo, a) memset(memo,a,sizeof(memo))

int const N=1e5+5;

int a[N];

int n;

int memo[N];

int dp(int i){

    if(i>n)

        return +N;

    if(i==n-1)

        return 0;

    int &ret=memo[i];

    if(ret!=-1)

        return ret;

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

}

int main()

{cin>>n;

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

    cin>>a[i];

clr(memo,-1);

cout<<dp(0)<<endl;





}


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

#include <bitset>

using namespace std;

#define ll long long

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

#define dcm(a) setprecision(a)<<fixed

#define MOD 1000000007

#define clr(memo, a) memset(memo,a,sizeof(memo))

#define PI acos(-1)



int const N=1e5+5;

int const inf=1e9+5;

void solve(){

int n;

cin>>n;

vector<int> dp(n,inf);

vector<int> v(n);

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

    cin>>v[i];

dp[0]=0;

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

for(int 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]<<endl;

}

int main(){

    fast;



solve();



return 0;}


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

}

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

using namespace std;

const int INF=1e9+5;

int main()

{

    int n;

    scanf("%d", &n);

    vector<int> h(n);

    vector<int> dp(n, INF);

    for(int& x : h)

        scanf("%d", &x);

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

    //while(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;

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;

}

// Optimized solution to the same problem (faster):
/*

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

}

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

}

// Optimized solution to the same problem (faster):
/*

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

}

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

}

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

}

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

	

}

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

}

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

}

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

}

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

}


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

}


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

  }

}

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

  }

}

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

}


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

*/


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


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

    

}

// Optimized solution to the same problem (faster):


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

    

}

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

}

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

}


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

}

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

}

// Fastest known solution for this problem: