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

#include <bitset>

using namespace std;

#define ll long long

#define mod 1000000009



// يلعن ابو الي يعقدها على نفسه تاني



int main()

{

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



    ll n; cin >> n;

    ll arr[100005];

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

        cin >> arr[i];

    }

    if(n == 2){

        cout << abs(arr[1]-arr[0]);

    }else{

        ll sol[100005] = {};

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

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

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

        }









        cout << sol[n-1];

    }















    return 0;

}

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

using namespace std;

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

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

#define rlp(i, n) for(int i = n-1; i >= 0; i--)

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

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

#define mem(a, val) memset(a, val, sizeof a);

#define test int t; cin>> t; while(t--)

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

#define ll long long

#define ld long double

#define mp_ make_pair

#define pb push_back

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

const int MAX = 1e5 + 5;

const int inf = 1e9+1;

const ll OO = 1e18;

typedef vector<int> vi;

typedef vector<string> vs;

typedef pair<int,int> pii;

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

int solve(int i = 0){

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



    if(dp[i] < 1e9) return dp[i];



    int choice1 = inf, choice2 = inf;



    if(i + 1 < n)

        choice1 = solve(i + 1) + abs(a[i + 1] - a[i]); // 20 10 20 // 20 10 0



    if(i + 2 < n)

        choice2 = solve(i + 2) + abs(a[i + 2] - a[i]); // 30 20



    return dp[i] = min(choice1, choice2);

}

int main()

