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



using namespace std;

using ll = long long;



const int maxn = 1e5+10;

const int INF = 1e9+10;



vector<int> g[maxn];

int p[maxn][3];



void bfs(int x){

	queue<pair<int,int>> q;

	q.push({x,0});

	p[x][0] = 0;

	while(!q.empty()){

		int nxt = q.front().first;

		int moves = q.front().second;

		q.pop();

		for(int i=0;i<g[nxt].size();++i){

			int v = g[nxt][i];

			if(p[nxt][moves]+1 < p[v][(moves+1)%3]){

				p[v][(moves+1)%3] = p[nxt][moves]+1;

				q.push({v,(moves+1)%3});

			}

		}

	}

}



void init(){

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

		for(int j=0;j<3;++j)

			p[i][j] = INF;

}



void solve(){

	int n,m,s,t;

	init();

	cin >> n >> m;

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

		int u,v;

		cin >> u >> v;

		g[u].push_back(v);

	}

	cin >> s >> t;

	bfs(s);

	if(p[t][0] == INF){

		cout << -1 << '\n';

	}

	else{

		cout << p[t][0]/3 << '\n';

	}

}



int main(){

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	int t = 1;

	//cin >> t;

	while(t--){ 

		solve();

	}

	return 0;

}

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

#define ll long long

#define F first

#define S second

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

using namespace std;

const ll N = 1e5+50, inf = 1e3+5, mod = 1e9+7, NN = 1e5+10;

int vis[N][3] ;

vector < int > graph[N] ;

int n, m, t,s, u, v ;

int main()

{

    Tsetso

    cin >> n >> m ;

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

    {

        cin >> u >> v ;

        graph[u].push_back(v);

    }

    cin >> s >> t ;

    queue < int > q ;

    q.push(s);

    vis[s][0] = 1 ;

    int cnt = 1 ;

    while ( q.size())

    {

        int y = q.size() ;

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

        {

            for ( auto j : graph[q.front()])

            {

                if ( !vis[j][cnt%3])

                {

                    if ( cnt%3 == 0 && j == t )

                        return cout << cnt/3, 0 ;

                    q.push(j);

                    vis[j][cnt%3] = 1 ;

                }

            }

            q.pop();

        }

        cnt++ ;

    }

    cout << -1 ;

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

using namespace std;



typedef long long ll;

typedef pair<ll,ll> pi;

typedef vector <ll> vi;

typedef vector <pi> vpi;

#define f first

#define s second

#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)

#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)

#define pb push_back

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

#define lbd(x, y) lower_bound(all(x), y)

#define ubd(x, y) upper_bound(all(x), y)

#define aFOR(i,x) for (auto i: x)

#define mem(x,i) memset(x,i,sizeof x)

#define fast ios_base::sync_with_stdio(false),cin.tie(0)

#define maxn 100001



int N,M,S,T;

vi adj[maxn];

vpi adj2[maxn];

bool vis[maxn][3];

int dist[maxn][3];

vpi nodes[3];



int main(){

	fast;

	

	cin>>N>>M;

	

	FOR(i,0,M-1){

		int a,b; cin>>a>>b; adj[a].pb(b);

	}

	

	cin>>S>>T;

	



		

	queue <pi> q;

	q.push(pi(S,0));

		

	while (!q.empty()){

		pi cur = q.front(); q.pop();

			

		if (vis[cur.f][cur.s%3]) continue;

		vis[cur.f][cur.s%3] = 1;

		

		dist[cur.f][cur.s%3] = cur.s;

		aFOR(i,adj[cur.f]){

			q.push(pi(i,cur.s+1));

		}

	}

	

	if (vis[T][0] == 1) cout<<dist[T][0]/3;

	else cout<<-1;



		

}




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



#define MAX 100005



using namespace std;



int n, m, s, t;

vector<int> G[MAX];

int8_t mark[MAX];;



int bfs()

{

        queue<pair<int,int>> q;

        int ls = 0;

        int kkp = 0;

        q.emplace(s,0);



        while (!q.empty()) {

                auto curr = q.front();

                q.pop();

                if (curr.second != 3) {

                        kkp += (ls == 3);

                        ls = curr.second;



                        if ((mark[curr.first] & (1<<curr.second))) continue;

                        mark[curr.first] |= (1<<curr.second);

                        for (auto e : G[curr.first])

                                q.emplace(e, curr.second+1);

                } else {

                        if (curr.first == t) return kkp+1;

                        else if ((mark[curr.first] & (1<<curr.second))) continue;



                        mark[curr.first] |= (1<<curr.second);

                        ls = curr.second;

                        for (auto e : G[curr.first])

                                q.emplace(e, 1);

                }

        }

        return -1;

}



int main()

{

        cin >> n >> m;

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

                int u, v;

                cin >> u >> v;

                G[u].push_back(v);

        }

        cin >> s >> t;

        cout << bfs() << endl;

        return 0;

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

using namespace std;



typedef long long ll;

typedef pair<ll,ll> pi;

typedef vector <ll> vi;

typedef vector <pi> vpi;

#define f first

#define s second

#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)

#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)

#define pb push_back

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

#define lbd(x, y) lower_bound(all(x), y)

#define ubd(x, y) upper_bound(all(x), y)

#define aFOR(i,x) for (auto i: x)

#define mem(x,i) memset(x,i,sizeof x)

#define fast ios_base::sync_with_stdio(false),cin.tie(0)

#define maxn 100001



int N,M,S,T;

vi adj[maxn];

vpi adj2[maxn];

bool vis[maxn][3];

int dist[maxn][3];

vpi nodes[3];



int main(){

	fast;

	

	cin>>N>>M;

	

	FOR(i,0,M-1){

		int a,b; cin>>a>>b; adj[a].pb(b);

	}

	

	cin>>S>>T;

	



		

	queue <pi> q;

	q.push(pi(S,0));

		

	while (!q.empty()){

		pi cur = q.front(); q.pop();

			

		if (vis[cur.f][cur.s%3]) continue;

		vis[cur.f][cur.s%3] = 1;

		

		dist[cur.f][cur.s%3] = cur.s;

		aFOR(i,adj[cur.f]){

			q.push(pi(i,cur.s+1));

		}

	}

	

	if (vis[T][0] == 1) cout<<dist[T][0]/3;

	else cout<<-1;



		

}




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



#define ll long long

#define N (ll)(4*1e6)

#define EPS (double)(1e-12)

#define M (ll)(1e9+7)



using namespace std;



const ll maxN = 1e5+1;



vector<ll> adj[maxN];



void addEdge(ll u, ll v) {

    adj[u].push_back(v);

}

ll mat[maxN][4];



ll bfs(ll s, ll t) {

    queue<pair<ll, ll>> fila;



    // node / distance

    fila.push({s, 0});



    while(!fila.empty()) {

        int no = fila.front().first;

        int dist = fila.front().second;



        fila.pop();



        if(mat[no][dist%3])

            continue;

        mat[no][dist%3] = true;



        if(no == t && dist%3 == 0)

            return dist/3;

        

        for(auto a : adj[no])

            fila.push({a, dist+1});

    }

    return -1;

}



int main() {

    // 189 algorithm design manual

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll n, m, s, t, u, v;



    cin >> n >> m;



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

        cin >> u >> v;

        addEdge(u, v);

    }

    cin >> s >> t;



    cout << bfs(s, t) << endl;





    return 0;

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

}

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

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

}


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





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

}


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





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

	}

}

// Faster C++ solution for the same problem (measured speedup: 1.3987948264413166x):
#include <iostream>

#include <set>

#include <deque>

#include<string>

#include<algorithm>

using namespace std;



int main()

{

    int n, m, a, sum = 0;

    cin >> n >> m;

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

    {

        cin >> a;

        sum += a;

    }

    if (n >= sum)

        cout << n - sum;

    else

        cout << -1;

    return 0;

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

	}

}

// Faster C++ solution for the same problem (measured speedup: 1.3987948264413166x):
#include <iostream>

#include <bits/stdc++.h>



using namespace std;



int main()

{

    int vac, assig, days, sum = 0;



    cin >> vac >> assig;



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

    {

        cin >> days;

        sum += days;

    }



    if (sum <= vac)

        cout << (vac - sum);

    else

        cout << -1;



    return 0;

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

	}

}

// Faster C++ solution for the same problem (measured speedup: 1.3881152076611263x):
#include <iostream>





using namespace std;



int main()

{

	int n , m , sum = 0 , total;

	cin >> n >> m;

	int arr[100000];

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

		cin >> arr[i];

		sum += arr[i];

	}

	total = n - sum;

	if (sum <= n){

		cout << total;

	}

	else if (sum > n){

		cout << -1;

	}

	

	return 0;

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

	}

}

// Faster C++ solution for the same problem (measured speedup: 1.3993256746276617x):


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

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

}


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

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

}


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

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

 } 

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

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

}


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

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

}




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

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

}

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

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

}


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

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

}


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

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

}


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

}