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



long long absdif(long long a, long long b){

	return ( a > b ) ? a-b: b-a;

}



int main(){

	int N;

	std::vector<long long> h, dp;

	std::cin >> N;

	h.resize(N);

	dp.resize(N+1);

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

		std::cin >> h[i];

	}



	dp[0] = 0;

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

		dp[i] = 1e9+9;

		if( i-1 >= 0 )

			dp[i] = std::min(dp[i], dp[i-1] + absdif(h[i], h[i-1]) );

		if( i-2 >= 0 )

			dp[i] = std::min(dp[i], dp[i-2] + absdif(h[i], h[i-2]) );

	}

	std::cout << dp[N-1] << '\n';

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

#include<iostream>

#include<algorithm>

#include<queue>

#define inf 0x3f3f3f3f

using namespace std;

typedef long long LL;

const int maxn = 1e5+5;



int a[maxn],dp[maxn];



int main(){

	int n;

	scanf("%d",&n);

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

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

	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-2] -a[i]));

	}

	printf("%d",dp[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;

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

const int N = 1e6;

const int inf = 1e9;



int main(){

	ios_base::sync_with_stdio(0);

	int a,b,n,T,cas=0;

	cin>>n;

	vector<int> A(n);

	for(int &x: A) {

		cin>>x;

	}

	vector<int> dp(n, inf);

	dp[0]=0;

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

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

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

		}

	}

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

using namespace std;

const int N = 2e5 + 100;

#define pb push_back

#define mp make_pair

#define f first

#define s second

#define ull unsigned long long

#define ll long long

#define pii pair <int,int>

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

#define FOR(l,i,n) for(int i = l;i < n;++i)

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

#define pll pair <ll,ll>

const ll inf = 1e9 + 7;

const ll ll_inf = 1e17 + 100;   

const double pi = 3.14159265358979323;

inline void fr(){

    freopen("gcd.in", "r", stdin);

    freopen("gcd.out", "w", stdout);

}

void boost()

{

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);

}

 

ll binpow (ll a, ll n)

{

    ll res = 1;

    while (n) {

        if (n & 1)

        {

            res *= a;

            res %= inf;

        }

        a *= a;

        n >>= 1;

        a %= inf;

    }

    return res;

}

        

int n;

int h[N];

int dp[N];

 

main()	

{                                                                        

	cin >> n;

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

}	 


// 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 mp make_pair

#define pb push_back

#define f first

#define s second

#define ll long long

#define int ll

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

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

#define VAR(v, i) __typeof( i) v=(i)

#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)

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

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

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);

 

using namespace std;

 

const int maxn = (int)1e5 + 100;

const int mod = (int)1e9 + 7;

 

#define inf mod

 

typedef long double ld;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;   

typedef vector<ll> Vll;               

typedef vector<pair<int, int> > vpii;

typedef vector<pair<ll, ll> > vpll;

 

int n, dp[maxn];

int h[maxn];

main () {

	cin >> n;

	forn(i, 1, n)

		cin >> h[i];

	dp[1] = 0;

	forn(i, 2, n){

		dp[i] = inf * inf;

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

		if(i > 2)

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

	}

	cout << dp[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 long long ll;

typedef long double ld;

typedef unsigned long long ull;

 

#define nl '\n'

 

#define y1 aza_ibagaliev

 

#define f first

#define s second

	

#define ed end()

#define bg begin()

#define rbg rbegin()

 

#define rv reverse

#define mp make_pair

#define pb push_back

#define ppb pop_back

#define ppf pop_front

 

#define sz size()

#define all(x) x.bg, x.ed

 

#define pll pair < ll, ll >

#define pii pair < int, int >

 

#define sqr(x) ((x) * 1ll * (x))

#define sqrd(x) ((x) * 1.0 * (x))

 

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

 

#define rnl cout << "----------------------------------------" << nl

 

#define bit __builtin_popcount

 

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 ppr = 257;

const ll INF = 2e18;

const int inf = 998244353;

const int mod = 1e9 + 7;

const int N = 1e5 + 123;

const ld pi = 3.1741592653589793238462643;

 

const int dx[] = {1, 0, -1, 0};

const int dy[] = {0, 1, 0, -1};



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



main() {             	

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

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



//	srand(time(NULL));



	scanf("%d", &n);



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

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



		if(i == 1) continue;



		dp[i] = inf;

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

		if(i > 2) dp[i] = min(dp[i], 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>

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, a[(int)2e5], d[(int)2e5];



int main(){

    cin >> n;

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

        cin >> a[i];

    }

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

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

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

    cout << d[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 <iostream>

#include <iomanip>

#include <cmath>

#include <cstdio>

#include <cstring>

#include <ctime>

#include <string>

#include <stdio.h>

#include <set>

#include <map>

#include <algorithm>

#include <queue>

#include <vector>

#define ll long long

#define pb push_back

#define mp make_pair

#define f first

#define s second



using namespace std;



const int inf = 1e9 + 7;

const long long INF = 1e18 + 7;

const int maxn = 2e5 + 7;



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



int main(){

	ios_base::sync_with_stdio(NULL);

	cin.tie(0);

	cout.tie(0);

	cin >> n;

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

		cin >> a[i], dp[i] = inf;

	dp[1] = 0;

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

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

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

	}

	cout << dp[n];

	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 main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    long long n;

    cin >> n;

    long long a[n + 1], dp[n + 1];

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

        cin >> a[i];

        dp[i] = 0;

    }

    if(n == 1)

        cout << 0 << endl;

    else {

        dp[1] = 0;

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

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

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

        }

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

#include <cmath>



using namespace std;

int i,n,h[100005];

long long dp[100005];

int main()

{

    cin>>n;

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

        cin>>h[i];

    dp[1]=0;

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

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

    {

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

    }

    cout<<dp[n];

    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 ;



const int nmax = 100010;



int h[nmax];

int dp[nmax];



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    int n;cin>>n;

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

    dp[0]=1000000000;

    dp[1]=0;

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

    {

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

    }

    cout<<dp[n];

    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;



long long n,a,m,b,qq;

string ss;

int main() {

    cin>>n;

    int l[n],l1[n];

    l[n]=0;

    l1[n]=0;

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

        l[i]=0;

        l1[i]=0;

    }

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

        cin>>l[i];

    }

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

        if (i==1){

            l1[i]=abs(l[i]-l[i-1]);

        }

        else{

            l1[i]=min(l1[i-1]+abs(l[i-1]-l[i]), l1[i-2]+abs(l[i-2]-l[i]));

        }

    }

    cout<<l1[n-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;





#define x_ real()

#define y_ imag()

#define cross(a, b) (conj(a)*(b)).imag()

#define dot(a, b) (conj(a)*(b)).real()

#define PI acos(-1)

#define F first

#define S second

#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)

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

typedef long double ld;

typedef long long ll;

typedef unsigned long long ull;

typedef complex<ld> point;

typedef tuple<int, int, int> line;

typedef vector<point> polygon;

typedef pair<double, double> pd;

pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };

ll mod = 1e9 + 7;

ld eps = 1e-6;









int main() {

	fastIO;

	int n;

	cin >> n;

	int dp[n+1], arr[n+1];

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

		cin >> arr[i];

	}

	dp[0] = 0;

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

		if (i > 1) {

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

		}

		else {

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

		}

	}



	cout << dp[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:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

 

int h[100000], mCost[100000];

int Nstones;

 

int main() {

	scanf("%d", &Nstones);

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

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

	}

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

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

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

	}

	printf("%d", mCost[Nstones - 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:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

ll h[100009];

ll dp[100009];

int main() {

    int n;

    cin>>n;

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

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

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

	

#define endl "\n"

#define ll unsigned long long

#define int long long

#define vi vector <int >

#define vii vector < pii >

#define vll vector <ll >

#define pii pair <int, int>

#define pdd pair< double, double>

#define piii pair < pii, int > 

#define pll pair<ll, ll >

#define umap unordered_map

#define pb push_back

#define pq priority_queue

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

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

#define a first

#define b second



int32_t main() {

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);



	int dp[100010];

	int n;

	cin >> n;

	vi arr(n);

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

		cin >> arr[i];

	}

	dp[0] = 0;

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

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

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

	}

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

    #include <cstdio>

    #include <cstring>

    #include <algorithm>

    #include <stack>

    #include <string>

    #include <cstring>

    #include <cmath>

    #include <vector>

    #include <set>

    #define INF  0x3f3f3f3f;

    #define maxn 1000605

    typedef long long LL;

    using namespace std;

    int h[100005];

    int d[100005];

    int get_min(int a,int b){

        if(a<b)

            return a;

        else

            return b;

    }



    int main(){

        int n;

        while(cin>>n){

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

                cin>>h[i];

            d[1]=0;

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

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

                d[i]=get_min(d[i-1]+abs(h[i]-h[i-1]),d[i-2]+abs(h[i]-h[i-2]));

            }

            cout<<d[n]<<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 arr[100010],n;

int dp[100010];

int f(int pos){

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

	int &ret=dp[pos];

	if(ret^-1)return ret;

	if(pos+1==n-1)return ret=abs(arr[pos+1]-arr[pos]);

	return ret=min(f(pos+1)+abs(arr[pos]-arr[pos+1]),f(pos+2)+abs(arr[pos]-arr[pos+2]));

}



int main(int argc, char const *argv[])

{

	memset(dp,-1,sizeof dp);

	cin>>n;

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

		cout<<f(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: