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



using namespace std;

int dp[100001];

int main() {



       int x,ans=0;

       cin>>x;

       int h[x];

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

        cin>>h[i];

       dp[1]=0;

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

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

       {

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



       }

       cout<<dp[x]<<endl;





}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

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

using namespace std;



int dp[100005];



int main(){

    int n;

    cin>>n;



    int arr[n];



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

        cin>>arr[i];





    dp[0]=0;

    if(n==1)

        cout<<0<<endl;



    else{

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





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

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



        }

    }



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

    return 0;







}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

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

using namespace std;



int main()

{

  int n;

  cin>>n;

  int arr[n],dp[n];

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

  {

      cin>>arr[i];

  }

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

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

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

  {

    int x=abs(arr[i]-arr[i-1]);

    int y=abs(arr[i]-arr[i-2]);

    dp[i]=min(dp[i-1]+x,dp[i-2]+y);

  }

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

  return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>



using namespace std;

const int N=100000;

int main(){

	int i,j,n,dp[N],a[N];

	cin>>n;

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

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

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

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

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

	}

	cout<<dp[n-1];

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

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

using namespace std;

typedef long long ll;

const int maxn=1e5+10;

ll dp[maxn];

ll a[maxn];

int main()

{

	int n;

	scanf("%d",&n);

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

		scanf("%lld",&a[i]);

	dp[1]=0;

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

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

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

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

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cmath>

using namespace std;

int main()

{

	int n;

	cin>>n;

    long long sum=0;

	int a[n];

	int dp[n];

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

	cin>>a[i];

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

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

using namespace std;

const int MAX = 100004;

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



int main()

{

    scanf("%d",&n);

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

    {

        cin>>h[i];

    }

    dp[0]=0;

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

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

    {

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

    }



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

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

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



using namespace std;

int v[100010];

int memo[100010];

int c;



int f(int i)

{



    if(memo[i]!=-1)

        return memo[i];



    if(i == 0)

        return memo[0] = 0;



    if(i == 1)

        return memo[1] = abs(v[0] - v[1]);



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

}



int main()

{



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

    cin>>c;



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

    {

        cin>>v[i];

    }



    cout<<f(c-1)<<endl;



    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

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



using namespace std;



const int N = 1e5 + 9;



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



int solve(int i){

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

    if(i == n)   return 1e9;



    int &ret = dp[i];

    if(~ret)    return ret;



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

}



int main(){



    cin >> n;

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

        cin >> h[i];



    memset(dp, -1, sizeof dp);



    cout << solve(0);

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

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

using namespace std;

int n;

long long h[100005];

long long dp[100005];



long long solve(int i){

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

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



	dp[i] = 1e17;

	if(i+1 <= n-1)

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

	if(i+2 <= n-1)

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



	return dp[i];

}



int main(){

	scanf("%d", &n);

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

		scanf("%lld", &h[i]);

	memset(dp, -1, sizeof dp);

	cout<<solve(0)<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <algorithm>

using std::min;

 

#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}

 

int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

    for(i=N-3;i>=0;i--)

    {

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

    }

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

 

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

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

#include <bits/stdc++.h>

#define pb push_back

#define f first

#define s second

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

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

#define SZ(a) (int)a.size()

#define Flush fflush(stdout);

typedef long long ll ;

using namespace std ;

int n;

const int M = 1e5 ;

int a[M]; 

int dp[M];

int main ()

{

    scanf ("%d" , &n );

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

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

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

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

    {

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

    }

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

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

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

#include<bits/stdc++.h>

#include<unordered_map>

using namespace std;

//<DEFINE>

void Fast() {

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

}

void File() {

#ifndef ONLINE_JUDGE

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

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

#endif

}

#define ll long long

#define ull unsigned long long

#define mod 1000000007

ll gcd(ll a, ll b) {

	return!b ? a : gcd(b, a % b);

}

#define fix(n) cout << fixed << setprecision(n);

#define numOfOnes(n) __builtin_popcount(n)

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

#define skip continue

#define stop(n) return cout<<n,0

#define pi  acos(-1)

#define endl "\n"

#define ceil(x,y) (x+y-1)/y

//</DEFINE>

int n;

vector<int>v;

int res[100001];

//<FUNCTIONS>

ll solve(int idx = 0) {

	ll res1, res2;

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

	if (~(res[idx]))return res[idx];

	res1 = 1e18;

	if (idx + 2 < n)res1 = solve(idx + 2) + abs(v[idx] - v[idx+2]);

	res2 = solve(idx + 1) + abs(v[idx] - v[idx+1]);

	return res[idx] = min(res1, res2);

}

//</FUNCTIONS>	

int main() {

	Fast();//, File();

	cin >> n;

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

		res[i] = -1;

	v.resize(n);

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

	cout << solve();

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

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

#include<bits/stdc++.h>

#include<unordered_map>

using namespace std;

//<DEFINE>

void Fast() {

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

}

void File() {

#ifndef ONLINE_JUDGE

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

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

#endif

}

#define ll long long

#define ull unsigned long long

#define mod 1000000007

ll gcd(ll a, ll b) {

	return!b ? a : gcd(b, a % b);

}

#define fix(n) cout << fixed << setprecision(n);

#define numOfOnes(n) __builtin_popcount(n)

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

#define skip continue

#define stop(n) return cout<<n,0

#define pi  acos(-1)

#define endl "\n"

#define ceil(x,y) (x+y-1)/y

//</DEFINE>



/*█▀▀▄░░░░░░░░░░░▄▀▀█

░█░░░▀▄░▄▄▄▄▄░▄▀░░░█

░░▀▄░░░▀░░░░░▀░░░▄▀

░░░░▌░▄▄░░░▄▄░▐▀▀

░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█

░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█

▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█

█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀

░▀▄░░▀░░▀▀▀░░▀░░░▄█▀

░░░█░░░░░░░░░░░▄▀▄░▀▄

░░░█░░░░░░░░░▄▀█░░█░░█

░░░█░░░░░░░░░░░█▄█░░▄▀

░░░█░░░░░░░░░░░████▀

░░░▀█▄▄▄▀▀▀▀▄▄▄█▀*/

int n;

vector<int>v;

int res[100001];

//<FUNCTIONS>

ll solve(int idx = 0) {

	ll res1, res2;

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

	if (~(res[idx]))return res[idx];

	res1 = 1e18;

	if (idx + 2 < n)res1 = solve(idx + 2) + abs(v[idx] - v[idx+2]);

	res2 = solve(idx + 1) + abs(v[idx] - v[idx+1]);

	return res[idx] = min(res1, res2);

}

//</FUNCTIONS>		

int main() {

	Fast();

	cin >> n;

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

		res[i] = -1;

	v.resize(n);

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

	cout << solve()<<endl;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

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

#include <algorithm>

#include <climits>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <iostream>

#include <math.h>

using namespace __gnu_pbds;

using namespace std;

#define ll long long

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> pbds;

#define vll vector<ll> 

#define nl cout << endl

#define fr(a,b) for(auto i=a;i<b;i++)

#define pll pair<ll,ll>

#define f first

#define s second

#define vpll vector<pll>

#define ump unordered_map

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

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

#define IN(a,b) ((a).find(b)!=(a).end())

#define pb push_back

#define mkp make_pair

#define PI M_PI

#define INF 1e18

#define deb(x) if(ON) cout << #x <<" : " << x << endl

#define fast ios_base::sync_with_stdio(false)

#define io cin.tie(NULL),cout.tie(NULL)

#define ON !false

ll dx[]={0,-1,0,1};

ll dy[]={1,0,-1,0};

const ll mod=1e9+7;

ll i,j;

ll add(ll a,ll b){

    return  ((a%mod)+(b%mod)+mod)%mod;

}

ll mul(ll a,ll b){

    return ((a%mod)*(b%mod)+mod)%mod;

}

void pause(ll id){

    cout << "Waiting " << id << endl;

    cin >> id;

}



const int mxn=1e5+10;

ll n,t;





signed main(){

    fast;

    io;

    if(!true){

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

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

    }



    cin >> n;

    ll h[n];

    vll ans(n,0);

    ll i,j;

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

        cin >> h[i];

    }

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

        ll mn=abs(h[i]-h[i-1])+ans[i-1];

        if(i>=2){

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

        }

        ans[i]+=mn;

    }

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

   

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

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

using namespace std;

int n; vector<int>v;

long long dp[100005];

long long solve(int i) {

	if (i >= n)return 1e18;

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

	if (i == n-3)return abs(v[i]-v[n-1]);

	long long& ret = dp[i];

	if (ret!=2e9)return ret;

	ret=min(solve(i + 1) + abs(v[i] - v[i + 1]),solve(i + 2) + abs(v[i] - v[i + 2]));

	return ret;

}

int main() {

	cin >> n; v.resize(n); 

	for (auto& t : v)cin >> t;

	fill(dp, dp + n, 2e9);

	cout << solve(0);

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#pragma comment(linker,"/STACK:102400000,102400000")

#define _USE_MATH_DEFINES

#include <iostream>

#include <cstdio>

#include <algorithm>

#include <vector>

#include <string>

#include <cstring>

#include <cctype>

#include <climits>

#include <cmath>

#include <set>

#include <map>

#include <sstream>

#include <queue>

#include <stack>

#include <bitset>

using namespace std;

const int N=2e5+10;

int arr[N],dp[N]; 

int main(){

	int n;

	scanf("%d",&n);

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

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

	}

	dp[n-1]=0;

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

		if(i==n-2){

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

		}

		else{

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

		}

	}

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

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include<bits/stdc++.h>

using namespace std;



int n;

int a[100004];

int dp[100004];



int main()

{

    cin>>n;

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

        cin>>a[i];

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



    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

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

#define endl '\n'

using namespace std;

typedef long long ll;

const int c=1e6;

const ll mod=1e9+7;

vector<pair<ll,ll> >v;

map<pair<ll,ll> ,bool>visited;

set<ll>s[10];

bool p[1000];

void sieve(){

p[0]=p[1]=1;

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

    for(int j=i*i;j<=100;j+=i){

        p[j]=1;

    }

}

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    ll n,x;

    cin>>n;

    ll arr[n+5];

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

        cin>>arr[i];

    }

    ll dp[n+5];

    ll ans=1e16,a,b;

    dp[1]=0;

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

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

            a=abs(arr[i-1]-arr[i]);

    b=abs(arr[i-2]-arr[i]);

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

    }

    cout<<dp[n];

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

using namespace std;

const int maxn=100005;

int cost[maxn],dp[maxn];

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

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

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

    }

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

    return 0;

}

// Fastest known solution for this problem: