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



#define Solved int main()

#define pb push_back

#define mp make_pair

#define F first

#define S second

#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

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

#define rep(i, x, y) for(int i = x; i <= y; i++)

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

#define pii pair<int, int>

#define ll long long

#define ull unsigned long long

#define ld long double

#define mii map<int, int>

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

using namespace std;



inline ll bip(ll x,ll n,ll mod){ll res=1;while(n){if(n&1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}



const int maxn = 1e9;

const ll inf = 1e18;

const int mod = 998244353;

//const int mod = 1e9 + 7;

const int N = 1e5 + 10;



int n;

ll a[N];

ll dp[N];



void solve() {

    cin >> n;



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

        cin >> a[i];



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

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

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

    }

    cout << dp[n];

}



Solved {

    SpeedForce;

	int tt = 1;

    //cin >> tt;

	while (tt--) {

		solve();

		cout << '\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):
#include <bits/stdc++.h>

using namespace std ; 

#define ll long long

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

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

int main()

{	ios ; 

	ll n ; 

	cin>>n ; 

	int a[n] ; 

	flp(i,0,n)

	{

		cin>>a[i] ; 

	}

	int dp[n] ;

	dp[0] = 0  ; 

	flp(i,1 , n)

	{

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

		if(i>1)

		{

			dp[i] =min(dp[i] ,dp[i-2] + abs(a[i]-a[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):
#include <bits/stdc++.h>

 

using namespace std;

 



int main(){

    int n; cin >> n;

    vector<int> h(n);

 

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

        cin >> h[i];

    }

 

    //dp[i] gives the minimum possible cost to reach ith stone

    //Initialize dp[i] with infinity for all i

    vector<int> dp(n, INT_MAX);

    

    //Base Cases

    //To reach 0th stone we dont need to jump from any cells so total cost is 0

    //To reach 1st stone we can jump from 0th cell with total cost = abs(h[1] - h[0])

    dp[0] = 0;

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

 

    //Iterate from 2 to (n -1)th stone in a bottom up manner

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

       

       //ith stone can be reached either from (i - 1)th stone or (i - 2)th stone

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

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

    }

    

    //Print cost to reach (n -1)th stone

    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>

/**

*   author: j o s e m a g o

*   date:

**/

using namespace std;

#pragma GCC optimize ("Ofast")

#define f first

#define s second

#define mp make_pair

#define lb lower_bound

#define ub upper_bound

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

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

#define pb push_back

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

#define rsz resize

#define ln "\n"



typedef double db;

typedef unsigned long long ull;

typedef long long ll;

typedef long double ld;

const ld PI = 2*acos(0.0);

const int MOD = 1000000007;

const int JJJ = 100009;









int main(){



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

  //freopen("input.out","w",stdout);



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



    int N;

    cin >> N;

    vector<int>h(N);

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

        cin >> h[i];

    }

    vector<int>dp(N,INT_MAX);

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















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

#include<string.h>

#include<algorithm>

using namespace std;

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

int xg(int a){

	if(a>0)

		return a;

	return -a;

}

int main(){

	cin>>n;

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

		cin>>dp[i];

	}

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

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

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

	cout<<a[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;

#define ll long long

#define ull unsigned long long

#define mst(a, b) memset((a), (b), sizeof(a))

#define mp(a, b) make_pair(a, b)

#define pi acos(-1)

#define pii pair<int, int>

#define pb push_back

const int INF = 0x3f3f3f3f;

const double eps = 1e-10;

const int maxn = 1e5 + 7;

const int maxm = 5e5 + 10;

int s[maxn];

ll dp[maxn][2];

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 >> s[i];

    dp[1][0] = dp[1][1] = 0;

    dp[0][0] = dp[0][1] = 0;

    dp[2][0] = dp[2][1] = abs(s[2] - s[1]);

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

    {

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

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

    }

    ll ans = min(dp[n][0], dp[n][1]);

    cout << ans << 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=2e5+5;

int a[N],dp[N];

int main(){

	int n;

	cin>>n;

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

		cin>>a[i];

	dp[1]=0;

    dp[0]=0;

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

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

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

	cout<<dp[n];

	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;

typedef long long ll;

const int N=1e5+10;

ll a[N],dp[N]={0};

int main()

{

	int n,i;

	scanf("%d",&n);

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

	{

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

	} 

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

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

	{

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

	}

	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>

using namespace std;

const int maxn=1e5+5;

int dp[maxn];

int h[maxn];

int path[maxn];

int main()

{

   int n;

   cin>>n;

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

       cin>>h[i];

   }

   dp[1]=0;

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

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

       if(dp[i-1]+abs(h[i]-h[i-1])>dp[i-2]+abs(h[i]-h[i-2])){

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

       }

       else{

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

       }

   }

   cout<<dp[n]<<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>

#include <algorithm>

#include <string>

#include <cmath>

#include <cstring>

#include <iomanip>



using namespace std;

typedef long long ll;

const int maxn=1e5+1111;



int arr[maxn];

int dp[maxn];

int main(){

    int n,k;

    scanf("%d",&n);

    k=2;

    dp[0]=dp[1]=0;

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

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

        if(i>1) dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);

        for(int j=2;j<=k&&i-j>0;++j){

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

        }

    }

    printf("%d\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<bits/stdc++.h>



#define endl '\n'

#define int long long int



using namespace std;

     

int gcd(int a, int b)

{

        return b == 0 ? a : gcd(b, a%b);

}

int lcm(int a, int b)

{

        return (a*b)/gcd(a,b);

}

int ncr(int n, int k)

{

        int res = 1;

        if ( k > n - k )

            k = n - k;

     

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

        {

            res *= (n - i);

            res /= (i + 1);

        }

        return res;

}



map<int, int> dpArr;



int dp(int arr[],int n)

{

        if(n<=1)

        {

            if( n == 0) return dpArr[0];

            return dpArr[1];

        }

        if(dpArr.count(n)){

            return dpArr[n];

        }

        dpArr[n] =  dp(arr,n-1) + abs(arr[n-1] - arr[n]);

        if(n > 1) dpArr[n] = min(dpArr[n], dp(arr, n-2)+ abs(arr[n-2] - arr[n]));

        return dpArr[n];

}

     

signed main()

{

        int n;

        cin >> n;

        int arr[n];

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

            cin >> arr[i];

        }

        dpArr[0] = 0;

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

        cout << dp(arr,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>

using namespace std;



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



int main()

{

    cin>>n;

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

    {

        cin>>h[i];

    }

    dp[1]=0;

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

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

}


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

#define MAXN 100010

#define INF 1000000010



using namespace std;



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



void init(){

    for(int i=1; i<=n; i++) dp[i]=INF;

    dp[1]=0;

    h[0]=INF;

}



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



    init();



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



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;

#define endl '\n'



const int N = 1e5;



int dp[N+5];

int arr[N+5];



int main(){



	ios_base::sync_with_stdio(0);

	int n; cin >>n;

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

	

	dp[0] = dp[1] = 0; arr[0] = arr[1];

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

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

	}

	

	cout <<dp[n] <<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>

    #define maxn 100000

    #define INF 1LL<<60

    using namespace std;

    long long h[maxn+3], dp[maxn+3];

    int n;



    long long solve(int cur){

        if(cur >= n) return INF;

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

        if(dp[cur]!= INF) return dp[cur];

        //long long res1 = INF, res2 = INF;

        long long res1 = solve(cur+1) + llabs(h[cur+1]-h[cur]);

        long long res2 = solve(cur+2) + llabs(h[cur+2]-h[cur]);

        return dp[cur] = min(res1, res2); 

    }



    int main() {

    	// your code goes here

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

    	while(scanf("%d",&n)==1){

            

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

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

                dp[i] = INF;

            }



            long long ans = solve(0);

            printf("%lld\n", ans);

        }

    }

     

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

     

    void __print(int x) {

        cerr << x;

    }

    void __print(long x) {

       cerr << x;

    }

    void __print(long long x) {

       cerr << x;

    }

    void __print(unsigned x) {

        cerr << x;

    }

    void __print(unsigned long x) {

        cerr << x;

    }

    void __print(unsigned long long x) {

        cerr << x;

    }

    void __print(float x) {

        cerr << x;

    }

    void __print(double x) {

        cerr << x;

    }

    void __print(long double x) {

        cerr << x;

    }

    void __print(char x) {

        cerr << '\'' << x << '\'';

    }

    void __print(const char *x) {

        cerr << '\"' << x << '\"';

    }

    void __print(const string &x) {

        cerr << '\"' << x << '\"';

    }

    void __print(bool x) {

        cerr << (x ? "true" : "false");

    }

     

    template<typename T, typename V>

    void __print(const pair<T, V> &x) {

        cerr << '{'; 

        __print(x.first); cerr << ','; 

       __print(x.second); cerr << '}';

    }

    template<typename T>

    void __print(const T &x) {

        int f = 0; cerr << '{'; 

        for (auto &i: x) 

            cerr << (f++ ? "," : ""), __print(i); 

        cerr << "}";

    }

    void _print() {

        cerr << "]\n";

    }

    template <typename T, typename... V>

    void _print(T t, V... v) {

        __print(t); 

        if (sizeof...(v)) 

            cerr << ", "; _print(v...);

    }

     

    #ifndef ONLINE_JUDGE

    #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

    #else

    #define debug(x...)

    #endif

     

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

    #define forw(i, w) for(int i = n; i >= 0; i--)

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

    #define dforw(i, b, a) for(int i = b; i >= a; i--)

    #define read(v) for(auto &i:v) cin >> i;

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

     

    typedef long long ll;

    typedef vector<int> vi;

    typedef vector<double> vd;

    typedef pair<int, int> pii;

     

    int n, k;

    vi arr, dp;

     

    int main(){

    	ios_base::sync_with_stdio(0);

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

    	

    	cin >> n;

    	k=2;

    	arr.assign(n, 0);

    	dp.assign(n, 999999999);

    	dp[0] = 0;

    	read(arr);

     

    	forn(i, n)

    		for(int j = i+1; j < n && j < i+k+1; j++)

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

     

    	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>

#include <fstream>

#define inf INFINITY

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

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

#define _3102_ main()

#define endl '\n'

typedef long long ll ;

typedef unsigned long long ull ; 

typedef long double ld ; 

using namespace std ;

const int N = 1e5+100  ; 

const ll mod = 1e9 + 7  ;







int _3102_ {

    Gamed

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

    cin >> n ; 

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

        cin >> arr[i] ; 

    }

    dp[0] = 0 ; 

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

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

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

    }

    cout << dp[--n] << 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: