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

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

#define ii          pair<int,int>

#define F           first

#define S           second

#define pb          push_back

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

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

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

#define forr(i,a)   for(int i = a; i >= 0; i--)

#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 

#define w(t)        while(t--)

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

#define cls(a,car)  memset(a,car,sizeof (a))

#define db(x)       cerr << #x << " is " << x << '\n'

#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);

#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

#define angle(x)    double(x * acos(-1) / 180.0)

using namespace std;

typedef long long   ll;

typedef vector<int> vi;

typedef vector<ii>  vii;

const int N = 1 * 1e5 + 5;

const ll mod = 1e9 + 7;

const double E = 1e-9;

//int dx[] = {1, 0}, dy[] = {0, 1};

//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};

//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0 ,1, 1, 1, 0, -1, -1, -1};

// fflush(stdout)

// cout << flush

// a + b = a ^ b + 2 * (a & b)

int v[N];

int dp[N];

int n, k = 2;

int f(int i){

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

    int &ans = dp[i];

    if(ans == -1){

        ans = 1e9;

        for(int j = 1; j <= k; j++)

            if(i + j < n)

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

            else

                break;

    }

    return ans;

}

int main(){

    //FL;

    FIN;

    cin >> n;

    fore(i, 0, n)cin >> v[i];

    cls(dp, -1);

    cout << f(0) << '\n';

    

    EjecuteTime;

    return 0;

}       

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

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

#define pii pair<int,int>

#define ll long long int

#define ull unsigned long long int

#define inf LONG_MAX;

using namespace std;

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

int main()