{

    cin>> n;

    lp(i, n)

        cin>> a[i];



    mem(dp, 63);

    cout<< solve() <<"\n";



    return 0;

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

#include<bits/stdc++.h>

#include<iostream>

#include<algorithm>

#include<iomanip>

#include<string>

#include<cmath>

#include<vector>

#include<set>

#include<queue>

#include<stack>

#include<fstream>

#include<map>

#include<bitset>

#include<unordered_map>

#include<cstring>

#include<cctype>

using namespace std;

#define  ll long long

#define  ull unsigned long long

#define  ul unsigned long

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

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

#define pb(s) push_back(s);

#define format(n) fixed<<setprecision(n)

#define finl "\n"

#define Mohammed_Atef_Hassan fast();

#define mod 1000000007

#define INF LLONG_MAX

#define PI acos(-1)

#define clr(dp,n) memset(dp,n,sizeof dp)

#define ex(n) return cout<<n<<finl,0;

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

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

ll fix_mod(ll x, ll y)

{

	return (y + x % y) % y;

}

void fast() {

	std::ios_base::sync_with_stdio(false);

	cin.tie(nullptr); cout.tie(nullptr);





}

int n;

vector<ll>v;

ll mem[(int)1e5 + 10];

ll solve(int i)

{

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

	ll& ret = mem[i];

	if (~ret)return ret;

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

	if (i + 2 < n)

		ret = min(ret, solve(i + 2) + abs(v[i + 2] - v[i]));

	return ret;

}

int main()

{

	Mohammed_Atef_Hassan

		clr(mem, -1);

		cin >> n;

	v = vector<ll>(n);

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

	ex(solve(0));

}

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

using namespace std;

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

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

#define rlp(i, n) for(int i = n-1; i >= 0; i--)

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

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

#define mem(a, val) memset(a, val, sizeof a);

#define test int t; cin>> t; while(t--)

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

#define ll long long

#define ld long double

#define mp_ make_pair

#define pb push_back

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

const int MAX = 1e5 + 5;

const int inf = 1e9+1;

const ll OO = 1e18;

typedef vector<int> vi;

typedef vector<string> vs;

typedef pair<int,int> pii;

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

int solve(int i = 0){

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



    if(dp[i] < 1e9) return dp[i];



    int choice1 = inf, choice2 = inf;



    if(i + 1 < n)

        choice1 = solve(i + 1) + abs(a[i + 1] - a[i]); // 20 10 20 // 20 10 0



    if(i + 2 < n)

        choice2 = solve(i + 2) + abs(a[i + 2] - a[i]); // 30 20



    return dp[i] = min(choice1, choice2);

}

int main()

{

    cin>> n;

    lp(i, n)

        cin>> a[i];



    mem(dp, 63);

    cout<< solve() <<"\n";



    return 0;

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

#include <sstream>

using namespace std;

#include <bits/stdc++.h>

#include<utility>

#include <algorithm>

#include<iterator>

#define  go return 0

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

#define rep(j,m) for(int j=0;j<m;++j)

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

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

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

#define F first

#define S second

#define pb push_back

#define pf push_front

#define mp make_pair

typedef long long ll;

typedef double db;

typedef vector<ll> ve;

typedef vector< vector <int> >vee;

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

typedef set<char>se;

typedef map<ll,ll> mpp;

const ll N=1e5+5;

bool f;

ll n,arr[N],dp[N];

ll solve(ll i=0)

{

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

  ll &ret=dp[i];

  if(~ret)return ret;

   return ret=min(solve(i+1)+abs(arr[i]-arr[i+1]) ,i+2<n? solve(i+2)+abs(arr[i]-arr[i+2]):12345 );

}

int main()

{

ios::sync_with_stdio(0);

cin.tie(0);

   cin>>n;

   memset(dp,-1,sizeof dp);

   rep(i,n)

    cin>>arr[i];

   cout<<solve();



go;

}


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

using namespace std;

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

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

#define rlp(i, n) for(int i = n-1; i >= 0; i--)

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

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

#define mem(a, val) memset(a, val, sizeof a);

#define test int t; cin>> t; while(t--)

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

#define ll long long

#define ld long double

#define mp_ make_pair

#define pb push_back

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

const int MAX = 1e5 + 5;

const int inf = 1e9+1;

const ll OO = 1e18;

typedef vector<int> vi;

typedef vector<string> vs;

typedef pair<int,int> pii;

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

int solve(int i = 0){

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



    if(dp[i] < 1e9) return dp[i];



    int choice1 = inf, choice2 = inf;



    if(i + 1 < n)

        choice1 = solve(i + 1) + abs(a[i + 1] - a[i]); // 20 10 20 // 20 10 0



    if(i + 2 < n)

        choice2 = solve(i + 2) + abs(a[i + 2] - a[i]); // 30 20



    return dp[i] = min(choice1, choice2);

}

int main()

{

    cin>> n;

    lp(i, n)

        cin>> a[i];



    mem(dp, 63);

    cout<< solve() <<"\n";



    return 0;

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

using namespace std;



vector<long long int> dp(100005,-1);

long long int n,ara[100005];

int f(long long int i){



    if(i==n) return 0;



    if(i==n-1) return abs(ara[i+1]-ara[i]);



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



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

    return dp[i];





}









int main()

{

    long long int i;

    cin>>n;

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

        scanf("%lld",&ara[i]);

    }



    cout<<f(1)<<endl;



    return 0;

}


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

using namespace std;

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

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

#define rlp(i, n) for(int i = n-1; i >= 0; i--)

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

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

#define mem(a, val) memset(a, val, sizeof a);

#define test int t; cin>> t; while(t--)

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

#define ll long long

#define ld long double

#define mp_ make_pair

#define pb push_back

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

const int MAX = 1e5 + 5;

const int inf = 1e9+1;

const ll OO = 1e18;

typedef vector<int> vi;

typedef vector<string> vs;

typedef pair<int,int> pii;

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

int solve(int i = 0){

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



    if(dp[i] < 1e9) return dp[i];



    int choice1 = inf, choice2 = inf;



    if(i + 1 < n)

        choice1 = solve(i + 1) + abs(a[i + 1] - a[i]); // 20 10 20 // 20 10 0



    if(i + 2 < n)

        choice2 = solve(i + 2) + abs(a[i + 2] - a[i]); // 30 20



    return dp[i] = min(choice1, choice2);

}

int main()

{

    cin>> n;

    lp(i, n)

        cin>> a[i];



    mem(dp, 63);

    cout<< solve() <<"\n";



    return 0;

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

#define ll long long

using namespace std;

#define inf 0x3f3f3f3f 

int main(){

	ll t , h[100001] , dp[100001] = {0};

    cin >> t;

	for(int i = 0 ; i < t ; ++i) scanf("%lld",h+i);

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

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

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

        cout<<dp[t-1];

}

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

using namespace std;

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

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

#define rlp(i, n) for(int i = n-1; i >= 0; i--)

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

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

#define mem(a, val) memset(a, val, sizeof a);

#define test int t; cin>> t; while(t--)

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

#define ll long long

#define ld long double

#define mp_ make_pair

#define pb push_back

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

const int MAX = 1e5 + 5;

const int inf = 1e9+1;

const ll OO = 1e18;

typedef vector<int> vi;

typedef vector<string> vs;

typedef pair<int,int> pii;

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

int solve(int i = 0){

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



    if(dp[i] < 1e9) return dp[i];



    int choice1 = inf, choice2 = inf;



    if(i + 1 < n)

        choice1 = solve(i + 1) + abs(a[i + 1] - a[i]); // 20 10 20 // 20 10 0



    if(i + 2 < n)

        choice2 = solve(i + 2) + abs(a[i + 2] - a[i]); // 30 20



    return dp[i] = min(choice1, choice2);

}

int main()

{

    cin>> n;

    lp(i, n)

        cin>> a[i];



    mem(dp, 63);

    cout<< solve() <<"\n";



    return 0;

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

using namespace std;

#define INF 100005

#define maxx 1000000000000



int n;

long long a[INF+5];

long long mem[INF];



long long rec(int pos)

{

    if(pos==n-1)

    {

        return 0;

    }

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

    long long tot=maxx;

    long long left=abs(a[pos]-a[pos+1]);

    long long right=abs(a[pos]-a[pos+2]);

    if(pos+1<n)

    {

        tot=min(tot,left+rec(pos+1));

    }

    if(pos+2<n)

    {

        tot=min(tot,right+rec(pos+2));

    }

    return mem[pos]=tot;

}



int main()

{

    memset(a,0,sizeof(a));

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

    scanf("%d",&n);

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

    {

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

    }

    long long ans=rec(0);

    printf("%lld\n",ans);

}


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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

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

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int arr[N], n, memo[N], res;



int Solve(int idx){



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

    int op1 = OO, op2 = OO;

    if(idx + 1 >= n)    return 0;

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

    if(idx + 2 < n)

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



    return memo[idx] = min(op1, op2);

}



int main() {

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

//    freopen("output.txt", "w", stdout);

    GO();

    scanf("%d", &n);

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

        scanf("%d", arr+i);

    }

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

    printf("%d", Solve(0));

    return 0;

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

#include<cstdio>

#include<string>

#include<cstring>

#include<algorithm>

#include<queue>

#include<stack>

#include<map>

#include<vector>

#include<set>

#include<list>

#define ll long long

using namespace std;

ll h[200050],dp[200050];

int main()

{

	ll n;

	cin>>n;

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

		cin>>h[i];

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

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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

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

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int arr[N], n, memo[N], res;



int Solve(int idx){



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

    int op1 = OO, op2 = OO;

    if(idx + 1 >= n)    return 0;

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

    if(idx + 2 < n)

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



    return memo[idx] = min(op1, op2);

}



int main() {

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

//    freopen("output.txt", "w", stdout);

    GO();

    scanf("%d", &n);

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

        scanf("%d", arr+i);

    }

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

    printf("%d", Solve(0));

    return 0;

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



using namespace std;

const int maxn = 2e5+2;

const int mod = 1e9+7;

const int inf = 1e9;



typedef long long ll;



int n;

int arr[maxn], dp[maxn];



int solve_dp (int pos){

    if (pos > n) return inf;

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



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



    int ans = inf;

    ans = min(ans, solve_dp(pos + 1) + abs(arr[pos + 1] - arr[pos]));

    ans = min(ans, solve_dp(pos + 2) + abs(arr[pos + 2] - arr[pos]));



    return dp[pos] = ans;

}



int main(){



    ios_base::sync_with_stdio(0);

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



    cin >> n;



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

        cin >> arr[i];

    }



    memset(dp, -1, sizeof dp);



    cout << solve_dp(0) << "\n";



    return 0;

}


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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

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

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int arr[N], n, memo[N], res;



int Solve(int idx){



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

    int op1 = OO, op2 = OO;

    if(idx + 1 >= n)    return 0;

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

    if(idx + 2 < n)

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



    return memo[idx] = min(op1, op2);

}



int main() {

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

//    freopen("output.txt", "w", stdout);

    GO();

    scanf("%d", &n);

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

        scanf("%d", arr+i);

    }

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

    printf("%d", Solve(0));

    return 0;

}
// Slower C++ solution:
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

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

typedef long long ll;

using namespace std;

ll n , arr[100005] , memo[100005];

ll solve(ll i)

{

	if(i == n - 1)

		return 0;

	ll &ans = memo[i];

	if(~ans)

		return ans;

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

	if(i < n - 2)

		ans = min(ans , abs(arr[i] - arr[i + 2]) + solve(i + 2));

	return ans;

}

int main()

{

	abdelrahman010

	cin >> n;

	memset(memo , -1 , sizeof memo);

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

		cin >> arr[i];

	cout << solve(0);

	return 0;

}


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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

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

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int arr[N], n, memo[N], res;



int Solve(int idx){



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

    int op1 = OO, op2 = OO;

    if(idx + 1 >= n)    return 0;

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

    if(idx + 2 < n)

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



    return memo[idx] = min(op1, op2);

}



int main() {

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

//    freopen("output.txt", "w", stdout);

    GO();

    scanf("%d", &n);

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

        scanf("%d", arr+i);

    }

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

    printf("%d", Solve(0));

    return 0;

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

#include<stdio.h>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

#define maxn 100005

int dp[maxn];

int h[maxn];

int n;

int main(){

    scanf("%d",&n);

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

    memset(h,0,sizeof(h));

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

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

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

        if(i-1>=1&&i-2>=1)

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

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

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

    }

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

    return 0;

}


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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

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

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int arr[N], n, memo[N], res;



int Solve(int idx){



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

    int op1 = OO, op2 = OO;

    if(idx + 1 >= n)    return 0;

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

    if(idx + 2 < n)

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



    return memo[idx] = min(op1, op2);

}



int main() {

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

//    freopen("output.txt", "w", stdout);

    GO();

    scanf("%d", &n);

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

        scanf("%d", arr+i);

    }

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

    printf("%d", Solve(0));

    return 0;

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

#include <bitset>

using namespace std;

#define ll long long

#define mod 1000000009



// يلعن ابو الي يعقدها على نفسه تاني



int main()

{

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



    ll n; cin >> n;

    ll arr[100005];

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

        cin >> arr[i];

    }

    if(n == 2){

        cout << abs(arr[1]-arr[0]);

    }else{

        ll sol[100005] = {};

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

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

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

        }









        cout << sol[n-1];

    }















    return 0;

}

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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

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

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int arr[N], n, memo[N], res;



int Solve(int idx){



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

    int op1 = OO, op2 = OO;

    if(idx + 1 >= n)    return 0;

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

    if(idx + 2 < n)

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



    return memo[idx] = min(op1, op2);

}



int main() {

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

//    freopen("output.txt", "w", stdout);

    GO();

    scanf("%d", &n);

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

        scanf("%d", arr+i);

    }

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

    printf("%d", Solve(0));

    return 0;

}