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



#define F first

#define S second

#define PB push_back



using namespace std;



typedef long long LL;

typedef pair<int, int> PII;

typedef priority_queue<int> HEAP;

typedef priority_queue<int, vector<int>, greater<int> > RHEAP;



const int N = 300010, M = 2 * N;



int n, m, st, ed;

int h[N], e[M], ne[M], idx;

int q[N], d[N];



void add(int a, int b)

{

	e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;

}



int bfs(int st, int ed)

{

	memset(d, -1, sizeof d);

	int hh = 0, tt = -1;

	d[st * 3] = 0;

	q[ ++ tt] = st * 3;

	

	while (hh <= tt)

	{

		int t = q[hh ++ ];

		

		for (int i = h[t]; ~i; i = ne[i])

		{

			int j = e[i];

			if (d[j] != -1) continue;

			

			d[j] = d[t] + 1;

			q[ ++ tt] = j;

			

			if (j == ed * 3) break;

		}

	}

	

	int t = d[ed * 3];

	if (t % 3) return -1;

	else return t / 3;

}



int main()

{

	memset(h, -1, sizeof h);

	

	scanf("%d%d", &n, &m);

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

	{

		int a, b;

		scanf("%d%d", &a, &b);

		

		add(a * 3, b * 3 + 1);

		add(a * 3 + 1, b * 3 + 2);

		add(a * 3 + 2, b * 3);

	}

	

	scanf("%d%d", &st, &ed);

	cout << bfs(st, ed) << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



#define F first

#define S second

#define PB push_back



using namespace std;



typedef long long LL;

typedef pair<int, int> PII;

typedef priority_queue<int> HEAP;

typedef priority_queue<int, vector<int>, greater<int> > RHEAP;



const int N = 300010, M = 2 * N;



int n, m;

int h[N], ne[M], e[M], idx;

int q[M], d[N];



void add(int a, int b)

{

	e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;

}



int bfs(int st, int ed)

{

	int hh = 0, tt = -1;

	q[ ++ tt] = st;

	

	while (hh <= tt)

	{

		int t = q[hh ++ ];

		

		for (int i = h[t]; ~i; i = ne[i])

		{

			int j = e[i];

			if (d[j]) continue;

			

			q[ ++ tt] = j;

			d[j] = d[t] + 1;

		}

	}

	

	if (d[ed]) return d[ed] / 3;

	else return -1;

}



int main()

{

	memset(h, -1, sizeof h);

	

	scanf("%d%d", &n, &m);

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

	{

		int a, b;

		scanf("%d%d", &a, &b);

		add(3 * a, 3 * b + 1);

		add(3 * a + 1, 3 * b + 2);

		add(3 * a + 2, 3 * b);

	}

	

	int st, ed;

	scanf("%d%d", &st, &ed);

	printf("%d\n", bfs(3 * st, 3 * ed));

	return 0;

}

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

using namespace std;

#define endl '\n'

#define mem0(s) memset(s,0,sizeof(s))

#define meminf(s) memset(s,0x3f,sizeof(s))

#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))

typedef long long ll;

typedef unsigned long long ull;

const int INF=0x3f3f3f3f,max_n=100005;

inline ll lowbit(ll x){return x&(-x);}

inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

inline ll min(ll a,ll b){return a<b?a:b;}

inline ll max(ll a,ll b){return a>b?a:b;}

double r,pi=acos(-1);

long long a,b,x;

int main()

{

	std::ios::sync_with_stdio(false);

	std::cin.tie(nullptr);

	cin>>a>>b;

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

	{

		cin>>x;

		a-=x;

	}

	if(a<0)

	{

		cout<<"-1";

	}

	else cout<<a;

	return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

    int N,M,A[10007],i,sum=0,r;

    scanf("%d%d",&N,&M);

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

    {

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

        sum=sum+A[i];





    }

    if(N>=sum)

    {

        r=N-sum;

    }

    else r=-1;

    printf("%d",r);





}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream> //AA06( 19/ 04/ 20) If u see my code, Have a Good Day! (^_^)



using namespace std;



int main()

{

    int N, M, i, sum = 0, A;



    cin >> N >> M;





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

        cin >> A;



        sum = sum + A;



    }



    if(sum > N) {

        cout << -1 << endl;

    }



    else {

        cout << N - sum << endl;

    }





    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

    int N,M,A[10007],i,sum=0,r;

    scanf("%d%d",&N,&M);

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

    {

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

        sum=sum+A[i];





    }

    if(N>=sum)

    {

        r=N-sum;

    }

    else r=-1;

    printf("%d",r);





}




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

using namespace std;

main(){

	int n,m;

	cin>>n>>m;

	int i=0;

	int a[100000]={};

	int ans=0;

	while(m--){

		cin>>a[i];

		ans+=a[i];

		i++;

	}

	if(ans>n)cout<<"-1";

	else {

		cout<<n-ans;

	}

}

// Optimized solution to the same problem (faster):


#include <iostream>

#include <bits/stdc++.h>

#include<vector>

#include<queue>



using namespace std;



int main()

{

    int n,m,a;

    long long sum=0,x;

    cin>> n >> m;

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

    {

        cin>>a;

        sum +=a;

    }

   x=n-sum;

   if(x < 0)

        cout << -1;

   else

    cout<< x;

  

    

	return 0;

}

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

using namespace std;



int main()

{

    int n,m,i,total = 0,x;

    cin >> n >> m;

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

    {

        cin >> x;

        total += x;

    }



    n >= total ? cout << n - total : cout << "-1";

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main()

{

    int i,n,m,a;

    int s=0;

    scanf("%d%d",&n,&m);

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

        scanf("%d",&a);

        s+=a;

    }

    if(n-s>=0) { printf("%d\n",n-s); }

    else { printf("-1\n"); }



    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define GODSPEED ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

#define pb push_back

#define f(i,x,n) for(i=x;i<n;i++)

#define rf(i,x,n) for(i=n;i>x;i--)

#define ll long long

#define GCD(a,b) __gcd(a,b)

#define adios return 0;



/*

SHERAJUL ARIFIN

Dept. of CSE,

IUT.

*/





#include <bits/stdc++.h>

using namespace std;



int main()

{

    GODSPEED;

    ll t,n,a,b,c,d,s=0,i,j,flag;

    cin>>t>>n;

    while(n--)

    {

        cin>>a;

        s+=a;

    }

    if(s>t) cout<<"-1\n";

    else cout<<t-s<<endl;









    adios;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main()

{

    int i,n,m,a;

    int s=0;

    scanf("%d%d",&n,&m);

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

        scanf("%d",&a);

        s+=a;

    }

    if(n-s>=0) { printf("%d\n",n-s); }

    else { printf("-1\n"); }



    return 0;

}

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

using namespace std;

typedef long long ll;

int main()

{

	int n,m,x;

	cin>>n>>m;

	while(m--)

	{

		cin>>x;

		n-=x;

	}

	if(n<0)	cout<<"-1"<<endl;

	else	cout<<n<<endl;

 } 

// Optimized solution to the same problem (faster):
#include <stdio.h>



int main()

{

    int i,n,m,a;

    int s=0;

    scanf("%d%d",&n,&m);

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

        scanf("%d",&a);

        s+=a;

    }

    if(n-s>=0) { printf("%d\n",n-s); }

    else { printf("-1\n"); }



    return 0;

}

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

#include<cstdio>

using namespace std;



int main(){

    int n, m, a, sum=0;

    scanf("%d%d", &n, &m);

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

        scanf("%d", &a);

        sum+=a;

    }

    if(sum>n)

        printf("-1\n");

    else

        printf("%d\n", n-sum);

     return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main()

{

    int i,n,m,a;

    int s=0;

    scanf("%d%d",&n,&m);

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

        scanf("%d",&a);

        s+=a;

    }

    if(n-s>=0) { printf("%d\n",n-s); }

    else { printf("-1\n"); }



    return 0;

}

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

#define ll long long

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

using namespace std;

const int N = 1e5+5, M=5e5+5, oo=0x3f3f3f3f, mod = 1e9+7;



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

