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

using namespace std;



vector<long long> altura;



long long dp[100005];

int n;

long long solve(int atual){

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

    if(atual < n-2){

        dp[atual] = min(abs(altura[atual] - altura[atual+1]) + solve(atual+1), abs(altura[atual] - altura[atual+2]) + solve(atual+2));

    }else if(atual == n-2){

        dp[atual] = abs(altura[atual] - altura[atual+1]);

    }else{

        dp[atual] = 0;

    }

    return dp[atual];

}



int main() {

    cin >> n;

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

        long long v;

        cin >> v;

        altura.push_back(v);

        dp[i] = -1;

    }

    cout << solve(0) << endl;

    return 0;

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

using namespace std;



vector<long long> altura;



long long dp[100005];

int n;

long long solve(int atual){

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

    if(atual < n-2){

        dp[atual] = min(abs(altura[atual] - altura[atual+1]) + solve(atual+1), abs(altura[atual] - altura[atual+2]) + solve(atual+2));

    }else if(atual == n-2){

        dp[atual] = abs(altura[atual] - altura[atual+1]);

    }else{

        dp[atual] = 0;

    }

    return dp[atual];

}



int main() {

    cin >> n;

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

        long long v;

        cin >> v;

        altura.push_back(v);

        dp[i] = -1;

    }

    cout << solve(0) << endl;

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

using namespace std;



vector<long long> altura;



long long dp[100005];

int n;

long long solve(int atual){

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

    if(atual < n-2){

        dp[atual] = min(abs(altura[atual] - altura[atual+1]) + solve(atual+1), abs(altura[atual] - altura[atual+2]) + solve(atual+2));

    }else if(atual == n-2){

        dp[atual] = abs(altura[atual] - altura[atual+1]);

    }else{

        dp[atual] = 0;

    }

    return dp[atual];

}



int main() {

    cin >> n;

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

        long long v;

        cin >> v;

        altura.push_back(v);

        dp[i] = -1;

    }

    cout << solve(0) << endl;

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

using namespace std;



vector<long long> altura;



long long dp[100005];

int n;

long long solve(int atual){

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

    if(atual < n-2){

        dp[atual] = min(abs(altura[atual] - altura[atual+1]) + solve(atual+1), abs(altura[atual] - altura[atual+2]) + solve(atual+2));

    }else if(atual == n-2){

        dp[atual] = abs(altura[atual] - altura[atual+1]);

    }else{

        dp[atual] = 0;

    }

    return dp[atual];

}



int main() {

    cin >> n;

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

        long long v;

        cin >> v;

        altura.push_back(v);

        dp[i] = -1;

    }

    cout << solve(0) << endl;

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

using namespace std;



vector<long long> altura;



long long dp[100005];

int n;

long long solve(int atual){

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

    if(atual < n-2){

        dp[atual] = min(abs(altura[atual] - altura[atual+1]) + solve(atual+1), abs(altura[atual] - altura[atual+2]) + solve(atual+2));

    }else if(atual == n-2){

        dp[atual] = abs(altura[atual] - altura[atual+1]);

    }else{

        dp[atual] = 0;

    }

    return dp[atual];

}



int main() {

    cin >> n;

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

        long long v;

        cin >> v;

        altura.push_back(v);

        dp[i] = -1;

    }

    cout << solve(0) << endl;

    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: 2.5535293785147415x):
/* Ajay Jadhav */

#include <bits/stdc++.h>

 

#define ll          long long

#define pb          push_back

#define pii         pair<int,int>

#define vi          vector<int>

#define vii         vector<pii>

#define mi          map<int,int>

#define mii         map<pii,int>

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

#define x           first

#define y           second

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

#define endl        '\n'

#define hell        1000000007

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

using namespace std;



void solve()

{

    int n;

    cin>>n;

    vi a(n);

    rep(i,0,n) cin>>a[i];

    vi dp(n);

    dp[0]=0;

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

    rep(i,2,n)

    {

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

    }

    cout<<dp[n-1];

}

 

signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t=1;

    // cin>>t;

    while(t--)

    {

        solve();

    }

    return 0;

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

using namespace std;

typedef long long int ll;

const int MAX=1e5+10;

int N,A[MAX],dp[MAX];

int solve(int idx)

{

    if(idx==N)return 0;

    if(idx>N)return 1e9;

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

    return dp[idx]=min(abs(A[idx+1]-A[idx])+solve(idx+1),abs(A[idx+2]-A[idx])+solve(idx+2));

}

int  main ()

{

    memset(dp,-1,sizeof dp);

    cin >> N;

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

        cin >> A[i];

    }

    cout<<solve(1)<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.3762228948393038x):
/* Ajay Jadhav */

#include <bits/stdc++.h>

 

#define ll          long long

#define pb          push_back

#define pii         pair<int,int>

#define vi          vector<int>

#define vii         vector<pii>

#define mi          map<int,int>

#define mii         map<pii,int>

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

#define x           first

#define y           second

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

#define endl        '\n'

#define hell        1000000007

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

using namespace std;



void solve()

{

    int n;

    cin>>n;

    vi a(n);

    rep(i,0,n) cin>>a[i];

    vi dp(n);

    dp[0]=0;

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

    rep(i,2,n)

    {

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

    }

    cout<<dp[n-1];

}

 

signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t=1;

    // cin>>t;

    while(t--)

    {

        solve();

    }

    return 0;

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

using namespace std;



#define mp make_pair

#define pb push_back

#define st first

#define nd second

#define lb lower_bound

#define ub upper_bound



typedef long long ll;

typedef long double ld;

typedef pair<int,int> pi;

typedef pair<ll,ll> pll;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef vector<pi> vpi;

