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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

const int mod = 1e9+9;

const int nax = 1e5+3;;



int n;;

int dp[nax];

int a[nax];

int f(int i){

	if (i==n-1)

             return 0;

	if(dp[i]!=-1) 

             return dp[i];

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

	if(i!=n-2) 

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

	return dp[i]=ans;

}

int main(){



	cin>>n;



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

               cin>>a[i];;;

	memset(dp, -1, sizeof dp);



	cout<<f(0)<<endl;;

	return 0;

}

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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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



using namespace std;

int v[100010];

int memo[100010];

int c;



int f(int i)

{



    if(memo[i]!=-1)

        return memo[i];



    if(i == 0)

        return memo[0] = 0;



    if(i == 1)

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



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

}



int main()

{

    ios_base::sync_with_stdio(false);

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

    cin>>c;



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

    {

        cin>>v[i];

    }



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



    return 0;

}

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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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

using namespace std;

#define Me3za() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))

#define endl "\n"

int n;

int arr[100005];

int mem[100005];

long long solve(int i,int cur){

if(i>=n)return 1e9;

//cout<<i<<" "<<cur<<endl;

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

long long ch1=solve(i+1,arr[i+1])+abs(cur-arr[i+1]);

long long ch2=0;

if(i+2<=n)ch2=solve(i+2,arr[i+2])+abs(cur-arr[i+2]);

return mem[i]=min(ch1,ch2);

}

int main() {

Me3za();

cin>>n;

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

    cin>>arr[i];

}

memset(mem,-1,sizeof mem);

cout<<solve(0,arr[0]);

}




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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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

using namespace std;



int const N=1e5+5, M=1e9+7, OO = 0x3f3f3f3f;



int n;

int arr[N];



int mem[N];

int solve(int i)

{

    if(i==n-1)

        return 0;

    if(mem[i]!=-1)

        return mem[i];

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

    int op2=(i<=n-3) ? solve(i+2)+abs(arr[i]-arr[i+2]) : OO;

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

}





int main()

{

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

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

    scanf("%d",&n);

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

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

    memset(mem, -1, sizeof mem);

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



    return 0;

}


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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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



using namespace std;

typedef long long ll;

typedef double dd;

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

#define endl "\n"

#define clr(n, r) memset(n,r,sizeof(n));



void fast() {

    cin.tie(0);

    cin.sync_with_stdio(0);

}



const int N = 1e5 + 9;

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



int sol(int i){

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

    if(i == n)  return 1e9;



    int &ret = dp[i];

    if(~ret)    return ret;



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

}





int main() {



    cin >> n;



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



    memset(dp, -1, sizeof dp);



    cout << sol(0);

}

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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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



using namespace std;



const int N=1e5;

int n;

int arr[N];

int mem[N];



int solve(int i){

    if(i==n-1)

        return 0;

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

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

    int op2=i+2<=n-1?solve(i+2)+abs(arr[i]-arr[i+2]):1000000000;

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

}



int main() {

    scanf("%d",&n);

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

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

    memset(mem,-1,sizeof mem);

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

    return 0;

}


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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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

 

using namespace std;

 

#define sf(n) scanf("%d", &n)

#define pd(n) printf("%.12lf", n)

#define pf(n) printf("%d", n)

#define p() printf("\n")

#define ps() printf(" ")

#define ll long long

#define ull unsigned long long

#define MAX 1e9

const int mod = 1000 * 1000 * 1000 + 7;

#define ex 1e18

#define dbl 2e09

#define qu(q) queue<int> q

#define pqu(q) priority_queue<int> q

#define len(s) s.length()

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

#define pb(x) push_back(x)

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

#define rall(x) x.rbegin(), x.rend()

#define F first

#define S second

#define clr(x) x.clear()

#define LOG(x) std::cout << x << std::endl;

 

const int INF = 0x3f3f3f3f;

const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

const double PI = 3.14159265359;

 

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

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



int a[100005];

int dp[100005];

int n;

int solve(int idx){

    if(idx==(n-1))

        return 0;

    if(idx>=n)

        return INF;

    int &ret = dp[idx];

    if(~ret)

        return ret;

    ret = INF;

    ret=min(ret,solve(idx+1)+abs(a[idx+1]-a[idx]));

    ret=min(ret,solve(idx+2)+abs(a[idx+2]-a[idx]));

    return ret;

}







int main(){



    cin>>n;

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

        cin>>a[i];

    }

    memset(dp,-1,sizeof dp);

    cout<<solve(0)<<endl;

    return 0;

}

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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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

using namespace std;

int abssub(int a,int b){

	if(a>b)return a-b;

	return b-a;

}

int main(){

	int n,h[100001],bp[100001]={0};

	cin>>n; 

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

		cin>>h[i];

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

		if(i==2)bp[i]=bp[i-1]+abssub(h[i],h[i-1]);

		else{

			bp[i]=min(bp[i-1]+abssub(h[i],h[i-1]),bp[i-2]+abssub(h[i],h[i-2]));

		}

	}

	cout<<bp[n]<<endl;

	return 0;

}

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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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

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

#define ii          pair<int,int>

#define F           first

#define S           second

#define pb          push_back

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

#define rall(x)     (x).rbegin(),(x).rend()

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

#define forr(i,a)   for(int i = a; i >= 0; i--)

#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 

#define w(t)        while(t--)

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

#define cls(a,car)  memset(a,car,sizeof (a))

#define db(x)       cerr << #x << " is " << x << '\n'

#define FL          freopen("in", "r", stdin),freopen("out", "w", stdout);

#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

#define angle(x)    double(x * acos(-1) / 180.0)

using namespace std;

typedef long long   ll;

typedef vector<int> vi;

typedef vector<ii>  vii;

const int N = 1 * 1e5 + 5;

const ll mod = 1e9 + 7;

const double E = 1e-9;

//int dx[] = {1, 0}, dy[] = {0, 1};

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

//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};

// fflush(stdout)

// cout << flush

// a + b = a ^ b + 2 * (a & b)

int n, k;

int v[N];

int dp[N];

int f(int i){

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

    int &ans = dp[i];

    if(ans != -1)return ans;

    ans = 1e9;

    for(int j = 1; j <= 2; j++){

        if(i + j < n)

            ans = min(ans, f(i + j) + abs(v[i] - v[i + j]));

    }

    return ans;

}

int main(){

    //FL;

    FIN;

    cin >> n;

    fore(i, 0, n)cin >> v[i];

    cls(dp, -1);

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

    EjecuteTime;

    return 0;

}       

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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

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



#define clr(x) memset((x), 0, sizeof(x))

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

#define pb push_back

#define mp make_pair

#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)

#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)

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

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

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

#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)

#define in(x) int (x); input((x));

#define x first

#define y second

#define less(a,b) ((a) < (b) - EPS)

#define more(a,b) ((a) > (b) + EPS)

#define eq(a,b) (fabs((a) - (b)) < EPS)

#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))

#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))

#define salfinal(x) cout<<x<<endl;

using namespace std;

const int MAX =1e5+1;

int v[MAX];

int memo[MAX];

int c;



int f(int i)

{



    if(memo[i]!=-1)

        return memo[i];



    if(i == 0)

        return memo[0] = 0;



    if(i == 1)

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



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

}



int main()

{

    ios_base::sync_with_stdio(false);

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

    cin>>c;



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

    {

        cin>>v[i];

    }



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



    return 0;

}


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

#define MAXN 1e5



using namespace std;





int dp (){

}



long long n,m,a,b,c;

string s1,s2;



int main(){

    cin>>n;

    int l[n],l2[n];

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

        cin>>l[i];

        l2[i]=0;

    }

    l2[1]=abs(l[1]-l[0]);

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

        l2[i]+=min(abs( l[i] - l[i-1]) + l2[i-1] , abs ( l[i] - l[i-2] ) + l2[i-2]);

    }

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

}