int solve(ll ind){

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

    if(mem[ind] != -1) return mem[ind];

    ll op1 = abs(arr[ind+1]-arr[ind]) + solve(ind+1);

    ll op2 = (ind+2 < n) ? abs(arr[ind+2]-arr[ind])+solve(ind+2) : oo;

    return mem[ind] = min(op1, op2);



}

int main()

{

    _69e27

    memset(mem, -1, sizeof mem);

    cin >> n;

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

        cin >> arr[i];

    cout << solve(0);



    return 0;

}




// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define ll long long

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

using namespace std;

const int N = 1e5+5, M=1e5+5, oo=0x3f3f3f3f, mod = 1e9+7;



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

int main()

{

    _69e27

    memset(dp, oo, sizeof dp);

    dp[0] = 0;

    cin >> n;

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

        cin >> arr[i];

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

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

            if(j < n)

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

        }

    }

    cout << dp[n-1];

    return 0;

}


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

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

using namespace std;

using ll = long long;

using P = pair<int,int>;





int INF = 1001001001;

int n;

vector<int> h(100010);

vector<int> dp(100010);



template<class T> inline bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }



    return false;

}





int rec(int i) {

    if (dp[i] < INF) return dp[i];

    if (i == 0) return 0;

    int res = INF;

    chmin(res, rec(i-1) + abs(h[i]-h[i-1]));

    if (i > 1) chmin(res, rec(i-2) + abs(h[i]-h[i-2]));



    return dp[i] = res; 

}



int main() {

    int n;

    cin >> n;

    rep(i,n) cin >> h[i];



    rep(i,n) dp[i] = INF;



    cout << rec(n-1) << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

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

using namespace std;

using ll = long long;

using P = pair<int,int>;



int INF = 1001001001;



template<class T> inline bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}



int main() {

    int n;

    cin >> n;

    vector<int> h(n);

    rep(i,n) cin >> h[i];

    vector<int> dp(n);

    rep(i,n) dp[i] = INF;

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

        if (i == 0) {

            dp[0] = 0;

            continue;

        }

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

        if (i > 1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));



    }

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

    return 0;

}

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

using namespace std;

int dif(int a, int b)

{

    int ans=a-b;

    if(ans<0) ans*=-1;

    return ans;

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int N, h[100005],i,j;

    int f1,f2;

    cin>>N;

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

        cin>>h[i];

    int M[100005]={0};

    M[N-2]=dif(h[N-1],h[N-2]);

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

    {

        f1=dif(h[i+1],h[i])+M[i+1];

        f2=dif(h[i+2],h[i])+M[i+2];

        M[i]=min(f1,f2);

    }

    cout<<M[0]<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#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;

}

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

using namespace std;

int n;

int h[1000005], memo[1000005];

int f(int n) {

    if(n == 1) {                        // bisa juga base case nya n = 0, f(0) harus tinggi, misal 1e9;

        return 0;

    }

    if(n == 2) {

        return abs(h[1] - h[2]);

    } 

    else if(memo[n] != -1) {

        return memo[n];

    }

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

    return memo[n];

}



int main() {

    scanf("%d", &n);

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

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

    }

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

    f(n);

    printf("%d\n", f(n));

}

// Optimized solution to the same problem (faster):
#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;

}

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

using namespace std;



typedef signed long long ll;

const int MX = 1e5 + 5;

const int INF = 1e9 + 5;

int n, A[MX], dp[MX];



int solve(int pos) {

    if(pos > n) return INF;

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

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

    int ans = INF;

    if(pos + 1 < n) ans = min(ans, abs(A[pos] - A[pos + 1]) + solve(pos + 1));

    if(pos + 2 < n) ans = min(ans, abs(A[pos] - A[pos + 2]) + solve(pos + 2));

    return dp[pos] = ans;

}



int main() {

    scanf("%d", &n);



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

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

    }

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

    printf("%d\n", solve(0));

    return 0;

}

// Optimized solution to the same problem (faster):
#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;

}

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

#include<cmath>

#include<algorithm>

#include<cstring>

using namespace std;



int h[100055],dp[100055];

const int inf = 0x3f3f3f;

int main()

{

	int n;

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

	cin>>n;

	h[1]=inf;

	h[0]=inf;

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

		cin>>h[i];

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

	return 0;

} 

//max(h[i],h[i-2])-min(h[i],h[i-2])

// Optimized solution to the same problem (faster):
#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;

}

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

using namespace std;

#define IO ios::sync_with_stdio(false), cin.tie(0)

typedef long long ll;

const int maxn = 1e6 + 5;

const int inf = 0x3f3f3f3f;

ll a[maxn];

ll dp[maxn];



int main()

{

    IO;

    int n, k=2;

    cin >> n ;

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

        cin >> a[i];

    memset(dp, inf, sizeof(dp));

    dp[1] = 0;

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

    {

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

        {

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

        }

    }

    cout << dp[n] << endl;

}


// Optimized solution to the same problem (faster):
#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;

}

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

using namespace std;

const int nax = 1e5+3;

int number;

int dyn[nax];

int a[nax];

int op1(int i){

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

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

	int res = abs(a[i]-a[i+1])+op1(i+1);

	if(i!=number-2) res = min(res, abs(a[i]-a[i+2])+op1(i+2));

	return dyn[i]=res;

}

int main(){

	cin>>number;

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

	memset(dyn, -1, sizeof dyn);

	cout<<op1(0)<<endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#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;

}

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

using namespace std;

int n, arr[100005], best, memo[100005];



int dp(int x){

	if(x==1 || x == 0){

		return 0;

	}

	if (x == 2){

		return abs(arr[x] - arr[x-1]);

	}

	if (memo[x] != -1){

		return memo[x];

	}

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

	memo[x] = best;

	return best;

}



int main(){

	ios_base::sync_with_stdio(0);

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

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	cout << dp(n) << endl;

}

// Optimized solution to the same problem (faster):
#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;

}

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

using namespace std;

int n, arr[100005], best, memo[100005];



int dp(int x){

	if(x==0 or x==1){

		return 0;

	}

	else if(x==2){

		return dp(x-1)+abs(arr[x]-arr[x-1]);

	}

	else if(memo[x]!=-1){

		return memo[x];

	}

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

	memo[x]=best;

	return best;

}



int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

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

	cin >> n;

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

		cin >> arr[i];

	}

	cout << dp(n) << endl;

}


// Optimized solution to the same problem (faster):
#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;

}

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

#include<string.h>

#include<time.h>

#include<math.h>

#include<stdlib.h>

#include<iostream>

#include<iomanip>

#include<utility>

#include<algorithm>

#include<stack>

#include<queue>

#include<map>

#include<set>

#define ll long long

#define fi first

#define sec second

#define pb push_back

#define mp make_pair

#define rep(a,b,c) for(int a=1;a<=b;a+=c)

#define repp(a,b,c,d) for(int a=b;a<=c;a+=d)



const double PI=acos(-1);

const double EPS=1e-12;

const int MOD=1e9+7;

const int INF=1<<30;





using namespace std;



int dat[100005];

int minn[100005];



int main(){

	int in;

	cin>>in;

	rep(i,in,1){

		cin>>dat[i];

	}

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

		if(i==in-1){

			minn[i]+=abs(dat[i]-dat[i+1]);

		}

		else{

			minn[i]+=min(abs(dat[i]-dat[i+1])+minn[i+1],abs(dat[i]-dat[i+2])+minn[i+2]);

		}

	}

	cout<<minn[1]<<endl;	

	return 0;

}

// Optimized solution to the same problem (faster):
#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;

}

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

#define ll long long

using namespace std;



int main(){

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

    cin >> n ;

    k=2;

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

    dp[n]=0;

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

        ll z=1e15;

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

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

        }

        dp[i]=z;

    }

    cout << dp[1] << endl;

}




// Optimized solution to the same problem (faster):
#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;

}

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

using namespace std;



int main(){

	long long a[100000], b[100000], n;

	scanf("%lld", &n);

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

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

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

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

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

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

	}

	printf("%lld", b[n-1]);

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem: