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

#define f(i,s,v) for(int i=(int)s;i<(int)v;++i)

#define rf(i,s,v) for(int i=(int)s-1;i>(int)v;--i)

#define pb push_back

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

#define memset(c, value) memset(c, (int)value, sizeof(c))

using namespace std;

typedef long long ll;

const int oo = 1e9;

const ll MOD =1e9+7;

void fast(){

    ios_base :: sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}

int n;

int h[100005];

bool valid (int r,int c){

    return (r < n && r >= 0 && c >= 0 && c < n);

}

int row[] = {0 , 1 , 0, -1};

int column[] = {1 , 0, -1, 0};

int vis[100002];

int dp(int i){

    if(i == n-1)

        return 0;

    int &ret = vis[i];

    if(ret != -1)

        return ret;



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

    if(i+2 < n)

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

    return ret = path1;

}



int main()

{

    fast();

    memset(vis, -1);

    cin>>n;

    f(i,0,n)

        cin>>h[i];

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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.4352077533841998x):
/*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]);

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

#include<cstring>

#include<algorithm>





using namespace std;



const long long inf= 1e10+ 123;

const int mx=1e5+123;

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



int solve( int i)

{

    if(i==n)

        return 0;



    if(dp[i]!= -1)

        return dp[i];



    int ret1, ret2;

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

    if(i+2<=n)

        ret2= abs(h[i]- h[i+2])+ solve(i+2);

    else

        ret2= inf;

    return dp[i]=min(ret1, ret2);

}



int main()

{

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



    cin>> n;

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

        cin>> h[i];



    cout<< solve(1)<< endl;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.4216398158959305x):
/*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]);

}
// Slower C++ solution:
/*

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

}


// Faster C++ solution for the same problem (measured speedup: 1.4324898810378475x):
/*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]);

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.8365641599511817x):
/*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]);

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.405770268718594x):
/*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]);

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.4182519148910744x):
/*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]);

}
// Slower C++ solution:
#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));

}


// Faster C++ solution for the same problem (measured speedup: 1.812216005143538x):
/*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]);

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.162926327242564x):
/*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]);

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.8243954753401719x):
/*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]);

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

using namespace std;

#define    sz    100110

#define    ll    long long int

ll n,c=0,p,q;

ll num[sz];

ll vis[sz];

ll dp[sz];



ll tani(int pos)

{



  if(pos>=n)return 0;

  if(vis[pos]==1)return dp[pos];

  vis[pos]=1;



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



}



int main()

{

    ll t,i;



    for(i=1;i<sz;i++)num[i]=1000000;



    cin>>n;

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

    {

        cin>>num[i];

    }

    t=tani(1);

    cout<<t<<endl;

    return 0;

}


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

using namespace std;



int main()

{



    int n;

    cin >> n;

    vector<int> DP(n, 0);

    int height [n];



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

        cin>>height[i];

    }



    DP[1]=abs(height[1]-height[0]);



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

        DP[i] = min(abs(height[i]-height[i-1]) + DP[i-1], abs(height[i]-height[i - 2])+DP[i-2]);

    }



    cout<<DP[n-1];

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

using namespace std;



#define fr(i,n) _back

#define pb	push_back

#define eb	emplace_back

#define mk	make_pair

#define fi	first

#define se	second

#define endl	'\n'



typedef long long ll;

typedef pair<int,int> ii;

typedef vector<ii> vii;

const int INF = 0x3f3f3f3f;

const double PI = acos(-1.0);

const int N = 1e5 + 3;

int h[N];

int dp[N];



int main() {

    ios_base::sync_with_stdio(false);

    memset(dp, INF, sizeof dp);

    int n; cin >> n;

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



    dp[0] = 0;

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

        for(int j = max(0,i-2); j < i; j++)

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



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

    return 0;

}


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

using namespace std;



int main()

{



    int n;

    cin >> n;

    vector<int> DP(n, 0);

    int height [n];



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

        cin>>height[i];

    }



    DP[1]=abs(height[1]-height[0]);



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

        DP[i] = min(abs(height[i]-height[i-1]) + DP[i-1], abs(height[i]-height[i - 2])+DP[i-2]);

    }



    cout<<DP[n-1];

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

using namespace std;



int N, a[100100], dp[100100];



int f(int n) {

	if (n==1) return 0;

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

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

	dp[n] = min(

				f(n-1) + abs(a[n] - a[n-1]),

				f(n-2) + abs(a[n] - a[n-2])

				);

	return dp[n];

}



int main() {

	cin >> N;

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

		cin >> a[i];

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

	cout << f(N) << endl;

	return 0;

}

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

using namespace std;



int main()

{



    int n;

    cin >> n;

    vector<int> DP(n, 0);

    int height [n];



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

        cin>>height[i];

    }



    DP[1]=abs(height[1]-height[0]);



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

        DP[i] = min(abs(height[i]-height[i-1]) + DP[i-1], abs(height[i]-height[i - 2])+DP[i-2]);

    }



    cout<<DP[n-1];

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

using namespace std;

typedef long long LL;



int arr[100007];

int dp[100007];



int Solve(int idx, int n){

//	cout<<cost<<" "<<idx<<endl;

	if(idx >= n)return 1e9;

	if(idx == n - 1){

		return 0;	

	}

	

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

	

	

	return dp[idx] = min(abs(arr[idx] - arr[idx+1]) + Solve(idx+1, n), abs(arr[idx] - arr[idx+2]) + Solve(idx+2,n));

}



int main(){

	int n; cin>>n;

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

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

		

	cout<<Solve(0,n)<<endl;

	return 0;

}

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

using namespace std;



int main()

{



    int n;

    cin >> n;

    vector<int> DP(n, 0);

    int height [n];



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

        cin>>height[i];

    }



    DP[1]=abs(height[1]-height[0]);



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

        DP[i] = min(abs(height[i]-height[i-1]) + DP[i-1], abs(height[i]-height[i - 2])+DP[i-2]);

    }



    cout<<DP[n-1];

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

using namespace std;

int dp[100005];

int H[100005];

void memo(int i,int n)

{

	if(i==n) return;

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

	memo(i+1,n);

}

int main()

{

	int N;cin>>N;

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

	{

        cin>>H[i];

	}

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

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

	memo(2,N);

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

	return 0;

}

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

using namespace std;



int main()

{



    int n;

    cin >> n;

    vector<int> DP(n, 0);

    int height [n];



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

        cin>>height[i];

    }



    DP[1]=abs(height[1]-height[0]);



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

        DP[i] = min(abs(height[i]-height[i-1]) + DP[i-1], abs(height[i]-height[i - 2])+DP[i-2]);

    }



    cout<<DP[n-1];

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



using namespace std;



int dp[(int)1e5+5];

int main()

{



    ios_base::sync_with_stdio(0);cin.tie(0);







    fill(dp, dp+(int)1e5+5 , INT_MAX );



    dp[1] = 0;

    int n;

    cin>>n;

    vector <int> v(n+3,0);

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



        cin>>v[i];



    }

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



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

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



    }

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

}


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

using namespace std;



int main()

{



    int n;

    cin >> n;

    vector<int> DP(n, 0);

    int height [n];



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

        cin>>height[i];

    }



    DP[1]=abs(height[1]-height[0]);



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

        DP[i] = min(abs(height[i]-height[i-1]) + DP[i-1], abs(height[i]-height[i - 2])+DP[i-2]);

    }



    cout<<DP[n-1];

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



using namespace std;



#define REP(i,a,b) for(ll i = a; i < b; i++)

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

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

#define endl '\n'



typedef long long ll;

typedef unsigned long long ull;

typedef pair<ll, ll> pii;

typedef pair<int, pii> tri;

typedef vector <vector <ll>> matrix;

typedef pair<string, string> pss;



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

const int MAX = (int)1e6 + 100;



const ll oo = 0x3f3f3f3f3f3f3f3f;



ll dp[MAX], a[MAX];



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    memset(dp, oo, sizeof(dp));



    int n; cin >> n;



    dp[1] = 0;



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

        cin >> a[i];

    }



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

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

        if(i - 2 >= 1){

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

        }

    }



    cout << dp[n] << endl;

}


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

using namespace std;



int main()

{



    int n;

    cin >> n;

    vector<int> DP(n, 0);

    int height [n];



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

        cin>>height[i];

    }



    DP[1]=abs(height[1]-height[0]);



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

        DP[i] = min(abs(height[i]-height[i-1]) + DP[i-1], abs(height[i]-height[i - 2])+DP[i-2]);

    }



    cout<<DP[n-1];

}