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

using namespace std;

const int N = 1e5+1;



vector<int> v(N, 0);

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



int cost(int pos, int n){

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

    else if (pos == n) return 0;

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

    else {

        memo[pos] = min(abs(v[pos] - v[pos + 1]) + cost(pos+1, n), abs(v[pos]-v[pos + 2]) + cost(pos+2, n));

        return memo[pos];

    }

}



int main(){

    int n; cin >> n;

    

    for (int i = 1; i!=n+1; i++) cin >> v[i];

    cout << cost(1, n) << endl;



    return 0;

}

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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define scl(n) scanf("%lld",&n)

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

    for(i=n-1;i>=1;i--)

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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

** author:mahmoud magdy

*/

#include <bits/stdc++.h>

using namespace std;



#define ll long long

#define endl "\n"



inline int D()

{

    int m ;

    cin>>m;

    return m ;

}

inline ll lD()

{

    ll m ;

    cin>>m;

    return m ;

}

inline double dD()

{

    double m;

    cin>>m;

    return m;

}

void fast()

{

    ios_base :: sync_with_stdio( 0 ) ;

    cin.tie( 0 ) ;

    cout.tie( 0 ) ;

}

int a[100005];

int dp[100005];

int n;

int solve(int i){

 if(i>=n)return 1e9;

 if(i==n-1)

    return 0;

 if(dp[i]!=-1)

      return dp[i];

 int ch1=abs(a[i]-a[i+1])+solve(i+1);

 int ch2=abs(a[i]-a[i+2])+solve(i+2);

 return dp[i]=min(ch1,ch2);

}

int main()

{

    fast();

    n=D();

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

        a[i]=D();

    }

    memset(dp,-1,sizeof dp);

    cout<<solve(0)<<endl;

}


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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define scl(n) scanf("%lld",&n)

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

    for(i=n-1;i>=1;i--)

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f

#define INF 0x3f3f3f3f

#define pb push_back

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

#define ms(a, x) memset(a, x, sizeof(a))

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

#define for1(i, n) for(int i = 1; i <= n; ++i)

using namespace std;

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<long long, int> pli;

typedef pair<long long, long long> pll;

const int mod = 1e9 + 7;

const int N = 1e5+10;

const int M = 1e6+10;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}

inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}

//==================================================================================================================================================================//



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



int main() {

   scanf("%d", &n);

   ms(dp, inf); dp[n] = 0;

   for1(i, n) scanf("%d", h+i);

   for(int i = n; i; --i) {

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

      else {

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

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

      }

   }

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

   return 0;

}

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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define scl(n) scanf("%lld",&n)

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

    for(i=n-1;i>=1;i--)

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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

using namespace std;



#define clr(arr,val) memset(arr,val ,sizeof arr)

//#define first f

//#define second s



typedef  long long ull;

typedef long long ll;

int const oo=(int)1e9 ;



int const SZ= (int)1e5+1;

//const ll mod=(ll)1e9+7;

int arr[SZ];

int dp[SZ];

int n;

//int mn=oo;

int solve(int i){

    

    if(i==n-1)

        return 0;

    if(i>=n)

        return oo;

    

    int &ret=dp[i];

    

    if(ret!=-1)

        return ret;

        

    int ch1=abs(arr[i]-arr[i+1])+solve(i+1);

    int ch2=abs(arr[i]-arr[i+2])+solve(i+2);

    ret=min(ch1,ch2);

    return ret;

    

}

int main() {

//    int t ;

//    cin>>t;

//    while(t--){

        cin>>n;

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

            cin>>arr[i];

        clr(dp,-1);

        cout<<solve(0)<<endl;

//    }

    return 0;

}

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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define scl(n) scanf("%lld",&n)

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

    for(i=n-1;i>=1;i--)

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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

using namespace std;

#define N (int)2e5

int n,memo[N],c[N];



int dp(int curr) {

    if (curr == n) return 0;

    if (curr > n) return 1e9;

    int &sol = memo[curr];

    if (sol != -1) return sol;

    sol = min(

        dp(curr + 1) + abs(c[curr] - c[curr + 1]) ,

        dp(curr + 2) + abs(c[curr] - c[curr + 2])

    );

    return sol;

}



int main() {

    scanf("%d" , &n);

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

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

    memset (memo , -1 , sizeof memo);

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

}


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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define scl(n) scanf("%lld",&n)

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

    for(i=n-1;i>=1;i--)

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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

using namespace std;



typedef long long LL; 

typedef pair<int, int> pii; 

typedef pair<LL, LL> pll; 

typedef pair<string, string> pss; 

typedef vector<int> vi; 

typedef vector<vi> vvi; 

typedef vector<pii> vii; 

typedef vector<LL> vl; 

typedef vector<vl> vvl;

typedef queue<int> qi;

typedef queue<char> qc;

typedef stack<int> si;

typedef stack<char> sc;

#define F first

#define S second

#define PB push_back



int costs[1000001];

int dp[1000001];





int frog(int i, int n){



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

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

    int cost = abs(costs[i] - costs[i + 1]) + frog(i+1, n);

    if(i + 2 <= n){

        cost = min(cost, abs(costs[i] - costs[i+2]) + frog(i + 2, n));

    }



    return dp[i] = cost;

}



int main(){

    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);



    int n;

    cin >> n;

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

        cin >> costs[i];

    } //cost for a jump = abs(h.i - h.j)

      //find minimum cost



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

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



    return 0;

}

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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define scl(n) scanf("%lld",&n)

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

    for(i=n-1;i>=1;i--)

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




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

#define ll long long 

#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');

#define setbit(x,k) (x |= (1 << k))

#define clearbit(x,k) (x &= ~(1ll << k))

#define checkbit(x,k) (x & (1ll << k))

#define mp make_pair

#define scl(x) scanf("%lld",&x)

#define sci(x) scanf("%d",&x)

#define pb push_back

#define pf push_front

#define ppb pop_back

#define ppf pop_front

#define pii pair<int,int> 

#define YES printf("YES\n")

#define Yes printf("Yes\n")

#define yes printf("yes\n")

#define NO printf("NO\n")

#define No printf("No\n")

#define no printf("no\n")

#define nn printf("\n") 

#define mod 10000007

using namespace std;    



ll n;

ll h[100005];

ll dp[100005];

ll solve(int pos)

{

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

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

    ll res = LONG_LONG_MAX;

    if(pos+1<n) res = min(res, abs(h[pos]-h[pos+1]) + solve(pos+1));

    if(pos+2<n) res = min(res, abs(h[pos]-h[pos+2]) + solve(pos+2));

    return dp[pos] = res;

    

}



int main() 

{

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

   cin>>n;

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

   cout<<solve(0); nn;

}

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



#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define scl(n) scanf("%lld",&n)

#define scll(n,m) scanf("%lld%lld",&n,&m)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define mod 1000000007

#define read freopen("input.txt","r",stdin)

#define write freopen("output.txt","w",stdout)



ll dp[100005],ar[100005];



int main()

{

	ll n,i;

    scl(n);

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

    scl(ar[i]);

    

    dp[n]=0;

    for(i=n-1;i>=1;i--)

    {

    	if(i==n-1)

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

    	else

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

	}

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

}




// 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>



using namespace std;

using namespace __gnu_pbds;



template <typename T>

using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



typedef long long ll;

typedef pair<ll, ll> pll;

typedef pair<int, int> pii;

typedef complex<double> point;



#define X real()

#define Y imag()

#define angle(a) (atan2((a).imag(), (a).real()))

#define vec(a, b) ((b) - (a))

#define same(p1, p2) (dp(vec(p1, p2), vec(p1, p2)) < EPS)

#define dp(a, b) ((conj(a) * (b)).real())

#define cp(a, b) ((conj(a) * (b)).imag())

#define length(a) (hypot((a).imag(), (a).real()))

#define normalize(a) (a) / length(a)

#define rotateO(p, ang) ((p)*exp(point(0, ang)))

#define rotateA(p, ang, about) (rotateO(vec(about, p), ang) + about)

#define reflectO(v, m) (conj((v) / (m)) * (m))

#define clr(a, b) memset(a, b, sizeof(a));



const ll N = 100005;

const int MOD = 1e9 + 7;

const double EPS = 1e-7;

const double PI = acos(-1.0);



ll n, h[N];

ll memo[N];



ll solve(int i)

{

	if(i == n - 1)

		return 0;



	ll& ret = memo[i];

	if(~ret)

		return ret;



	ret = solve(i + 1) + llabs(h[i] - h[i + 1]);



	if(i < n - 2)

		ret = min(ret, solve(i + 2) + llabs(h[i] - h[i + 2]));



	return ret;

}



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(NULL), cout.tie(NULL);

    cin >> n;

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

    	cin >> h[i];

    clr(memo, -1);

    cout << solve(0) << endl;

}

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



using namespace std;



typedef long long ll;

typedef pair<ll, ll> pll;

typedef pair<int, int> pii;



const ll N = 100005;

const ll INF = 1e9;

const int MOD = 1e9 + 7;

const double EPS = 1e-7;

const double PI = acos(-1.0);



ll n, h[N], dp[N];



int main() {

	ios::sync_with_stdio(false);

	cin.tie(NULL), cout.tie(NULL);

	cin >> n;

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

		cin >> h[i];



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

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

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

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

}






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

using namespace std;



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



int solve(int x)

{

  if (x == n - 1)

    return 0;

  if (dp[x] != -1)

    return dp[x];

  int c = solve(x + 1) + abs(a[x] - a[x + 1]); 

  if (x < n - 2)

    c = min(c, solve(x + 2) + abs(a[x] - a[x + 2]));

  return dp[x] = c;

}



int main()

{

  memset(dp, -1, sizeof dp);

  cin >> n;

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

    cin >> a[i];

  cout << solve(0);

  return 0;

}

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

using namespace std;



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

#define wtf(s) freopen((s), "w", stdout)

#define rff(s) freopen((s), "r", stdin)

#define pi (2 * acos(0))

typedef long double ld;

typedef long long ll;

typedef complex<ld> point;

#define endl '\n'

#define matrix vector<vector<ll>>

#define EPS 1e-9

#define X real()

#define Y imag()

#define vec(a, b) ((b) - (a))

#define dot(a, b) ((conj(a) * (b)).real())

#define cross(a, b) ((conj(a) *(b)).imag())

#define lengthsqr(v) (dot(v, v))

#define length(v) ((ld)hypot((v).Y, (v).X))

#define same(a, b) (lengthsqr(vec(a, b)) < EPS)



const int N = 1e5 + 5, inf = 1e9 + 5;

const ll mod = 1e9 + 7;



int dp[N], a[N];



int main()

{

    VIC

    int n;

    cin >> n;

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

        cin >> a[i];

    a[0] = a[1];

    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;

}


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

using namespace std;



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



int main()

{

    memset(dp, -1, sizeof dp);

    cin >> n;

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

        cin >> a[i];

    dp[n - 1] = 0;

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

      for (int i = n - 3; i > -1; i--)

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

      cout << dp[0];

      return 0;

}

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

using namespace std;



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

#define wtf(s) freopen((s), "w", stdout)

#define rff(s) freopen((s), "r", stdin)

#define pi (2 * acos(0))

typedef long double ld;

typedef long long ll;

typedef complex<ld> point;

#define endl '\n'

#define matrix vector<vector<ll>>

#define EPS 1e-9

#define X real()

#define Y imag()

#define vec(a, b) ((b) - (a))

#define dot(a, b) ((conj(a) * (b)).real())

#define cross(a, b) ((conj(a) *(b)).imag())

#define lengthsqr(v) (dot(v, v))

#define length(v) ((ld)hypot((v).Y, (v).X))

#define same(a, b) (lengthsqr(vec(a, b)) < EPS)



const int N = 1e5 + 5, inf = 1e9 + 5;

const ll mod = 1e9 + 7;



int dp[N], a[N];



int main()

{

    VIC

    int n;

    cin >> n;

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

        cin >> a[i];

    a[0] = a[1];

    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;

}


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

using namespace std;

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#pragma GCC optimize ("-ffloat-store")  

#pragma GCC optimize ("-fno-defer-pop")

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

#define ll long long int

#define ld long double

ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}

ll modInverse(ll a, ll m) { return power(a, m-2, m); }

#define ps push_back

#define fs first

#define sc second

#define N 300005

#define endl "\n"

#define mod 1000000007

ll n,ar[N],dp[N];

ll minval(ll i){

	if(i==n){

		return 0;

	}

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

		return dp[i];

	}



	if(i+2<=n){

		ll a,b;

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

		b=minval(i+2)+abs(ar[i+2]-ar[i]);

		return dp[i]=min(a,b);

	}

	else {

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

	}

}

int main(){



	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	

	ll i,j,k,l;

	cin>>n;

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

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

		cin>>ar[i];

	}

	

	k=minval(1);

	cout<<k;

	return 0;

}


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

using namespace std;

#pragma GCC optimize("Ofast")

#pragma GCC optimize("unroll-loops")

#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision

#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns

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

#define ll long long int

#define ld long double

ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}

ll modInverse(ll a, ll m) { return power(a, m-2, m); }

#define ps push_back

#define fs first

#define sc second

#define takeline cin.ignore();

#define iactive cout.flush();

#define N 3000005

#define endl "\n"

#define mod 1000000007

//((1.0l)*BIG MULTIPLY MAGIC?)

// string to integer stoi()

// string to long long stoll()

// string.substr(position,length);

// integer to string to_string();

//-----------------------------------------------

ll n,ar[100005],dp[100005];

ll findmin(ll i){

	if(i==n){

		return 0;

	}

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

		return dp[i];

	}



	ll a=1e18,b=1e18;

	if(i+1<=n)

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

	if(i+2<=n)

		b=findmin(i+2)+abs(ar[i]-ar[i+2]);

	return dp[i]=min(a,b);

}

int main(){



	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);



	ll i,j,k,l;

	cin>>n;

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

		cin>>ar[i];

	}

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

	ll an=findmin(1);

	cout<<an;

	return 0;

}

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

using namespace std;



const int MAXN = 1e5+5;

const int INF = 1e9+7;

int a[MAXN],dp[MAXN];

// The minimum we can get from i to 0 house

int main()

{

    for(int i=0;i<MAXN;++i) dp[i] = INF;



    int n;cin >> n;

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

        cin >> a[i];

    }



    dp[0] = 0;

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

        // We can jump in dp[i-1] or dp[i-2]

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

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

        }

    }

    cout << dp[n-1];

}


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

using namespace std;



const int MAXN = 3e5+5;

const int INF = 1e9+7;

#define ll long long

#define pb push_back

#define endl '\n'

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

#define F first

#define S second



ll poww(ll a, ll b, ll md) {

    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));

}



ll MOD(ll a){

    return ((a%INF)+INF)%INF;

}



ll inv(ll a){

    return poww(a,INF-2,INF);

}



int h[MAXN],dp[MAXN];



int main()

{

    fast_io;

    //cout << fixed << setprecision(15);



    int n;cin >> n;

    int k = 2;

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

    dp[n] = 0;

    for(int i=n-1;i>=1;--i){

        dp[i] = INF;

        for(int j =i+1;j<=min(n,i+k);++j){

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

        }

    }

    cout << dp[1];

}


// 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 <iostream>

#include <vector>

using namespace std;



const int MX = 100005;



int main() {

    int n; cin >> n;

    vector<int> a(MX), dp(MX, 0);

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

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

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

    for (int i = 3; 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] << "\n";

    return 0;

}


// Fastest known solution for this problem: