stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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; 

}

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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

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

}                               

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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

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

	}



}


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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

}
// Slower C++ solution:


/**

    And in the end, the love you take is equal to the love you make.



        I LOVE YOU LAURA.

**/



#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/rope>



#define _CRT_SECURE_NO_DEPRECATE

#define _CRT_DISABLE_PERFCRIT_LOCKS



#define findOrder find_by_order

#define orderKey order_of_key



#define isOn(mask, i) (mask & (1 << i))

#define turn(mask, i) (mask |= (1 << i))

#define switch(mask, i) (mask &= ~(1 << i))

#define change(mask, i) (mask ^= (1 << i))

#define lowbit(mask) (mask & (-mask))

#define turnAll(mask, n) (mask = (1 << n) - 1)

#define switchLastBit(mask) (mask & (mask - 1))

#define turnLastZero(mask) (mask | (mask + 1))

#define modulo(x, mod) ((x) & (mod - 1))

#define log2(x) (31 - __builtin_clz(x))



#define mkp make_pair

#define pb push_back

#define pf push_front

#define eb emplace_back

#define ef emplace_front

#define ins insert

#define rsz resize

#define f first

#define s second

#define lb lower_bound

#define ub upper_bound



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

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

#define rall(x) rbegin(x), rend(x)



#define debug(x) (cerr << x << " ")



using namespace std;

using namespace __gnu_pbds;

using namespace __gnu_cxx;



typedef double db;

typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;



typedef pair<int, int> ii;

typedef pair<ll,ll> pll;

typedef pair<ld,ld> pdb;

typedef pair<int, ii> tri;

typedef complex<ld> cd;



typedef vector<int> vi;

typedef vector<ii> vii;

typedef vector<ld> vdb;

typedef vector<cd> vcd;

typedef vector<ll> vll;

typedef vector<string> vs;

typedef vector<vll> matrix;



typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_tree;



const ll mod = 1e9+7;

const int maxn = 2e5+2;

const int pi = 2 * acos(0.0);

const db eps = 1e-9;



ll arr[maxn], dp[maxn];



int main()

{

    ios_base::sync_with_stdio(0);

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



    int n; cin >> n;



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

        cin >> arr[i];

    }



    memset(dp, 63, sizeof dp);



    dp[1] = 0;

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

        if (i <= 2){

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

        }

        else{

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

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

        }

    }



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



    return 0;

}


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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

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

}

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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

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

}

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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

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

}

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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

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

}

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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

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

}

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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

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

} 

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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

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

}

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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

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

}


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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

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

}

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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

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

}

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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

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

using namespace std;

#define ll long long int

#define dbl double

#define pi acos(-1)

#define sc1(a) scanf("%lld",&a)

#define sc2(a,b) scanf("%lld%lld",&a,&b)

#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)

#define pb push_back



ll ara[1000005];



map<ll,ll>vis;

map<ll,ll>vis1;

map<ll,ll>pos;

map<ll,ll>high;

map<ll,ll>low;

map<string,ll>mp;

vector<ll>vec;

vector<ll>v;

stack<ll>q;

string str1[100];

string str2[100];

priority_queue<ll>pq;

ll dp[1000005],t;

ll mn=1000000;

ll call(ll id)

{

    if(id==t )return 0;

    if(dp[id]!=-1)

        return dp[id];

    ll p=call(id+1)+abs(ara[id+1]-ara[id]);

    ll q=100000000;

    if(id+2!=t+1)

        q=call(id+2)+abs(ara[id+2]-ara[id]);

    dp[id]=min(p,q);

    return dp[id];



}

int main()

{



    // ll t;

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

    sc1(t);

    for(ll i=1; i<=t; i++)

    {

        sc1(ara[i]);

    }

    cout<<call(1)<<endl;

    return 0;

}


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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

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

}


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

#include <cstdlib>

#include <algorithm>



using namespace std;



int main() {

    int n;

    scanf("%d", &n);



    int height[100005];

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

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

    }



    int dp[100005];

    dp[0] = 0;

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



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

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

    }

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

    return EXIT_SUCCESS;

}