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

#define ll long long

#define pb push_back

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

#define mp make_pair

#define ff first

#define ss second

#define MAXN  1000005

#define endl "\n"

using namespace std;

vector<ll>v;

ll dp[100003];

ll a,n;

ll rec(int i){

    if(i==n-1)

        return 0;

    if(dp[i]!=-1)

        return dp[i];

    if(i<n-2){

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

    }

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

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cin>>n;

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

        cin>>a;

        v.pb(a);

    }

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

    ll ans=rec(0);

    cout<<ans<<endl;







    return 0;

}




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

#define ll long long

#define pb push_back

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

#define mp make_pair

#define ff first

#define ss second

#define MAXN  1000005

#define endl "\n"

using namespace std;



int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

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

    cin>>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(abs(v[i] - v[i-1]) + dp[i-1], abs(v[i] - v[i-2]) + dp[i-2]);

    }

    cout<<dp[n-1];



    return 0;

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



using namespace std;

    int N;

     vector<int>dp(2e5 , -1);   

     vector<int>H(2e5);

      int so(int index){

            if(index == N) return 0;

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

          if(index == N-1) return so(index+1) + abs(H[index] - H[index+1]);

        int result = 1e9;

        result = min(so(index+1) + abs(H[index] - H[index+1]),so(index+2) + abs(H[index] - H[index+2]));

        dp[index] = result ;

        return result;

      }





    void solve(){

        cin>>N;

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

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

    }



int main(){

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

    int tc = 1;

    //cin>>tc;

    while (tc--)

    {

        solve();

    }

    

    return 0;

}

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



using namespace std;

  

     

    





    void solve(){

          int N;

           cin>>N;

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

     vector<int>H(N+1);

       

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

        dp[1] = 0;

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

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

    }



int main(){

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

    int tc = 1;

    //cin>>tc;

    while (tc--)

    {

        solve();

    }

    

    return 0;

}
// Slower C++ solution:


    #include <bits/stdc++.h>

    using namespace std;

    const int inf=1e5+9;

    long long  dp[inf],a[inf],n;



    int solve(int pos){

        if(pos==n)

            return 0;

        if(pos>n)

            return 1e9+9;

        long long  &ret=dp[pos];

        if(ret!=-1)

            return ret;

        ret=min(abs(a[pos]-a[pos+1])+solve(pos+1),abs(a[pos]-a[pos+2])+solve(pos+2)  );

        return ret;

    }



    int main(){



        cin>>n;

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

            cin>>a[i];

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

        cout<<solve(1)<<endl;

    }


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


#include <bits/stdc++.h>

using namespace std;

const int inf=1e5+9;

long long  dp[inf],a[inf];

 

int main(){

 

    int n;

    cin>>n;

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

        cin>>a[i];

    

    dp[1]=0;

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

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

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

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

        dp[i]=min(x,y);

    }

    cout<<dp[n]<<endl;

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

using namespace std;

#define endl '\n'

#define pb push_back

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

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

#define reps(i, m, n) for (int i = m; i <= n; ++i)

typedef long long ll;

typedef vector<int> vi;

typedef vector<ll> vl;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int INF = 0x3f3f3f3f;

const ll LINF = 0x3f3f3f3f3f3f3f3fLL;



int n;

int h[100010];

int memo[100010];



int dp(int i) {



  if( i < 1 ) return INF;

  if( i == 1 ) return 0;

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



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

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



  memo[i] = min(a1, a2);



  return memo[i];

}



signed main()

{

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



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



  cin >> n;



  reps(i, 1, n) cin >> h[i];



  cout << dp(n) << endl;



  return 0;

}


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



using namespace std;



#ifndef DEBUG

#define dump(...)

#endif



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);



    size_t N;

    cin >> N;



    vector<int64_t> h(N);

    for (auto &hi: h) {

        cin >> hi;

    }



    vector<int64_t> dp(N);

    for (size_t i = 1; i < N; ++i) {

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

        else {

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

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

            dp[i] = min(value1, value2);

        }

    }



    cout << dp[N - 1] << "\n";



    return 0;

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

using namespace std;

#define endl '\n'

#define pb push_back

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

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

#define reps(i, m, n) for (int i = m; i <= n; ++i)

typedef long long ll;

typedef vector<int> vi;

typedef vector<ll> vl;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int INF = 0x3f3f3f3f;

const ll LINF = 0x3f3f3f3f3f3f3f3fLL;



int n;

int h[100010];

int memo[100010];



int dp(int i) {



  if( i < 1 ) return INF;

  if( i == 1 ) return 0;

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



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

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



  memo[i] = min(a1, a2);



  return memo[i];

}



signed main()

{

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



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



  cin >> n;



  reps(i, 1, n) cin >> h[i];



  cout << dp(n) << endl;



  return 0;

}


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

#pragma GCC optimize("Ofast")



// Begin {{{

using namespace std;



#ifndef DEBUG

#define dump(...)

#endif



template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }



template <class T>

inline vector<T> make_v(const T &initvalue, size_t sz) {

    return vector<T>(sz, initvalue);

}



template <class T, class... Args>

inline auto make_v(const T &initvalue, size_t sz, Args... args) {

    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));

}



constexpr size_t    operator""_sz(unsigned long long value) { return value; };

constexpr intmax_t  operator""_im(unsigned long long value) { return value; };

constexpr uintmax_t operator""_um(unsigned long long value) { return value; };

// }}} End



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);



    size_t N;

    cin >> N;



    vector<int64_t> h(N);

    for (auto &hi: h) cin >> hi;



    vector<int64_t> dp(N);

    for (size_t i = 1; i < N; ++i) {

        if (i == 1) {

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

        } else {

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

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

            dp[i] = min(value1, value2);

        }

    }



    cout << dp[N - 1] << "\n";



    return 0;

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

using namespace std;

#define endl '\n'

#define pb push_back

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

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

#define reps(i, m, n) for (int i = m; i <= n; ++i)

typedef long long ll;

typedef vector<int> vi;

typedef vector<ll> vl;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int INF = 0x3f3f3f3f;

const ll LINF = 0x3f3f3f3f3f3f3f3fLL;



int n;

int h[100010];

int memo[100010];



int dp(int i) {



  if( i < 1 ) return INF;

  if( i == 1 ) return 0;

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



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

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



  memo[i] = min(a1, a2);



  return memo[i];

}



signed main()

{

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



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



  cin >> n;



  reps(i, 1, n) cin >> h[i];



  cout << dp(n) << endl;



  return 0;

}


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

#pragma GCC optimize("Ofast")



// Begin {{{

using namespace std;



#ifndef DEBUG

#define dump(...)

#endif



template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }



template <class T>

inline vector<T> make_v(const T &initvalue, intmax_t sz) {

    return vector<T>(sz, initvalue);

}



template <class T, class... Args>

inline auto make_v(const T &initvalue, intmax_t sz, Args... args) {

    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));

}



constexpr int INF = 0x3f3f3f3f;

constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

// }}} End



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);



    size_t N; cin >> N;



    vector<int> h(N);

    for (auto &hi: h) cin >> hi;



    vector<int> dp(N, INF);

    dp[0] = 0;

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

        for (size_t j = 1; j <= 2; ++j) {

            if (i + j < N) {

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

            }

        }

    }



    cout << dp[N - 1] << "\n";



    return 0;

}
// Slower C++ solution:
/* Code by : Suraj (@suraj1611) */



#include<bits/stdc++.h>

#include <string>



using namespace std;



#define ll long long int

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

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

#define mx INT_MAX

#define mn INT_MIN

#define md 1000000007

#define pb push_back

#define mp make_pair

#define pf printf

#define sc scanf

#define maxsize 1100005

#define lb cout<<endl;

#define F first

#define S second

#define print(i) cout<<i<<endl

#define print1(i,j) cout<<i<<" "<<j<<endl

#define label cout<<"hello!"<<endl

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



ll dp[maxsize];



ll power(ll x, ll  y) 

{ 

    if (y == 0) 

        return 1; 

    else if (y%2 == 0) 

        return power(x, y/2)*power(x, y/2); 

    else

        return x*power(x, y/2)*power(x, y/2); 

} 



int main()

{

	IOS

	

	/*#ifndef ONLINE_JUDGE   

	    freopen("in.txt", "r", stdin);

	    freopen("out.txt", "w", stdout);

	#endif*/



	    

	    rep(i,maxsize)

	    dp[i]=mx;

	    ll n;

		cin>>n;

		ll a[n];

		rep(i,n)

		cin>>a[i];

		

		dp[0]=0;



		rep(i,n)

		{

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

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

		}



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



	/*

	#ifndef ONLINE_JUDGE

    	cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";

    #endif*/



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 10.129320467406103x):
/* Code by : Suraj (@suraj1611) */



#include<bits/stdc++.h>

#include <string>



using namespace std;



#define ll long long int

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

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

#define mx INT_MAX

#define mn INT_MIN

#define md 1000000007

#define pb push_back

#define mp make_pair

#define maxsize 1100005

#define lb cout<<endl;

#define endl "\n"

#define F first

#define S second

#define label cout<<"hello!"<<endl

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





ll power(ll x, ll  y) 

{ 

	ll m=md;

   	ll ans=1;

    while (y > 0) 

    {

        if (y & 1)

            ans = (ans * x) % m;

        x = (x * x) % m;

        y >>= 1;

    }

    return ans;

} 



int main()

{

	IOS

	







		ll n;

		cin>>n;

		ll a[n];

		ll dp[n];

		rep(i,n)

		cin>>a[i];

		dp[0]=a[0];

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

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

		{

			if(i==2)

			{

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

				continue;

			}

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

		}

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



	



	



    return 0;

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

using namespace std;



long dp[100001], a[100001], n;



long magic(int i){

	if(i == n)

		return 0;

	if(i > n)

		return 1e9 + 7;

	long &ret = dp[i];

	if(~ret)

		return ret;

	long p1, p2;

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

	p2 = abs(a[i] - a[i + 2]) + magic(i + 2);

	return ret = min(p1, p2);

}



int main(){

 

	ios::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);



	memset(dp, -1, sizeof dp);

	cin >> n;

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

		cin >> a[i];

	cout << magic(1);

	return 0;

}

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

using namespace std;



int main(){ 

    

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    

    int n, a[100001];

    cin >> n;

    vector<int> dp(n, INT_MAX);

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

        cin >> a[i];

    dp[0] = 0;

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

        if(i + 1 < n)

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

        if(i + 2 < n)

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

    }

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

    return 0;

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

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

using namespace std;

typedef long long ll;



int n;

vector<int> h(100000);

vector<int> cost(100000);



int ans(int n)

{

    if (cost.at(n) != -1)

        return cost.at(n);

    cost.at(n) = min(ans(n - 1) + abs(h.at(n) - h.at(n - 1)),

                     ans(n - 2) + abs(h.at(n) - h.at(n - 2)));

    return cost.at(n);

}



int main()

{

    cin >> n;

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

    {

        cin >> h.at(i);

        cost.at(i) = -1;

    }

    cost.at(0) = 0;

    cost.at(1) = abs(h.at(1) - h.at(0));

    cout << ans(n - 1) << endl;



    return 0;

}

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

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

using namespace std;

typedef long long ll;



int main()

{

    int n;

    cin >> n;

    vector<int> h(n);

    vector<int> dp(n);

    rep(i,n) {

        cin >> h[i];

        dp [i] = -1;

    }

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





    return 0;

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

using namespace std;



int dp[100001];



int recurse(auto& h, int i) {

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

    	return dp[i];

    } else if(i == 1) {

  		return dp[i] = 0;

    } else if(i == 2) {

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

    } else {

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

    }

}



int main() {

	int n; cin >> n;

  	vector<int> h(n + 1);

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

    	cin >> h[i];

    }

  	memset(dp, -1, sizeof dp);

  	cout << recurse(h, n);

}

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

using namespace std;



signed main() {

  	int n; cin >> n;

  	vector<int> h(n);

  	for(int& i: h) cin >> i;

  	int dp[n];

  	memset(dp, 0, sizeof dp);

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

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

	return 0;

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

#define ll long long

#define ff first

#define ss second

#define mp make_pair

#define mod(d) d%1000000007

#define loop(i,s,e) for(ll i=s;i<e;i++)

#define vll vector<ll>

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

using namespace std;



int dp[1000000];



int MinimJumpCost(ll n,ll pos,int* A){

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

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

	int ans1=0;

	int ans2=0;

	int ans=0;

	if(pos<n-2){

    ans1+=abs(A[pos]-A[pos+1])+MinimJumpCost(n,pos+1,A);

    ans2+=abs(A[pos]-A[pos+2])+MinimJumpCost(n,pos+2,A); 

    ans=min(ans1,ans2);

    }

    else {

    	ans+=MinimJumpCost(n,pos+1,A)+abs(A[pos]-A[pos+1]);

    }

	return dp[pos] = ans;

}



int main(){

	

    ll n;

    cin>>n;



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



    int* A= new int[n];

    loop(i,0,n)cin>>A[i];



    cout<<MinimJumpCost(n,0,A)<<endl;



}




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

#include <ext/pb_ds/assoc_container.hpp> 

#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;

using namespace std;

 

#define ff                  first

#define ss                  second

#define endl                "\n"

#define loop(i,s,e)         for(int i=s;i<e;i++)

#define int                 long long

#define vi                  vector<int> 

#define S(v)                sort(v.begin(),v.end())

#define RS(v)               sort(v.rbegin(),v.rend())

#define R(v)                reverse(v.begin(),v.end())

#define mxpq(T)             priority_queue <T>

#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>

#define prv(v)              for(auto &x : v)cout << x << " ";

#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;

#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";

#define mp                  make_pair

#define pii                 pair<int,int>

#define mset(a,f)           memset(a , f , sizeof(a))

#define pb                  push_back

#define inf                 INT_MAX

#define INF                 LLONG_MAX

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



const int N = 2e6 + 6;

int A[N];

int dp[N];

int n;





void solve()

{

    cin >> n;



    loop(i,0,n)cin >> A[i];



    loop(i,0,n+1)dp[i] = inf;



    dp[0] = 0;

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



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

}

 

int32_t main()

{

 

cout<<fixed<<setprecision(16);



ios_base:: sync_with_stdio(false);

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

     



     int t = 1;

     // cin >> t;

     while(t--)solve();

  

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



using namespace std;

int a[100005],dp[100003];

int n;

int mincost(int x)

{

	if(dp[x]!=-1)

		return dp[x];

	if(x==n)

	{

		dp[x]=0;

		return dp[x];

	}

	if(x==n-1)

	{

		if(dp[x]==-1)

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

		return dp[x];

	}

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

	return dp[x];

}

int main()

{

	cin>>n;

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

	{

		cin>>a[i];

	}

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

	{

		dp[i]=-1;

	}

	

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

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

	// {

	// 	cout<<dp[i]<<' ';

	// }

	// cout<<'\n';



}

// Faster C++ solution for the same problem (measured speedup: 1.3322968306505907x):
//  Mayank Agarwal

//  IIIT Hyderabad







#include<bits/stdc++.h>

using namespace std;

const long long int M = 1000000007; 

#define ll long long int

#define ld double

#define pb push_back

#define mp make_pair

ll power(ll x, ll y,  ll p) 

{ 

    ll res = 1;      

    x = x % p;   

    while (y > 0) 

    { 

        if (y & 1) 

            res = (res*x) % p; 

        y = y>>1;x = (x*x) % p; 

    } return res%p; 

} 

ll modinver(ll a,ll b)

{

    return (power(a,1,M)*power(b,M-2,M))%M;

}

void SieveOfEratosthenes(int n) 

{   

    bool prime[10005]; 

    memset(prime, true, sizeof(prime)); 

  

    for (int p=2; p*p<=n; p++) 

    { 

        if (prime[p] == true) 

        { 

            for (int i=p*p; i<=n; i += p) 

                prime[i] = false; 

        } 

    } 

} 

int main()

{

    ios_base::sync_with_stdio(false);

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

    ll n;

    cin>>n;

    ll a[100002];

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

    {

    	cin>>a[i];

    }

    ll dp[100002];

    dp[n]=0;

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

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

    {

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

    }

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

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

#include <algorithm>

#include <cstring>

#include <functional>

#include <bits/stdc++.h>

using namespace std;

int n,c,dp[100001];

vector<int> h;

int cost(int i)

{

    if(i==n-1)

        return 0;

    if(dp[i]!=-1)

        return dp[i];

    else

    {

        if(i+2<n)

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

        else

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

        return dp[i];

    }

}

int main()

{

    std::ios::sync_with_stdio(false);

    memset(dp,-1,sizeof dp);

    int x;

    cin>>n;

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

    {

        cin>>x;

        h.push_back(x);

    }

    cout<<cost(0)<<endl;

    return 0;

}


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

#include <algorithm>

#include <cstring>

#include <functional>

#include <bits/stdc++.h>

using namespace std;

int n;

vector<int> h;

int main()

{

    std::ios::sync_with_stdio(false);

    int x;

    cin>>n;

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

    {

        cin>>x;

        h.push_back(x);

    }

    int d[n];

    d[n-1]=0;

    d[n-2]=abs(h[n-1]-h[n-2]);

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

    {

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

    }

    cout<<d[0];

    return 0;

}