typedef vector<pll> vpll;



const ll oo=1e18;

const int MOD=1000000007;

const int INF=1000000000;

const ld EPS=0.000000001;



int dp[100005],h[100005],n,k=2;



signed main() {

    ios_base::sync_with_stdio(NULL);

    cin.tie(NULL);

    cout.tie(NULL);

    memset(dp,0x3f3f,sizeof dp);

    dp[1]=0;

    h[0]=0;

    cin>>n;

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

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

        for(int j=1;j<=min(k,i);++j) {

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

        }

    }

    cout<<dp[n];

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.3963658466467614x):
/* Ajay Jadhav */

#include <bits/stdc++.h>

 

#define ll          long long

#define pb          push_back

#define pii         pair<int,int>

#define vi          vector<int>

#define vii         vector<pii>

#define mi          map<int,int>

#define mii         map<pii,int>

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

#define x           first

#define y           second

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

#define endl        '\n'

#define hell        1000000007

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

using namespace std;



void solve()

{

    int n;

    cin>>n;

    vi a(n);

    rep(i,0,n) cin>>a[i];

    vi dp(n);

    dp[0]=0;

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

    rep(i,2,n)

    {

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

    }

    cout<<dp[n-1];

}

 

signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t=1;

    // cin>>t;

    while(t--)

    {

        solve();

    }

    return 0;

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

#include<iostream>

#include<cmath>

#include<stack>

#include<cstring>

#include<algorithm>

using namespace std;

int n;

int h[100005];

int dp[100005];



int main()

{

memset(dp, 0x3f ,sizeof dp);

scanf("%d",&n);

for( int i = 1 ; i <= n ; i++) scanf("%d",&h[i]);

dp[1] = 0;

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

{

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

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

}

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



	return 0;

}






// Faster C++ solution for the same problem (measured speedup: 1.3717552286873516x):
/* Ajay Jadhav */

#include <bits/stdc++.h>

 

#define ll          long long

#define pb          push_back

#define pii         pair<int,int>

#define vi          vector<int>

#define vii         vector<pii>

#define mi          map<int,int>

#define mii         map<pii,int>

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

#define x           first

#define y           second

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

#define endl        '\n'

#define hell        1000000007

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

using namespace std;



void solve()

{

    int n;

    cin>>n;

    vi a(n);

    rep(i,0,n) cin>>a[i];

    vi dp(n);

    dp[0]=0;

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

    rep(i,2,n)

    {

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

    }

    cout<<dp[n-1];

}

 

signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t=1;

    // cin>>t;

    while(t--)

    {

        solve();

    }

    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: 2.5686572127551064x):
/* Ajay Jadhav */

#include <bits/stdc++.h>

 

#define ll          long long

#define pb          push_back

#define pii         pair<int,int>

#define vi          vector<int>

#define vii         vector<pii>

#define mi          map<int,int>

#define mii         map<pii,int>

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

#define x           first

#define y           second

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

#define endl        '\n'

#define hell        1000000007

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

using namespace std;



void solve()

{

    int n;

    cin>>n;

    vi a(n);

    rep(i,0,n) cin>>a[i];

    vi dp(n);

    dp[0]=0;

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

    rep(i,2,n)

    {

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

    }

    cout<<dp[n-1];

}

 

signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t=1;

    // cin>>t;

    while(t--)

    {

        solve();

    }

    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.7922707523988088x):
/* Ajay Jadhav */

#include <bits/stdc++.h>

 

#define ll          long long

#define pb          push_back

#define pii         pair<int,int>

#define vi          vector<int>

#define vii         vector<pii>

#define mi          map<int,int>

#define mii         map<pii,int>

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

#define x           first

#define y           second

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

#define endl        '\n'

#define hell        1000000007

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

using namespace std;



void solve()

{

    int n;

    cin>>n;

    vi a(n);

    rep(i,0,n) cin>>a[i];

    vi dp(n);

    dp[0]=0;

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

    rep(i,2,n)

    {

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

    }

    cout<<dp[n-1];

}

 

signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t=1;

    // cin>>t;

    while(t--)

    {

        solve();

    }

    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.7893474761156305x):
/* Ajay Jadhav */

#include <bits/stdc++.h>

 

#define ll          long long

#define pb          push_back

#define pii         pair<int,int>

#define vi          vector<int>

#define vii         vector<pii>

#define mi          map<int,int>

#define mii         map<pii,int>

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

#define x           first

#define y           second

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

#define endl        '\n'

#define hell        1000000007

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

using namespace std;



void solve()

{

    int n;

    cin>>n;

    vi a(n);

    rep(i,0,n) cin>>a[i];

    vi dp(n);

    dp[0]=0;

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

    rep(i,2,n)

    {

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

    }

    cout<<dp[n-1];

}

 

signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t=1;

    // cin>>t;

    while(t--)

    {

        solve();

    }

    return 0;

}
// 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.3808745405434844x):
/* Ajay Jadhav */

#include <bits/stdc++.h>

 

#define ll          long long

#define pb          push_back

#define pii         pair<int,int>

#define vi          vector<int>

#define vii         vector<pii>

#define mi          map<int,int>

#define mii         map<pii,int>

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

#define x           first

#define y           second

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

#define endl        '\n'

#define hell        1000000007

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

using namespace std;



void solve()

{

    int n;

    cin>>n;

    vi a(n);

    rep(i,0,n) cin>>a[i];

    vi dp(n);

    dp[0]=0;

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

    rep(i,2,n)

    {

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

    }

    cout<<dp[n-1];

}

 

signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t=1;

    // cin>>t;

    while(t--)

    {

        solve();

    }

    return 0;

}