{

    fast_io

    cin>>n;

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

        cin>>h[i];

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

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

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

    cout<<dp[n]<<endl;

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

#define INF 0x3f3f3f3f

using namespace std;

const int maxn = 1e6+10;

int a[maxn];

int dp[maxn];

int main()

{

    int n;

    memset(dp,INF,sizeof dp);

    scanf("%d",&n);

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

    {

        scanf("%d",a+i);

    }

    dp[1]=0;

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

    {

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

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

    }

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

    return 0;

}


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

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

#define pii pair<int,int>

#define ll long long int

#define ull unsigned long long int

#define inf LONG_MAX;

using namespace std;

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

int main()

{

    fast_io

    cin>>n;

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

        cin>>h[i];

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

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

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

    cout<<dp[n]<<endl;

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

using namespace std;



const int mx=1e5+1;

int n,k;

int h[mx],dp[mx];

int solve(int s) //s->no of stone

{

    if(s==n) return 0;

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

    int ret=INT_MAX;

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

        if((i+s)<=n) ret=min(ret,abs(h[s+i]-h[s])+solve(s+i));

    }

    return dp[s]=ret;

}

int main()

{

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

    //freopen("input.txt","r",stdin);    return 0;



    cin>>n;

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

    memset(dp,-1,sizeof dp);

    cout<<solve(1);



    return 0;

}


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

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

#define pii pair<int,int>

#define ll long long int

#define ull unsigned long long int

#define inf LONG_MAX;

using namespace std;

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

int main()

{

    fast_io

    cin>>n;

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

        cin>>h[i];

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

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

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

    cout<<dp[n]<<endl;

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

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

const int maxn=100000+10;

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

int main()

{

	cin>>n;

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

	memset(dp,0x3f3f3f3f,sizeof(dp));

	dp[1]=0;

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

	{

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

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

	}

	cout<<dp[n]<<endl;

	return 0;

}

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

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

#define pii pair<int,int>

#define ll long long int

#define ull unsigned long long int

#define inf LONG_MAX;

using namespace std;

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

int main()

{

    fast_io

    cin>>n;

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

        cin>>h[i];

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

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

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

    cout<<dp[n]<<endl;

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

#define N 100007

#define inf 999999999

using namespace std;



long long mem[N];

long long ara[N];

int n;



long long dp(int i, int j)

{

    if(i >= n)

        return inf;

    if(i == j)

        return 0;

    if(mem[i] != -1)

        return mem[i];

    long long ans = min(abs(ara[i + 1] - ara[i]) + dp(i + 1, j), abs(ara[i + 2] - ara[i]) + dp(i + 2, j));

    mem[i] = ans;

    return ans;

}

int main()

{

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

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

    cin >> n;

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

        cin >> ara[i];

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

    cout << dp(0, n - 1) << endl;

    return 0;

}

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

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

#define pii pair<int,int>

#define ll long long int

#define ull unsigned long long int

#define inf LONG_MAX;

using namespace std;

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

int main()

{

    fast_io

    cin>>n;

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

        cin>>h[i];

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

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

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

    cout<<dp[n]<<endl;

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

using namespace std;

using ll = long long;

using ii = pair<int, int>;

using iii = pair<ii, int>;

#define vt vector

#define pq priority_queue

#define pb push_back

#define pf push_front

#define mp make_pair

#define fi first

#define se second

#define __lcm(a, b) a * b / __gcd(a, b)

const int MOD = 1e9 + 7;

const int INF = 2e9;

const int N = 1e5 + 5;



int n;

int a[N], dp[N];



int f(int idx) {

    if(idx > n) return INF;

    if(idx == n) return 0;

    int &sol = dp[idx];

    if(sol != -1) return sol;

    return sol = min(f(idx + 1) + abs(a[idx] - a[idx + 1]), 

                     f(idx + 2) + abs(a[idx] - a[idx + 2]));

}



void solve() {

    cin >> n;

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

        cin >> a[i];

    }

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

    cout << f(1) << "\n";

}



int main() {

 

    ios_base::sync_with_stdio(0);

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

    

    solve();

    

}

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

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

#define pii pair<int,int>

#define ll long long int

#define ull unsigned long long int

#define inf LONG_MAX;

using namespace std;

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

int main()

{

    fast_io

    cin>>n;

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

        cin>>h[i];

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

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

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

    cout<<dp[n]<<endl;

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

#define pb emplace_back

#define ll long long

#define mp make_pair

#define PI acos(-1)

using namespace std;

ll dp[200005],a[200005],n;

ll solve(ll idx)

{

    if(idx>=n-1)

        return 0;

    if(dp[idx]!=-1)

        return dp[idx];

    ll res=INT_MAX;

    if(idx+1<n)

        res=min(res,abs(a[idx+1]-a[idx])+solve(idx+1));

    if(idx+2<n)

        res=min(res,abs(a[idx+2]-a[idx])+solve(idx+2));

    return dp[idx]=res;

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    ll i,j,k,x,y,z,m,t,l,r;

    cin>>n;

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

        cin>>a[i];

    memset(dp,-1,sizeof dp);

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

}














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

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

#define pii pair<int,int>

#define ll long long int

#define ull unsigned long long int

#define inf LONG_MAX;

using namespace std;

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

int main()

{

    fast_io

    cin>>n;

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

        cin>>h[i];

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

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

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

    cout<<dp[n]<<endl;

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

#define fr(i,a,n) for(ll i=a;i<n;i++)

#define YES cout<<"YES"<<endl

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

#define NO cout<<"NO"<<endl

#define pb(x) emplace_back(x)

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

#define vi vector<ll>

#define mi map<ll,ll>

#define pi pair<ll,ll>

#define what(x) cout<<#x<<" ="<<x<<endl;

#define scn(n) scanf("%d",&n)

#define print(a) printf("%d",a);

using namespace std;

using ll =int;

ll n;



ll dp[200005],a[200005]={1000000000};

ll invalid=1e9;

ll cnt=0;

int solve(ll i,ll p)

{ //cnt++;

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

    if(i>=n)return 1e9;

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

    //what(p-a[i]);

    //cout<<i<<" GG "<<i+1<<endl;



    ll x=abs(a[i+1]-a[i])+solve( i+1,a[i]);



   // what(x);



    ll y=abs(a[i+2]-a[i])+solve(i+2,a[i]);

   // cout<<i<<" "<<i+2<<endl;

   //what(x); what(y);

    x=min(x,y);







    return dp[i]=x;



}



int main()

{

    ll t;

    memset(dp,-1,sizeof dp);



    scn(n);

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



    solve(0,a[0]);



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

    //what(cnt);

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



}




















































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

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

#define pii pair<int,int>

#define ll long long int

#define ull unsigned long long int

#define inf LONG_MAX;

using namespace std;

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

int main()

{

    fast_io

    cin>>n;

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

        cin>>h[i];

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

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

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

    cout<<dp[n]<<endl;

}
// Slower C++ solution:


/**

    And in the end, the love you take is equal to the love you make.



        I LOVE YOU LAURA.

**/



#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/rope>



#define _CRT_SECURE_NO_DEPRECATE

#define _CRT_DISABLE_PERFCRIT_LOCKS



#define findOrder find_by_order

#define orderKey order_of_key



#define isOn(mask, i) (mask & (1 << i))

#define turn(mask, i) (mask |= (1 << i))

#define switch(mask, i) (mask &= ~(1 << i))

#define change(mask, i) (mask ^= (1 << i))

#define lowbit(mask) (mask & (-mask))

#define turnAll(mask, n) (mask = (1 << n) - 1)

#define switchLastBit(mask) (mask & (mask - 1))

#define turnLastZero(mask) (mask | (mask + 1))

#define modulo(x, mod) ((x) & (mod - 1))

#define log2(x) (31 - __builtin_clz(x))



#define mkp make_pair

#define pb push_back

#define pf push_front

#define eb emplace_back

#define ef emplace_front

#define ins insert

#define rsz resize

#define f first

#define s second

#define lb lower_bound

#define ub upper_bound



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

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

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



#define debug(x) (cerr << x << " ")



using namespace std;

using namespace __gnu_pbds;

using namespace __gnu_cxx;



typedef double db;

typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;



typedef pair<int, int> ii;

typedef pair<ll,ll> pll;

typedef pair<ld,ld> pdb;

typedef pair<int, ii> tri;

typedef complex<ld> cd;



typedef vector<int> vi;

typedef vector<ii> vii;

typedef vector<ld> vdb;

typedef vector<cd> vcd;

typedef vector<ll> vll;

typedef vector<string> vs;

typedef vector<vll> matrix;



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



const ll mod = 1e9+7;

const int maxn = 2e5+2;

const int pi = 2 * acos(0.0);

const db eps = 1e-9;



ll arr[maxn], dp[maxn];



int main()

{

    ios_base::sync_with_stdio(0);

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



    int n; cin >> n;



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

        cin >> arr[i];

    }



    memset(dp, 63, sizeof dp);



    dp[1] = 0;

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

        if (i <= 2){

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

        }

        else{

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

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

        }

    }



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



    return 0;

}


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

using namespace std;

int n;

long long dp[100009],ans;

long long arr[100009];

int solve(int idx)

{

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

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

    ans=solve(idx+1)+(abs(arr[idx+1]-arr[idx]));

    if(idx+2<n)

       {

           ans=min(ans,solve(idx+2)+ abs(arr[idx+2]-arr[idx]));

       }

    return dp[idx]=ans;

}

int main()

{

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

    cin>>n;

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

    cout<<solve(0)<<endl;

    return 0;

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

using namespace std;

#define ll long long int

#define dbl double

#define pi acos(-1)

#define sc1(a) scanf("%lld",&a)

#define sc2(a,b) scanf("%lld%lld",&a,&b)

#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)

#define pb push_back



ll ara[1000005];



map<ll,ll>vis;

map<ll,ll>vis1;

map<ll,ll>pos;

map<ll,ll>high;

map<ll,ll>low;

map<string,ll>mp;

vector<ll>vec;

vector<ll>v;

stack<ll>q;

string str1[100];

string str2[100];

priority_queue<ll>pq;

ll dp[1000005],t;

ll mn=1000000;

ll call(ll id)

{

    if(id==t )return 0;

    if(dp[id]!=-1)

        return dp[id];

    ll p=call(id+1)+abs(ara[id+1]-ara[id]);

    ll q=100000000;

    if(id+2!=t+1)

        q=call(id+2)+abs(ara[id+2]-ara[id]);

    dp[id]=min(p,q);

    return dp[id];



}

int main()

{



    // ll t;

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

    sc1(t);

    for(ll i=1; i<=t; i++)

    {

        sc1(ara[i]);

    }

    cout<<call(1)<<endl;

    return 0;

}


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

using namespace std;

int n;

long long dp[100009],ans;

long long arr[100009];

int solve(int idx)

{

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

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

    ans=solve(idx+1)+(abs(arr[idx+1]-arr[idx]));

    if(idx+2<n)

       {

           ans=min(ans,solve(idx+2)+ abs(arr[idx+2]-arr[idx]));

       }

    return dp[idx]=ans;

}

int main()

{

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

    cin>>n;

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

    cout<<solve(0)<<endl;

    return 0;

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

using namespace std;



int a[1000001];

int dp[1000001];

int it;



int fr(int p){

	if (p==it-1){

      return 0;

    }

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

      return dp[p];

    }

	int re=abs(a[p]-a[p+1])+fr(p+1);

	if(p!=it-2){

      re=min(re,abs(a[p]-a[p+2])+fr(p+2));

    }

	return dp[p]=re;

}

int main(){

	cin>>it;

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

    cin>>a[i];

    }



	memset(dp,-1,sizeof dp);

	cout<<fr(0)<<endl;

	return 0;

}


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

using namespace std;

int n;

long long dp[100009],ans;

long long arr[100009];

int solve(int idx)

{

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

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

    ans=solve(idx+1)+(abs(arr[idx+1]-arr[idx]));

    if(idx+2<n)

       {

           ans=min(ans,solve(idx+2)+ abs(arr[idx+2]-arr[idx]));

       }

    return dp[idx]=ans;

}

int main()

{

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

    cin>>n;

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

    cout<<solve(0)<<endl;

    return 0;

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

#define INF 0x3f3f3f3f

using namespace std;

const int maxn = 1e6+10;

int a[maxn];

int dp[maxn];

int main()

{

    int n;

    memset(dp,INF,sizeof dp);

    scanf("%d",&n);

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

    {

        scanf("%d",a+i);

    }

    dp[1]=0;

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

    {

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

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

    }

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

    return 0;

}


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

using namespace std;

int n;

long long dp[100009],ans;

long long arr[100009];

int solve(int idx)

{

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

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

    ans=solve(idx+1)+(abs(arr[idx+1]-arr[idx]));

    if(idx+2<n)

       {

           ans=min(ans,solve(idx+2)+ abs(arr[idx+2]-arr[idx]));

       }

    return dp[idx]=ans;

}

int main()

{

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

    cin>>n;

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

    cout<<solve(0)<<endl;

    return 0;

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

#define pb emplace_back

#define ll long long

#define mp make_pair

#define PI acos(-1)

using namespace std;

ll dp[200005],a[200005],n;

ll solve(ll idx)

{

    if(idx>=n-1)

        return 0;

    if(dp[idx]!=-1)

        return dp[idx];

    ll res=INT_MAX;

    if(idx+1<n)

        res=min(res,abs(a[idx+1]-a[idx])+solve(idx+1));

    if(idx+2<n)

        res=min(res,abs(a[idx+2]-a[idx])+solve(idx+2));

    return dp[idx]=res;

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    ll i,j,k,x,y,z,m,t,l,r;

    cin>>n;

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

        cin>>a[i];

    memset(dp,-1,sizeof dp);

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

}














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

using namespace std;

int n;

long long dp[100009],ans;

long long arr[100009];

int solve(int idx)

{

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

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

    ans=solve(idx+1)+(abs(arr[idx+1]-arr[idx]));

    if(idx+2<n)

       {

           ans=min(ans,solve(idx+2)+ abs(arr[idx+2]-arr[idx]));

       }

    return dp[idx]=ans;

}

int main()

{

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

    cin>>n;

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

    cout<<solve(0)<<endl;

    return 0;

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

using namespace std;

#define ll long long int

#define dbl double

#define pi acos(-1)

#define sc1(a) scanf("%lld",&a)

#define sc2(a,b) scanf("%lld%lld",&a,&b)

#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)

#define pb push_back



ll ara[1000005];



map<ll,ll>vis;

map<ll,ll>vis1;

map<ll,ll>pos;

map<ll,ll>high;

map<ll,ll>low;

map<string,ll>mp;

vector<ll>vec;

vector<ll>v;

stack<ll>q;

string str1[100];

string str2[100];

priority_queue<ll>pq;

ll dp[1000005],t;

ll mn=1000000;

ll call(ll id)

{

    if(id==t )return 0;

    if(dp[id]!=-1)

        return dp[id];

    ll p=call(id+1)+abs(ara[id+1]-ara[id]);

    ll q=100000000;

    if(id+2!=t+1)

        q=call(id+2)+abs(ara[id+2]-ara[id]);

    dp[id]=min(p,q);

    return dp[id];



}

int main()

{



    // ll t;

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

    sc1(t);

    for(ll i=1; i<=t; i++)

    {

        sc1(ara[i]);

    }

    cout<<call(1)<<endl;

    return 0;

}


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



using namespace std;



#define ll long long



const int N = 1e5+4;

const ll inf = 1e16;

int h[N], n;

ll dp[3][N];



ll f(int j, int t)

{

    if(j > n)

        return inf;



    if(dp[t][j] != -1)

        return dp[t][j];



    ll x = f(j + 1, 1), y = f(j + 2, 2);



    if(x == inf and y == inf)

        x = y = 0;



    return dp[t][j] = abs(h[j] - h[j - t]) + min(x, y);

}



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    cin >> n;



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

        cin >> h[i];



    memset(dp, -1, sizeof dp);



    cout << f(1, 0) << '\n';



    return 0;

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

using namespace std;



int a[1000001];

int dp[1000001];

int it;



int fr(int p){

	if (p==it-1){

      return 0;

    }

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

      return dp[p];

    }

	int re=abs(a[p]-a[p+1])+fr(p+1);

	if(p!=it-2){

      re=min(re,abs(a[p]-a[p+2])+fr(p+2));

    }

	return dp[p]=re;

}

int main(){

	cin>>it;

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

    cin>>a[i];

    }



	memset(dp,-1,sizeof dp);

	cout<<fr(0)<<endl;

	return 0;

}


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



using namespace std;



#define ll long long



const int N = 1e5+4;

const ll inf = 1e16;

int h[N], n;

ll dp[3][N];



ll f(int j, int t)

{

    if(j > n)

        return inf;



    if(dp[t][j] != -1)

        return dp[t][j];



    ll x = f(j + 1, 1), y = f(j + 2, 2);



    if(x == inf and y == inf)

        x = y = 0;



    return dp[t][j] = abs(h[j] - h[j - t]) + min(x, y);

}



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    cin >> n;



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

        cin >> h[i];



    memset(dp, -1, sizeof dp);



    cout << f(1, 0) << '\n';



    return 0;

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

#define INF 0x3f3f3f3f

using namespace std;

const int maxn = 1e6+10;

int a[maxn];

int dp[maxn];

int main()

{

    int n;

    memset(dp,INF,sizeof dp);

    scanf("%d",&n);

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

    {

        scanf("%d",a+i);

    }

    dp[1]=0;

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

    {

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

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

    }

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

    return 0;

}


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



using namespace std;



#define ll long long



const int N = 1e5+4;

const ll inf = 1e16;

int h[N], n;

ll dp[3][N];



ll f(int j, int t)

{

    if(j > n)

        return inf;



    if(dp[t][j] != -1)

        return dp[t][j];



    ll x = f(j + 1, 1), y = f(j + 2, 2);



    if(x == inf and y == inf)

        x = y = 0;



    return dp[t][j] = abs(h[j] - h[j - t]) + min(x, y);

}



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    cin >> n;



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

        cin >> h[i];



    memset(dp, -1, sizeof dp);



    cout << f(1, 0) << '\n';



    return 0;

}