stablegradients/pie-gem5-pairs huggingface dataset:
// 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.3983043484432631x):
#include<bits/stdc++.h>

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

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

#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

#define FAST()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

            a = abs(ar[i] - ar[i-1]) + DP[i-1];

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

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

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



}
// 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.3983043484432631x):
#include<bits/stdc++.h>

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

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

#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

#define FAST()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

            a = abs(ar[i] - ar[i-1]) + DP[i-1];

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

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

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



}
// 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.3778721906738887x):
#include<bits/stdc++.h>

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

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

#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

#define FAST()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

            a = abs(ar[i] - ar[i-1]) + DP[i-1];

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

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

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



}
// 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.3825970107722838x):
#include<bits/stdc++.h>

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

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

#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

#define FAST()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

            a = abs(ar[i] - ar[i-1]) + DP[i-1];

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

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

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



}
// 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.782602084071377x):
#include<bits/stdc++.h>

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

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

#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

#define FAST()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

            a = abs(ar[i] - ar[i-1]) + DP[i-1];

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

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

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



}
// 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.381013426928452x):
#include<bits/stdc++.h>

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

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

#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

#define FAST()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

            a = abs(ar[i] - ar[i-1]) + DP[i-1];

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

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

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



}
// 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.7779884718136754x):
#include<bits/stdc++.h>

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

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

#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

#define FAST()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

            a = abs(ar[i] - ar[i-1]) + DP[i-1];

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

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

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



}
// 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.1760215653192243x):
#include<bits/stdc++.h>

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

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

#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

#define FAST()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

            a = abs(ar[i] - ar[i-1]) + DP[i-1];

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

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

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



}
// 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.3805118949236794x):
#include<bits/stdc++.h>

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

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

#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

#define FAST()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

            a = abs(ar[i] - ar[i-1]) + DP[i-1];

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

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

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



}
// 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.3873397576944824x):
#include<bits/stdc++.h>

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

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

#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

#define FAST()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

            a = abs(ar[i] - ar[i-1]) + DP[i-1];

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

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

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



}