stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
//       Author: Mostafa Mounir Shehab

 

#include <bits/stdc++.h>

using namespace std;

 

#define PI  3.14159265  // PI = acos(-1)

#define EPS (1e-10)

#define endl "\n"

#define SZ(v) (int)(v.size())

typedef long long ll;

typedef long double ld;

//template <class Type>

 

 

void Fast(){

	std::ios_base::sync_with_stdio(0);

	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);

}

 

inline int D(){

	int t;

	scanf("%d",&t);

	return t;

}

inline ll llD(){

	ll t;

	scanf("%lld",&t);

	return t;

}

 

 

ll MOD=1e9 + 7; 

const int N=1e5 + 5,M=50 + 1;

int arr[N];

ll dp[N];

ll OO=1e12; 

 

ll n,m,k,cnt,SU,idx,len,MN,MX;

ll l,r,mid;

ll a,b,c,d;



ll Solve(int idx){

	ll &ret = dp[idx];

	if(~ret)

		return ret;

		

	if(idx >= n)

		return ret = (idx == n) ? 0 : OO;

	

	

	ll x = abs(arr[idx] - arr[idx+1]) + Solve(idx+1);

	ll y = abs(arr[idx] - arr[idx+2]) + Solve(idx+2);

	

	return ret = min(x,y);

}







 

 

int main(){

	

	memset(dp, -1 ,sizeof dp);

	cin>>n;

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

		cin>>arr[i];



	cout<<Solve(1)<<endl;

	



	





}

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

#include<cmath>

using namespace std;

const int maxn = 1e6 + 10;

int height[maxn];

long long dp[maxn];



int main(){

    int n;

    scanf("%d", &n);

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

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

    dp[1] = 0;

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

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

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

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

    return 0;

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

using namespace std;

const int maxn = 1e5 + 5;

int main(){

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

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

	scanf("%d",&n);

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

		scanf("%d",&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]));

	}

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

	return 0;

}

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

#include<cmath>

using namespace std;

const int maxn = 1e6 + 10;

int height[maxn];

long long dp[maxn];



int main(){

    int n;

    scanf("%d", &n);

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

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

    dp[1] = 0;

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

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

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

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

    return 0;

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



using namespace std;



const int N = 1e5 + 9;



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



int sol(int i, int prev){

    if(i >= n)  return 1e9;

    if(i == n - 1)  return abs(h[i] - h[i - 1 - (prev == 1)]);



    int &ret = dp[i][prev];

    if(~ret)    return ret;



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

}



int main(){

    cin >> n;

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

        cin >> h[i];



    memset(dp, -1, sizeof dp);



    cout << min(sol(1, 0), sol(2, 1));



    return 0;

}

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

#include<cmath>

using namespace std;

const int maxn = 1e6 + 10;

int height[maxn];

long long dp[maxn];



int main(){

    int n;

    scanf("%d", &n);

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

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

    dp[1] = 0;

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

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

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

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

    return 0;

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



using namespace std;



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



int sol(int i, int choice){

    if(i==0) return 0;

    if(i<0) return 1E9;



    int &ret = dp[i][choice];

    if(~ret) return ret;



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

}



int main()

{

    cin >> n;

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

        cin >> h[i];



    memset(dp, -1, sizeof dp);

    cout << min(sol(n-1, 1), sol(n-1, 2));

}


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

#include<cmath>

using namespace std;

const int maxn = 1e6 + 10;

int height[maxn];

long long dp[maxn];



int main(){

    int n;

    scanf("%d", &n);

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

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

    dp[1] = 0;

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

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

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

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

    return 0;

}
// Slower C++ solution:


#include <bits/stdc++.h>

using namespace  std;



int N;

const int SIZE = 100005;

long h [SIZE];

int mem [SIZE];



int dp (int i) {

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

  

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



  long ret = LLONG_MAX;



  if (i+1 < N) 

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

  if (i+2 < N)

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



  return  mem[i] = ret;

}



int main (){ 



  cin  >> N;

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

    cin >> h[i];

  }



  memset(mem, -1, sizeof mem);



  cout << dp(0);



}

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

#include<cmath>

using namespace std;

const int maxn = 1e6 + 10;

int height[maxn];

long long dp[maxn];



int main(){

    int n;

    scanf("%d", &n);

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

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

    dp[1] = 0;

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

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

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

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

    return 0;

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

#define maxn 100005

using namespace std;



int main(){

    int n;

    cin >> n;

    int h[maxn];

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

        cin >> h[i];

    }

    int dp[maxn];

    fill(dp, dp+maxn, 0x7fffffff);

    dp[0] = 0;

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

        int temp = 0;

        if(i+1 < n){

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

            if(temp < dp[i+1])

                dp[i+1] = temp;

        }

        if(i+2 < n){

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

            if(temp < dp[i+2])

                dp[i+2] = temp;

        }

    }

    cout << dp[n-1];

    return 0;

}


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

