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

using namespace std;

int n;

int h[1000005], memo[1000005];

int f(int n) {

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

        return 0;

    }

    if(n == 2) {

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

    } 

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

        return memo[n];

    }

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

    return memo[n];

}



int main() {

    scanf("%d", &n);

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

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

    }

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

    f(n);

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

}

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

#include <vector>

#include <cmath>

#include <set>

#include <queue>

#include <map>

#include <cstdio>

#include <cstring>

#include <string>

#include <stack>

#include <algorithm>

#include <limits.h>

#include <bits/stdc++.h>

#define fw(x) freopen("x.txt","w",stdout)

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

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

#define REP1(i,n) for(int i = 1; i<=n;i++)

#define mem(a,s) memset(a,s,sizeof a)

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

#define pf printf

#define sc scanf

#define ll long long

#define pii pair<int,int>

#define pll pair<ll,ll>

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

#define vii vector<int>

#define vll vector<ll>

#define vss vector<string>

#define debug(x)  cout<<#x"="<<(x)<<endl

#define pb push_back





using namespace std;





// moves



//int dx[]= {0,0,1,-1};/*4 side move*/

//int dy[]= {-1,1,0,0};/*4 side move*/

//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/

//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/

//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/

//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/





//big_mod



//ll bigmod(ll a,ll b,ll m)

//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}

//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M



//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}

//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}

//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}

//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}



const int mod = 1000000007;



int main()

{

    fast;

    int n;

    cin>>n;

    int arr[n];

    REP(i, n) cin>>arr[i];

    int cost[n] = {0};

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

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

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

    }

    cout<<cost[n-1]<<'\n';

    return 0;

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

using namespace std;



typedef signed long long ll;

const int MX = 1e5 + 5;

const int INF = 1e9 + 5;

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



int solve(int pos) {

    if(pos > n) return INF;

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

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

    int ans = INF;

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

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

    return dp[pos] = ans;

}



int main() {

    scanf("%d", &n);



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

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

    }

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

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

    return 0;

}

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

#include <vector>

#include <cmath>

#include <set>

#include <queue>

#include <map>

#include <cstdio>

#include <cstring>

#include <string>

#include <stack>

#include <algorithm>

#include <limits.h>

#include <bits/stdc++.h>

#define fw(x) freopen("x.txt","w",stdout)

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

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

#define REP1(i,n) for(int i = 1; i<=n;i++)

#define mem(a,s) memset(a,s,sizeof a)

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

#define pf printf

#define sc scanf

#define ll long long

#define pii pair<int,int>

#define pll pair<ll,ll>

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

#define vii vector<int>

#define vll vector<ll>

#define vss vector<string>

#define debug(x)  cout<<#x"="<<(x)<<endl

#define pb push_back





using namespace std;





// moves



//int dx[]= {0,0,1,-1};/*4 side move*/

//int dy[]= {-1,1,0,0};/*4 side move*/

//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/

//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/

//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/

//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/





//big_mod



//ll bigmod(ll a,ll b,ll m)

//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}

//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M



//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}

//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}

//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}

//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}



const int mod = 1000000007;



int main()

{

    fast;

    int n;

    cin>>n;

    int arr[n];

    REP(i, n) cin>>arr[i];

    int cost[n] = {0};

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

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

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

    }

    cout<<cost[n-1]<<'\n';

    return 0;

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

#include<cmath>

#include<algorithm>

#include<cstring>

using namespace std;



int h[100055],dp[100055];

const int inf = 0x3f3f3f;

int main()

{

	int n;

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

	cin>>n;

	h[1]=inf;

	h[0]=inf;

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

		cin>>h[i];

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

	{

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

	}

		

	cout<<dp[n]<<endl;

	return 0;

} 

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

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

#include <vector>

#include <cmath>

#include <set>

#include <queue>

#include <map>

#include <cstdio>

#include <cstring>

#include <string>

#include <stack>

#include <algorithm>

#include <limits.h>

#include <bits/stdc++.h>

#define fw(x) freopen("x.txt","w",stdout)

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

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

#define REP1(i,n) for(int i = 1; i<=n;i++)

#define mem(a,s) memset(a,s,sizeof a)

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

#define pf printf

#define sc scanf

#define ll long long

#define pii pair<int,int>

#define pll pair<ll,ll>

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

#define vii vector<int>

#define vll vector<ll>

#define vss vector<string>

#define debug(x)  cout<<#x"="<<(x)<<endl

#define pb push_back





using namespace std;





// moves



//int dx[]= {0,0,1,-1};/*4 side move*/

//int dy[]= {-1,1,0,0};/*4 side move*/

//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/

//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/

//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/

//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/





//big_mod



//ll bigmod(ll a,ll b,ll m)

//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}

//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M



//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}

//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}

//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}

//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}



const int mod = 1000000007;



int main()

{

    fast;

    int n;

    cin>>n;

    int arr[n];

    REP(i, n) cin>>arr[i];

    int cost[n] = {0};

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

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

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

    }

    cout<<cost[n-1]<<'\n';

    return 0;

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

using namespace std;

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

typedef long long ll;

const int maxn = 1e6 + 5;

const int inf = 0x3f3f3f3f;

ll a[maxn];

ll dp[maxn];



int main()

{

    IO;

    int n, k=2;

    cin >> n ;

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

        cin >> a[i];

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

    dp[1] = 0;

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

    {

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

        {

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

        }

    }

    cout << dp[n] << endl;

}


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

#include <vector>

#include <cmath>

#include <set>

#include <queue>

#include <map>

#include <cstdio>

#include <cstring>

#include <string>

#include <stack>

#include <algorithm>

#include <limits.h>

#include <bits/stdc++.h>

#define fw(x) freopen("x.txt","w",stdout)

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

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

#define REP1(i,n) for(int i = 1; i<=n;i++)

#define mem(a,s) memset(a,s,sizeof a)

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

#define pf printf

#define sc scanf

#define ll long long

#define pii pair<int,int>

#define pll pair<ll,ll>

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

#define vii vector<int>

#define vll vector<ll>

#define vss vector<string>

#define debug(x)  cout<<#x"="<<(x)<<endl

#define pb push_back





using namespace std;





// moves



//int dx[]= {0,0,1,-1};/*4 side move*/

//int dy[]= {-1,1,0,0};/*4 side move*/

//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/

//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/

//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/

//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/





//big_mod



//ll bigmod(ll a,ll b,ll m)

//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}

//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M



//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}

//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}

//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}

//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}



const int mod = 1000000007;



int main()

{

    fast;

    int n;

    cin>>n;

    int arr[n];

    REP(i, n) cin>>arr[i];

    int cost[n] = {0};

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

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

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

    }

    cout<<cost[n-1]<<'\n';

    return 0;

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

using namespace std;

const int nax = 1e5+3;

int number;

int dyn[nax];

int a[nax];

int op1(int i){

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

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

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

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

	return dyn[i]=res;

}

int main(){

	cin>>number;

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

	memset(dyn, -1, sizeof dyn);

	cout<<op1(0)<<endl;

	return 0;

}


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

#include <vector>

#include <cmath>

#include <set>

#include <queue>

#include <map>

#include <cstdio>

#include <cstring>

#include <string>

#include <stack>

#include <algorithm>

#include <limits.h>

#include <bits/stdc++.h>

#define fw(x) freopen("x.txt","w",stdout)

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

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

#define REP1(i,n) for(int i = 1; i<=n;i++)

#define mem(a,s) memset(a,s,sizeof a)

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

#define pf printf

#define sc scanf

#define ll long long

#define pii pair<int,int>

#define pll pair<ll,ll>

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

#define vii vector<int>

#define vll vector<ll>

#define vss vector<string>

#define debug(x)  cout<<#x"="<<(x)<<endl

#define pb push_back





using namespace std;





// moves



//int dx[]= {0,0,1,-1};/*4 side move*/

//int dy[]= {-1,1,0,0};/*4 side move*/

//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/

//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/

//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/

//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/





//big_mod



//ll bigmod(ll a,ll b,ll m)

//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}

//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M



//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}

//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}

//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}

//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}



const int mod = 1000000007;



int main()

{

    fast;

    int n;

    cin>>n;

    int arr[n];

    REP(i, n) cin>>arr[i];

    int cost[n] = {0};

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

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

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

    }

    cout<<cost[n-1]<<'\n';

    return 0;

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

using namespace std;

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



int dp(int x){

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

		return 0;

	}

	if (x == 2){

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

	}

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

		return memo[x];

	}

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

	memo[x] = best;

	return best;

}



int main(){

	ios_base::sync_with_stdio(0);

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

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	cout << dp(n) << endl;

}

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

#include <vector>

#include <cmath>

#include <set>

#include <queue>

#include <map>

#include <cstdio>

#include <cstring>

#include <string>

#include <stack>

#include <algorithm>

#include <limits.h>

#include <bits/stdc++.h>

#define fw(x) freopen("x.txt","w",stdout)

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

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

#define REP1(i,n) for(int i = 1; i<=n;i++)

#define mem(a,s) memset(a,s,sizeof a)

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

#define pf printf

#define sc scanf

#define ll long long

#define pii pair<int,int>

#define pll pair<ll,ll>

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

#define vii vector<int>

#define vll vector<ll>

#define vss vector<string>

#define debug(x)  cout<<#x"="<<(x)<<endl

#define pb push_back





using namespace std;





// moves



//int dx[]= {0,0,1,-1};/*4 side move*/

//int dy[]= {-1,1,0,0};/*4 side move*/

//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/

//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/

//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/

//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/





//big_mod



//ll bigmod(ll a,ll b,ll m)

//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}

//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M



//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}

//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}

//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}

//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}



const int mod = 1000000007;



int main()

{

    fast;

    int n;

    cin>>n;

    int arr[n];

    REP(i, n) cin>>arr[i];

    int cost[n] = {0};

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

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

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

    }

    cout<<cost[n-1]<<'\n';

    return 0;

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

using namespace std;

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



int dp(int x){

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

		return 0;

	}

	else if(x==2){

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

	}

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

		return memo[x];

	}

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

	memo[x]=best;

	return best;

}



int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

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

	cin >> n;

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

		cin >> arr[i];

	}

	cout << dp(n) << endl;

}


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

#include <vector>

#include <cmath>

#include <set>

#include <queue>

#include <map>

#include <cstdio>

#include <cstring>

#include <string>

#include <stack>

#include <algorithm>

#include <limits.h>

#include <bits/stdc++.h>

#define fw(x) freopen("x.txt","w",stdout)

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

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

#define REP1(i,n) for(int i = 1; i<=n;i++)

#define mem(a,s) memset(a,s,sizeof a)

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

#define pf printf

#define sc scanf

#define ll long long

#define pii pair<int,int>

#define pll pair<ll,ll>

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

#define vii vector<int>

#define vll vector<ll>

#define vss vector<string>

#define debug(x)  cout<<#x"="<<(x)<<endl

#define pb push_back





using namespace std;





// moves



//int dx[]= {0,0,1,-1};/*4 side move*/

//int dy[]= {-1,1,0,0};/*4 side move*/

//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/

//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/

//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/

//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/





//big_mod



//ll bigmod(ll a,ll b,ll m)

//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}

//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M



//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}

//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}

//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}

//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}



const int mod = 1000000007;



int main()

{

    fast;

    int n;

    cin>>n;

    int arr[n];

    REP(i, n) cin>>arr[i];

    int cost[n] = {0};

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

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

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

    }

    cout<<cost[n-1]<<'\n';

    return 0;

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

}

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

#include <vector>

#include <cmath>

#include <set>

#include <queue>

#include <map>

#include <cstdio>

#include <cstring>

#include <string>

#include <stack>

#include <algorithm>

#include <limits.h>

#include <bits/stdc++.h>

#define fw(x) freopen("x.txt","w",stdout)

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

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

#define REP1(i,n) for(int i = 1; i<=n;i++)

#define mem(a,s) memset(a,s,sizeof a)

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

#define pf printf

#define sc scanf

#define ll long long

#define pii pair<int,int>

#define pll pair<ll,ll>

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

#define vii vector<int>

#define vll vector<ll>

#define vss vector<string>

#define debug(x)  cout<<#x"="<<(x)<<endl

#define pb push_back





using namespace std;





// moves



//int dx[]= {0,0,1,-1};/*4 side move*/

//int dy[]= {-1,1,0,0};/*4 side move*/

//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/

//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/

//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/

//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/





//big_mod



//ll bigmod(ll a,ll b,ll m)

//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}

//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M



//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}

//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}

//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}

//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}



const int mod = 1000000007;



int main()

{

    fast;

    int n;

    cin>>n;

    int arr[n];

    REP(i, n) cin>>arr[i];

    int cost[n] = {0};

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

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

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

    }

    cout<<cost[n-1]<<'\n';

    return 0;

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

#define ll long long

using namespace std;

const int maxn = 1e5+5;

int a[maxn], dp[maxn];



int main(){

	int n; cin >> n;

	memset(dp, 0x3f, sizeof dp);

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

	dp[1] = 0;

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

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

}

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

#include <vector>

#include <cmath>

#include <set>

#include <queue>

#include <map>

#include <cstdio>

#include <cstring>

#include <string>

#include <stack>

#include <algorithm>

#include <limits.h>

#include <bits/stdc++.h>

#define fw(x) freopen("x.txt","w",stdout)

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

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

#define REP1(i,n) for(int i = 1; i<=n;i++)

#define mem(a,s) memset(a,s,sizeof a)

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

#define pf printf

#define sc scanf

#define ll long long

#define pii pair<int,int>

#define pll pair<ll,ll>

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

#define vii vector<int>

#define vll vector<ll>

#define vss vector<string>

#define debug(x)  cout<<#x"="<<(x)<<endl

#define pb push_back





using namespace std;





// moves



//int dx[]= {0,0,1,-1};/*4 side move*/

//int dy[]= {-1,1,0,0};/*4 side move*/

//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/

//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/

//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/

//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/





//big_mod



//ll bigmod(ll a,ll b,ll m)

//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}

//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M



//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}

//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}

//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}

//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}



const int mod = 1000000007;



int main()

{

    fast;

    int n;

    cin>>n;

    int arr[n];

    REP(i, n) cin>>arr[i];

    int cost[n] = {0};

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

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

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

    }

    cout<<cost[n-1]<<'\n';

    return 0;

}