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



#define ll int64

#define pb push_back

#define ff first

#define ss second

#define sz size()

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

#define allr(a) a.rbegin(), a.rend()

#define mod 1000000007

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

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

     

using namespace std;



const int maxn=110000;

int n,h[maxn],f[maxn];

int main(){

    IO;    

    scanf("%d",&n);

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

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

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

    printf("%d",f[n]);    

    return 0;

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

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

#define ll long long

#define ld long double

using namespace std;

const int N = 1e5+5;



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





int solve(int i)

{

    if(i == n-1)

        return 0;

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

    ll op1 = solve(i+1) + abs(h[i+1] - h[i]);

    ll op2 = op1;

    if(i + 2 < n)

        op2 = solve(i+2) + abs(h[i+2] - h[i]);

    return dp[i] = min(op1, op2);

}



int table()

{

    dp[0] = 0;

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

    {

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

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

    }

    return dp[n-1];

}



int main()

{

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

    cin >> n;

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

        cin >> h[i];

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

    cout << table();

    // cout << solve(0);





    return 0;

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

const int mod = 1e9+9;

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

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

*void exEuclid(int a, int b){

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

	exEuclid(b, a%b);

	int x1=y;

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

	x=x1;

	y=y1;

} 

* */

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

const int nax = 1e5+3;

int n;

int dp[nax];

int a[nax];

int f(int i){

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

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

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

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

	return dp[i]=ans;

}

int main(){

	cin>>n;

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

	memset(dp, -1, sizeof dp);

	cout<<f(0)<<endl;

	return 0;

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

}
// Slower C++ solution:
#include<iostream>

using namespace std;

int numStones;

int heights[100005],b[100005];

int main(){

	cin>>numStones;

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

	    cin>>heights[i];

	}

	b[2]=abs(heights[1]-heights[2]);

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

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

	}

	cout<<b[numStones];

	return 0;

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

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

using namespace std;

 

typedef long long lld;

const int NN = 1e5 + 5;

lld aa[NN], dp[NN];

int nn;

 

int main() {

    ios::sync_with_stdio(0);

    cin.tie(0); 

    cout.tie(0);

        cin >> nn;

        for (int ii = 1; ii <= nn; ++ii)

            cin >> aa[ii];

        dp[1] = 0;

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

        for (int ii = 3; ii <= nn; ++ii)

            dp[ii] = min(dp[ii-1] + abs(aa[ii] - aa[ii - 1]), dp[ii-2] + abs(aa[ii] - aa[ii - 2]));

        cout << dp[nn];

    return 0;

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

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

using namespace std;

#define INF 1<<28

#define max 100005

 

 

typedef long long ll;

 

int n, a[100005];

int dp[max];

 

int main()

{

    cin>>n;

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

        cin>>a[i];

    dp[1] = 0;

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

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

    return 0;

}  

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

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

using namespace std;

#define ll long long

ll dp[100009];

ll n,x;

vector<ll>v;

ll frog(ll pos)

{

    if(pos<=0)

        return 0;

    if(pos==1)

        return abs(v[0]-v[1]);

        if(dp[pos]==-1)

        {

            dp[pos]= min(abs(v[pos]-v[pos-1])+frog(pos-1),abs(v[pos]-v[pos-2])+frog(pos-2));

        }

    return dp[pos];

}



int main()

{

    cin>>n;

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

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

    {

        cin>>x;

        v.push_back(x);

    }

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

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

}
// Slower C++ solution:
#include<iostream>

#include<cmath>

#include<algorithm>

using namespace std;



int dp[100004]={0};

int h[100005]={0};

int main(){

	int n;

	cin>>n;

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

		cin>>h[i];

	}

	

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

		int i1=i-1>0 ? i-1: 1,i2=i-2>0? i-2:1;

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

//		cout<<dp[i1]+abs(h[i]-h[i1])<<" "<<dp[i2]+abs(h[i]-h[i2])<<endl;

	}

//	for(int i=1;i<=n;i++) cout<<dp[i]<<" ";

	cout<<dp[n];

//	cout<<min(20 ,20);

	return 0;

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

}
// Slower C++ solution:
#define _CRT_SECURE_NO_vARNINGS

#include <vector>

#include <iostream>

#include <cstdio>

#include <map>

#include <algorithm>

#include <queue>

#include <string>

#include <climits>

#include <list>

#include <cmath>

using namespace std;



int main() {

	int n;

	cin >> n;

	vector<int> v(n, 0);

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

	// dp[i] = min(dp[i-1]+ abs(v[i]-v[i-1]), dp[i-2]+abs(v[i]-v[i-2]))

	vector<int> dp(n, 0);

	dp[0] = 0;

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

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

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

	}

	cout << dp[n - 1];

	return 0;

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <algorithm>

#include <vector>

#include <unordered_map>

#include <string>

#include <cstring>

#include <cctype>

#include <climits>

#include <cmath>

#include <set>

#include <map>

#include <unordered_set>

#include <sstream>

#include <queue>

#include <stack>

using namespace std;

vector<int> high;

int n;



int main(){

	scanf("%d",&n);

	high.resize(n+1);

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

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

	}

	vector<int> dp(n+1);

	dp[1]=0;

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

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

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

	}

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

	return 0;

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

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



using namespace std;

int v[1000010];

int memo[1000010];

int c;



int f(int i)

{



    if(memo[i]!=-1)

        return memo[i];



    if(i == 0)

        return memo[0] = 0;



    if(i == 1)

        return memo[1] = abs(v[0] - v[1]);



    return memo[i] = min(abs(v[i] - v[i-1]) + f(i-1), abs(v[i] - v[i-2]) + f(i-2));

}



int main()

{



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

    cin>>c;



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

    {

        cin>>v[i];

    }



    cout<<f(c-1)<<endl;



    return 0;

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

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

using namespace std;

const int N = 1e5 + 100;

int n, h[N], mem[N];



int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);



	cin >> n;



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

		cin >> h[i];

	}



	mem[n - 2] = abs(h[n - 1] - h[n - 2]);



	for (int i = n - 3; i >= 0; i--) {

		int a1 = mem[i + 1] + abs(h[i] - h[i + 1]);

		int a2 = mem[i + 2] + abs(h[i] - h[i + 2]);

		mem[i] = min(a1, a2);

	}



	cout << mem[0] << '\n';

	

	return 0;

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

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

using namespace std;

const long long mk=100005;

long long arr[mk];

long long n, dp[mk];

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	dp[0]=0;

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

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

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

	}

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

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

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

using namespace std;

int h[100001];

int dp[100001];

int n;

int solve(int stone)

{

    if(stone+1==n) return dp[stone]=abs(h[stone]-h[stone+1]);

    if(stone+2==n) return dp[stone+2]=abs(h[stone]-h[stone+2]);

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

    return dp[stone]=min(abs(h[stone]-h[stone+1])+solve(stone+1),abs(h[stone]-h[stone+2])+solve(stone+2));

}



int main()

{

    int i;

    scanf("%d",&n);



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

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



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

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





    return 0;

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

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

using namespace std;

const int mx = 1e5+10;

int dp[mx];

int main()

{

    int n;

    cin>>n;

    int arr[n+1];

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

        cin>>arr[i];

    dp[0]=0;

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

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

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

    {

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

    }

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

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

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



using namespace std;



int n, h[100002], dp[100002];



int sol(int i){

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

    if(i>=n) return 1E9;



    int &ret = dp[i];

    if(~ret) return ret;



    return ret = min(abs(h[i+1]-h[i]) + sol(i+1),

                     abs(h[i+2]-h[i]) + sol(i+2));

}



int main()

{

    cin >> n;

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

        cin >> h[i];



    memset(dp, -1, sizeof dp);

    cout << sol(0);

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

}
// Slower C++ solution:
#include<iostream>

using namespace std;

#define maxn 100005

int h[maxn];

int dp[maxn];

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;

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

}
// Slower C++ solution:
#include <iostream>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<string>

#define ll long long int

using namespace std;

const int maxn=1000010;



int high[maxn];

int dp[maxn];



int main( )

{

    int i,n;;

    cin>>n;

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

    {

        cin>>high[i];

    }

    dp[1]=0;

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

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

    {

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

        //cout<<dp[i]<<endl;

    }

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

	 return 0;

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

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

using namespace std;



#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void __f(const char* name, Arg1&& arg1) {

  cerr << name << " : " << arg1 << "\n";

}

template <typename Arg1, typename... Args>

void __f(const char* na, Arg1&& arg1, Args&&... args) {

  const char* c = strchr(na + 1, ',');

  cerr.write(na, c - na) << " : " << arg1 << " , ";

  __f(c + 1, args...);

}

#define endl "\n"

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

#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())

typedef long long LL;

typedef pair <int,int> pii;

const double pi = acos(-1.0);

const double eps = 1e-8;

const int mod = 1e9 + 7;

const int inf = 1e9;

const LL INF = 1e18;

const int N = 1e5 + 5;



int main() {

  ios_base::sync_with_stdio(false);

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

  #ifdef LOCAL

    freopen("input.txt", "r", stdin);

  #endif // LOCAL

  int n;

  cin >> n;

  vector <LL> h (n + 1);

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

  vector <LL> dp (n + 1, INF);

  dp[1] = 0;

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

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

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

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    }

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

}