#include<cmath>

using namespace std;

const int maxn = 1e6 + 10;

int height[maxn];

long long dp[maxn];



int main(){

    int n;

    scanf("%d", &n);

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

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

    dp[1] = 0;

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

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

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

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

    return 0;

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

#include<bits/stdc++.h>

#define rep(i,a,n) for (int i=a;i<n;i++)

#define per(i,a,n) for (int i=n-1;i>=a;i--)

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

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

#define clr(v, d) memset(v, d, sizeof(v))

#define fi first

#define se second

#define pp push_back

#define pb pop_back

#define pi 3.141592654

#define MOD 1000000007 

#define cons1 1e12

#define cons2 1e6

using namespace std;

typedef long long ll;

typedef vector<int> vi;

typedef pair<int, int> pa;

typedef unsigned long long int ull;

typedef double long dl;

const int N = 1e5+9;

int n;

int v[N], ans[N];

int sol(int i) {

	if (ans[i] == -1) {

		if (i == n - 1)

			ans[i] = 0;

		else if (i == n - 2)

			ans[i] = abs(v[i] - v[i + 1]);

		else 

			ans[i] = min(abs(v[i] - v[i + 1])+sol(i + 1)

				, abs(v[i] - v[i + 2]) + sol(i + 2));

		

	}

	return ans[i];

	

}

void solve() {

	clr(ans, -1);

	cin >> n;

	rep(i, 0, n)

		cin >> v[i];

	cout << sol(0) << endl;

}

int main() {

	ios::sync_with_stdio(0);

	cin.tie(NULL);

	cout.tie(NULL);

	int t = 1;

	//cin >> t;

	while (t--)

		solve();



#ifndef ONLINE_JUDGE

	- system("pause");

#endif



}

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

#include<cmath>

using namespace std;

const int maxn = 1e6 + 10;

int height[maxn];

long long dp[maxn];



int main(){

    int n;

    scanf("%d", &n);

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

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

    dp[1] = 0;

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

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

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

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

    return 0;

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

using namespace std;



typedef long double LD;

typedef long long ll;

typedef map<int,int> mii;

typedef pair<int,int> pii;

typedef vector<pii> vpii;



#define pb              push_back

#define mp              make_pair

#define F               first

#define S               second

#define mod             1000000007

#define INF             2147483647

#define Endl            "\n"

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

#define precision(a)    cout << fixed << setprecision(a)

#define bug(a,b)        cout<<a<<"\t"<<b<<"\n";

#define Case(a,b)       cout<<"Case "<<a<<": "<<b<<"\n";

#define reset(a,b)      memset(a,b,sizeof(a));

#define srt(a)      sort(a.begin(),a.end());



const int MAXN = 1000005;

const int SQRTN = 1003;

const int LOGN = 22;

const double PI=acos(-1);

const int sz=1e5+9;



int strtoint(string str){

    stringstream ss(str);

    int x = 0;

    ss >> x ;

    return x ;

}

string intostr(int x){

    stringstream ss;

    ss << x;

    string str = ss.str();

    return str;

}

void rem(string &s, const string &c) {

	auto pos = s.find(c);

	if (pos == string::npos) {

		cout << -1 << endl;

		exit(0);

	}

	s.erase(0, pos + 1);

}

void println (int n){

    cout<<n<<"\n";

}

void printvec(vector <int> &a){

    for (int i=0;i<a.size();i++){

        cout<<a[i]<<" ";

    }

    cout<<"\n";

}



void printgraph(vector <int> g[],int e){

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

        cout<<i<<" --> ";

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

            cout<<g[i][j]<<" ";

        }

        cout<<"\n";

    }

}



void printmap (map <int,int> &mymap){

    for (auto itr = mymap.begin(); itr != mymap.end(); ++itr) {

        cout << '\t' << itr->first

             << '\t' << itr->second << '\n';

    }

    cout << "\n";

}



int n,x,arr[sz],dp[sz];





int rec (int i){

    if (i==n) return 0;

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

    int left = abs(arr[i]-arr[i+1])+rec(i+1);

    int right = INF;

    if (i+2<=n){

        right = abs(arr[i]-arr[i+2])+rec (i+2);

    }

    return dp[i]= min(left,right);

}





void solve(){



    cin>>n;

    reset (dp,-1);

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





    cout << rec (1) << Endl;



    //printvec(v);

}





int main(){

    //FasterIO;



    solve();

    return 0;

}


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

#include<cmath>

using namespace std;

const int maxn = 1e6 + 10;

int height[maxn];

long long dp[maxn];



int main(){

    int n;

    scanf("%d", &n);

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

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

    dp[1] = 0;

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

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

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

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

    return 0;

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



using namespace std;



const int N = 1e5; // Maximum stones as per problem



int n, stones[N];



int memo[N]; // Memoization Table



int jumps(int ind) {

    if (ind == (n - 1)) return 0; // If we are last stone, then the answer will be 0.

    if (ind >= n) return INT_MAX; // Checking the boundary condition





    // If you are done with the whole function, then only read

    // Since we stored the minimum cost for a stone, now we will use the stored cost

    // We are initializing the table to -1, if the value stored is not -1, then we have calculated the minimum cost

    // So just return that cost

    if (memo[ind] != -1) return memo[ind]; // If reading for first time, then ignore this line



    // Calculate the cost for jumping to next stone (ind + 1) and recursively doing it for next stone

    int oneJump = abs(stones[ind] - stones[ind + 1]) + jumps(ind + 1);



    // Initializing the twoJumps because there can be a case in which there can be only one stone.

    int twoJumps = INT_MAX;



    // Checking if there are more than 2 stones

    if (ind + 2 < n) {

        // Calculate the cost for jumping to next to next stone (ind + 2) and recursively doing it for next to next stone

        twoJumps = abs(stones[ind] - stones[ind + 2]) + jumps(ind + 2);

    }



    // Storing the minimum cost in the memoization table and returning the minimum cost

    // After this,  go to the ignored line.

    return memo[ind] = min(oneJump, twoJumps);

}





int main() {

    // Initializing the memoization table to -1

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



    cin >> n;

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

        cin >> stones[i];

    }



    // We will start from first stone

    cout << jumps(0) << endl;



    return 0;

}

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

#include<cmath>

using namespace std;

const int maxn = 1e6 + 10;

int height[maxn];

long long dp[maxn];



int main(){

    int n;

    scanf("%d", &n);

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

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

    dp[1] = 0;

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

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

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

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

    return 0;

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

using namespace std;

#define ll long long

#define ull unsigned long long

#define INF 1e18

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

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

typedef vector<int> vi;

typedef vector<ll> vll;

typedef pair<int,int> pi;



#define M_PI 3.14159265358979323846



int a[100005];

const int oo = 1e9+10;

const int mod = 7901;



ll gcd(ll a, ll b){return a==0 ? b : gcd(b%a, a);}



int dp[100005];

int n;

int memo[100005];



int dpF(int i){

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

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

	

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

	if(i+2 <= n-1){

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

	}



	return memo[i] = ans;

}



void solve(){

	cin>>n;

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

	

	memset(memo, -1 , sizeof memo);

	cout << dpF(0) << '\n';

	return;

	dp[0] = 0;

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

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

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

	}

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

}

int main(){   

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

	int t=1;

	while(t--){

		solve();

	}

}

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

#include<cmath>

using namespace std;

const int maxn = 1e6 + 10;

int height[maxn];

long long dp[maxn];



int main(){

    int n;

    scanf("%d", &n);

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

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

    dp[1] = 0;

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

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

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

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

    return 0;

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

#define endl '\n'

#define ll long long

using namespace std;



const int MXN = 1e5 + 5;

int n;

int h[MXN];

int dp[MXN];



int Dp(int idx) {

    if(idx == n - 1) return 0; // caso base

    if(dp[idx] != -1) return dp[idx]; // caso dp

    int ans = Dp(idx + 1) + abs(h[idx] - h[idx + 1]);

    if(idx + 2 < n) ans = min(ans, Dp(idx + 2) + abs(h[idx] - h[idx + 2])); 

    return dp[idx] = ans; // guardar

}



int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> n;

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

        cin >> h[i];

    }

    memset(dp, -1, sizeof dp);

    cout << Dp(0) << endl;

    return 0;

}

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

#include<cmath>

using namespace std;

const int maxn = 1e6 + 10;

int height[maxn];

long long dp[maxn];



int main(){

    int n;

    scanf("%d", &n);

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

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

    dp[1] = 0;

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

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

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

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

    return 0;

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

using namespace std;



const int inf=0x3f;

int h[100005],dp[100005];



signed main()

{

	int n;

	while(cin>>n){

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

		memset(dp,inf,sizeof dp);

		

		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: 1.418727874312649x):
#include<iostream>

#include<cmath>

using namespace std;

const int maxn = 1e6 + 10;

int height[maxn];

long long dp[maxn];



int main(){

    int n;

    scanf("%d", &n);

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

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

    dp[1] = 0;

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

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

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

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

    return 0;

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

using namespace std;

int dif(int a, int b)

{

    int ans=a-b;

    if(ans<0) ans*=-1;

    return ans;

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int N, h[100005],i,j;

    int f1,f2;

    cin>>N;

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

        cin>>h[i];

    int M[100005]={0};

    M[N-2]=dif(h[N-1],h[N-2]);

    for(i=N-3;i>=0;i--)

    {

        f1=dif(h[i+1],h[i])+M[i+1];

        f2=dif(h[i+2],h[i])+M[i+2];

        M[i]=min(f1,f2);

    }

    cout<<M[0]<<endl;

    return 0;

}


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

#include<cmath>

#include<iomanip>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

int a[100005],dp[100005];

int main()

{

    ll n,i;

	cin>>n; 

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

	cin>>a[i];

	dp[1]=0;

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

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

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

	cout<<dp[n];

	return 0;

}
// 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.062677487908618x):
#include<iostream>

#include<cmath>

#include<iomanip>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

int a[100005],dp[100005];

int main()

{

    ll n,i;

	cin>>n; 

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

	cin>>a[i];

	dp[1]=0;

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

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

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

	cout<<dp[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.3872837580700046x):
#include<iostream>

#include<cmath>

#include<iomanip>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

int a[100005],dp[100005];

int main()

{

    ll n,i;

	cin>>n; 

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

	cin>>a[i];

	dp[1]=0;

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

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

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

	cout<<dp[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.4028834491117688x):
#include<iostream>

#include<cmath>

#include<iomanip>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

int a[100005],dp[100005];

int main()

{

    ll n,i;

	cin>>n; 

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

	cin>>a[i];

	dp[1]=0;

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

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

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

	cout<<dp[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.402183358886187x):
#include<iostream>

#include<cmath>

#include<iomanip>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

int a[100005],dp[100005];

int main()

{

    ll n,i;

	cin>>n; 

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

	cin>>a[i];

	dp[1]=0;

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

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

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

	cout<<dp[n];

	return 0;

}