stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):


#include <iostream>

#include <bits/stdc++.h>





using namespace std;





int a[100005], p[100005],n, i;

int respuesta(int x)

{

    if(x==n) return 0;

    if(x>n) return 1e9;

    if(p[x]!=-1)return p[x];

    return p[x]=min(abs(a[x+1]-a[x])+respuesta(x+1), abs(a[x+2]-a[x])+respuesta(x+2));

}





int main()

{

    memset(p,-1,sizeof p);

    cin>>n;

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

    {

        cin>>a[i];

    }

    cout<<respuesta(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;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

const int mod = 1e9+9;

//===========================================================//

const int nax = 1e5+3;

int n;

int dp[nax];

int a[nax];

int f(int i){

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

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

	int ans = abs(a[i]-a[i+1])+f(i+1);

	if(i!=n-2) ans = min(ans, abs(a[i]-a[i+2])+f(i+2));

	return dp[i]=ans;

}

int main(){

	cin>>n;

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

	memset(dp, -1, sizeof dp);

	cout<<f(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 <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

const int mod = 1e9+9;

/*ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }

*ll lcm(ll x, ll y){return x*(y/gcd(x,y));}

*void exEuclid(int a, int b){

	if(b==0){x = 1; y=0; d=a; return ;}

	exEuclid(b, a%b);

	int x1=y;

	int y1=x-(a/b)*y;

	x=x1;

	y=y1;

} 

* */

//===========================================================//

const int nax = 1e5+3;

int n;

int dp[nax];

int a[nax];

int f(int i){

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

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

	int ans = abs(a[i]-a[i+1])+f(i+1);

	if(i!=n-2) ans = min(ans, abs(a[i]-a[i+2])+f(i+2));

	return dp[i]=ans;

}

int main(){

	cin>>n;

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

	memset(dp, -1, sizeof dp);

	cout<<f(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<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll dp[100009];

int arr[100009];

ll sum = 0;

long long Frog1(int n){

 

    if(n==0) return 0;

    else if(n==1) return abs(arr[n] - arr[n-1]);

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

    else {

            ll x = Frog1(n-1);

            ll y = Frog1(n-2);

        dp[n] = min(abs (arr[n-1] - arr[n]) + x,abs(arr[n-2] - arr[n]) + y);

        //cout << n << " = " << dp[n] << endl;

         return dp[n];

    }

}

 

 

int main()

{

    int n;

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

    cin >> n;

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

    cout << Frog1(n-1) << 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;

#define ll long long

#define ld long double

#define sf scanf

#define pf printf

#define pb push_back

#define llu unsigned long long

#define U unsigned int

#define SIZE 1000002

#define pie 3.14159265358979323

#define minuss 1e-6

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

 

#define BIG 100000000

 

ll  lcm(ll a,ll b)

{

    ll GCD=__gcd(a,b);

    ll lcm=(a*b)/GCD;

    return lcm;

}

ll dp[100005];

ll weight[1000005],value[1000005];

ll total,val;

ll call(ll n)

{

    if(n>=total)

        return 0;

 

    if(dp[n]!=-1)

        return dp[n];

 

    ll res1=BIG,res2=BIG;

 

   // if(weight[n]+c<=val)

    res1=abs(weight[n]-weight[n+1]) + call(n+1);

    if(n+2<=total) res2=abs(weight[n]-weight[n+2]) + call(n+2);

    //cout<<n<<" "<<res1<<" "<<res2<<endl;

    dp[n]=min(res1,res2);

    return dp[n];

 

}

int main()

{

    cin>>total;

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

        cin>>weight[i];

 

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

    ll ret=call(1);

    cout<<ret<<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 num[100001], memo[100001];



int dp(int n){

    if(n==0) return 0;

    if(n==1) return abs(num[0]-num[1]);

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

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

}



int main(){

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

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

    ios_base::sync_with_stdio(0);

    cin.tie(0);

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

    int n;

    cin>>n;

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

    cout<<dp(n-1)<<"\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 n;

int h[100001];

int f[100001];



int main(){

	cin>>n;

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

		cin>>h[i];

	}

	f[1]=0;

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

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

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

	}

	cout<<f[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):
/*

	Author: Luis Manuel D�az Bar�n (LUISMO)

	Problem:

	Online Judge:

	Idea:

*/

#include<bits/stdc++.h>

// Types

#define ll long long

#define ull unsigned long long

// IO

#define sf scanf

#define pf printf

#define mkp make_pair

#define fi first

#define se second

#define endl "\n"



using namespace std;



typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const ll inf = 1e16 + 3;

const int mod = 1e9 + 7;

const int lim = 2e5 + 2;



int N;

ll hi[lim];



ll dp[lim];

int mark[lim];



ll DynamicProgramming(int idx)

{

    if(idx <= 0)

        return 0;



    if(mark[idx])

        return dp[idx];



    mark[idx] = true;



    DynamicProgramming(idx - 1);

    DynamicProgramming(idx - 2);



    ll k1 = dp[idx-1] + abs(hi[idx] - hi[idx-1]);

    ll k2 = (idx > 1) ? dp[idx-2] + abs(hi[idx] - hi[idx-2]) : inf;



    dp[idx] = min(k1, k2);

    return dp[idx];

}





void solve()

{

    cin >> N;

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

        cin >> hi[i];   



    ll answ = DynamicProgramming(N - 1);

    cout << answ;

}



void fastIO()

{

	cin.sync_with_stdio(false);

	cin.tie(0);

}



void IO()

{

	if(fopen("d:\\lmo.in","r") != NULL)

	{

		freopen("d:\\lmo.in","r",stdin);

	}

	else if(fopen("/media/Beijing/lmo.in","r") != NULL)

	{

		freopen("/media/Beijing/lmo.in", "r", stdin);

	}

}



int main()

{

	IO();



	fastIO();



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

#define ll long long

#define ull unsigned long long

using namespace std;

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

	

int main (){

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

	cin >> n;

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

		cin >> a[i];

	}

	for (int i=n; i>=1; i--){

		ll x,y;

		if (i<=n-2){

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

		}

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

	}

	cout << dp[1] << 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<stdio.h>



using namespace std;



int main(){

    int n, i, j;

    scanf("%d", &n);

    int height[n+5];

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

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

    }

    int dp[n+5];

    for(i = 0; i <=n; i++) dp[i] = 1e9;

    dp[1] = 0;

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

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

        if(i > 2) {

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

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

            }

        }

    }



    printf("%d", 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 <cstring>

#include <iostream>

#include <string>

#include <vector>

#include <cmath>

#include <algorithm>

#include <sstream>

#include <queue>

#include <deque>

#include <set>

#include <bitset>

#include <iterator>

#include <list>

#include <stack>

#include <map>

#include <set>

#include <functional>

#include <numeric>

#include <utility>



#include <cstdlib>  // for abs



#include <iomanip>



using namespace std;

int main()

{

  // Standard incantation to set up fast IO.

  ios::sync_with_stdio(false);

  cin.tie(0);



  int n;

  cin >> n;

  int cur, next;

  if (n <= 1) {

    cout << 0 << '\n';

    return 0;

  }

  int a, b, c;

  cin >> a >> b;

  cur = 0;

  next = abs(a - b);

  if (n == 2) {

    cout << next << '\n';

    return 0;

  }

  int ans;

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

    cin >> c;

    ans = min(cur + abs(c-a), next + abs(c-b));

    a = b;

    b = c;

    cur = next;

    next = ans;

  }

  cout << ans << '\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;



int main(){



        int n; cin >> n;

        vector<int> frog(n + 1, 0);

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

                cin >> frog[i];

        }



        vector<int> dp(n + 5, 0);

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



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

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

using namespace std;

long long n,h[100010],dp[100010];



int main()

{

	scanf("%lld",&n);

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

	{

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

	}

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

	{

	//	printf("%d %d %d %d\n",dp[i-1],dp[i-2],h[i-1]-h[i],h[i-2]-h[i]);

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

		if(i>2)

		{

			

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

		}

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

	}

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

#include<cmath>

#include<cstring>

#include<iostream>

#include<algorithm>



using namespace std;

const int MAX = 1e9;

const int MaxN = 1e5 + 5;



int n;

int h[MaxN], dp[MaxN];



int main()

{

	while (~scanf ("%d", &n)){

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

		for (int i = 1; i <= n; i++) scanf ("%d", &h[i]);

		dp[1] = 0;

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

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

			int h1 = fabs (h[i] - h[i - 1]);

			int h2 = fabs (h[i] - h[i - 2]);

			dp[i] = min (dp[i - 1] + h1, dp[i - 2] + h2);

		}

		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):
//by Top1

#include <bits/stdc++.h>

     

#define f first

#define s second

#define int long long

#define ld long double

#define ull unsigned long long

#define pii pair <int, int>

#define pll pair <long, long>

#define mp make_pair

#define pb push_back

#define pf push_front

#define pp pop_back

#define rev reverse

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

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

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

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

#define nxtp next_permutation

#define pvtp prev_permutation

#define KZ return 

#define x1 x21212121

#define y1 y21212121

#define sqr(x) x * x 

 

const int inf = INT_MAX;

const int mod = 1e9 + 7;

const int maxn = 6e5 + 111;

     

using namespace std;



int n, a[maxn], dp[maxn], t, q;



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



	cout << dp[n];

}



main(){

    boost;

	    

	q = 1;



	while (q--){

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

using namespace std;

#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'

const int N = 1e5;

int A[N+7], dp[N+7], n;

const int inf=1e9;



int solve(int i) {

	if(i==n) return 0;

	if(i>n) return inf;

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

	int a = solve(i+1) + abs(A[i]-A[i+1]);

	int b = solve(i+2) + abs(A[i]-A[i+2]);

	return dp[i] = min(a, b);

}

int main(){

	ios_base::sync_with_stdio(0);

	int a,b,T,cas=0;

	cin>>n;

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

	fill(dp, dp+n+1, -1);

	int res = solve(1);

	cout<<res<<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 <cstdio>

#include <cstring>

#include <cmath>

using namespace std;

int N;

int h[1000001],f[1000001];

int main () {

	cin>>N;

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

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

	}

	f[1]=0;

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

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

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

	}

	cout<<f[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>                  

#include <stdio.h>



#define f first

#define s second

#define pb push_back

#define ppb pop_back

#define mp make_pair



using namespace std;



typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;



const int N = 1e5 + 123, inf = 1e9 + 123, mod = 1e9 + 7;

const ll INF = 1e18;



int a[N], dp[N];



int main() {

	cin.tie(0);

	cout.tie(0);

	ios_base::sync_with_stdio(0);

	int n;

	cin >> n;

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

		cin >> a[i];

	}

	dp[1] = 0;

	a[0] = inf;

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

	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: