stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp> 

#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace __gnu_pbds;

using namespace std;

#define getbit(n, i) (((n) & (1LL << (i))) != 0) 

#define setbit0(n, i) ((n) & (~(1LL << (i)))) 

#define setbit1(n, i) ((n) | (1LL << (i))) 

#define togglebit(n, i) ((n) ^ (1LL << (i))) 

#define lastone(n) ((n) & (-(n))) 

char gap = 32;

template<typename T> 

ostream& operator<<(ostream &os, const vector<T> &v) { 

    os << '{'; 

    for (const auto &x : v) os << gap << x;

        return os << '}'; 

}

template<typename A, typename B> 

ostream& operator<<(ostream &os, const pair<A, B> &p) {

        return os << '(' << p.first << gap << p.second << ')';

}



template <class T>

void read(T &x) {

    char c;

    for (c = getchar(); c < '0' || c > '9'; c = getchar())

        ;

    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);

}

#define ll long long 

#define lll __int128_t

#define pb push_back

#define mp make_pair

typedef pair < int,int> ii;

typedef vector<ii> vii;

typedef vector<ll>vl;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef tree<

int,

null_type,

less<int>,

rb_tree_tag,

tree_order_statistics_node_update>

ordered_set;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll hashPrime = 1610612741;



int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    ll n, i, j, k, l;

    cin >> n;

    vector<ll> Data(n + 1, 0);

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

        cin >> Data[i];

    }

    vector<ll> Dp(n + 1, 0);

    Dp[1] = 0;

    Dp[2] = abs(Data[1] - Data[2]);

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

        Dp[i] = min(Dp[i - 1] + abs(Data[i - 1]- Data[i]), Dp[i - 2] + abs(Data[i - 2] - Data[i]));

    }

    cout << Dp[n];

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int h[100005];



int abse(int n)

{

    if(n<0) return -n;

    return n;

}

int solve(int i,int n,int dp[])

{

    if(i==n-2)return dp[i]= abse(h[n-2]-h[n-1]);

    if(i>n-2)  return dp[i]= 0;

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

    return dp[i]=min(abse(h[i+1]-h[i])+solve(i+1,n,dp),abse(h[i+2]-h[i])+solve(i+2,n,dp)) ;



}

int main(void)

{

    int n,i;

    cin>>n;

    int dp[n+5];

    memset(dp,-1,sizeof dp);

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

        cin>>h[i];

    cout<<solve(0,n,dp);

}




// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream> 

using namespace std;



int main(){

    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    int h[n];

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

        cin >> h[i];

    int dp[n];

    dp[0] = 0;

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

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

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

    }

    cout << dp[n-1];

}

// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int main()

{

    int N;

    cin >> N;

    vector<int> cost(N+1);

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

        cin >> cost[i];

    int INF = 1e6 + 5;

    vector<int>dp(N+1,INF);

    dp[1] = 0;



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

    {

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

    }



    cout << dp[N];

    return 0;





}

// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define inf INFINITY

#define file freopen( "input.txt" , "r" , stdin) ; freopen( "output.txt" , "w" , stdout) ;

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

#define _3102_ main()

#define endl '\n'

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

using namespace std;

const int N = 1e5 + 100;

const ll MX = 1e9;

const ll mod = 1e9 + 7;

const double eps = 1e-9 ;





int _3102_{

	Gamed

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

	cin >> n ;

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

		cin >> h[i] ;

	}

	dp[0] = 0 ;

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

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

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

	}

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

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define ll long long int

main(){

    int n;

    cin>>n;

    int a[n];

    ll b[n];

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

    b[0]=0;

    if(n>1) b[1]=abs(a[0]-a[1]);

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

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

    }

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

}

// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define si(a) scanf("%d", &a)

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

#define N_MAX 100005

using namespace std;

typedef long long ll;

typedef pair<int,int> pi;

typedef vector<int> vi;

int n,k;

vi v;

vi dp;

void leer(){

    si(n); 

    //si(k);//B

    k=2; //A

    v.assign(n+1,0);

    dp.assign(n+1,INT_MAX);

    fore(i,1,n+1)

        si(v[i]);

    int x;

    x = v[1];

    if(k>n)

        k = n;

    fore(i,1,k+1)

        dp[i] = abs(x-v[i]);

    fore(i,k+1,n+1){

        fore(j,1,k+1){

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

        }

    }

}

void solve(){

	leer();

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

}

int main(){

	solve();

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define MAXN 100000



int h[MAXN];

int dp[MAXN];

int n;



int main() {

	int i;

	scanf("%d",&n);

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

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

	}

	dp[n-1]=0;

	dp[n-2]=abs(h[n-1]-h[n-2]);

	for (i=n-3; i>=0; i--) {

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

	}

	

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

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define f first

#define s second

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

#define pb push_back

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

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

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

#define ENDL '\n'

using namespace std;

typedef long double ld;

typedef long long lli;

typedef pair<lli,lli> ii;

#define deb(x) cout << #x": " << (x) << endl;



int main(){ _

  lli n;

  cin >> n;

  vector <lli> a(n);

  lli x;

  fore (i,0,n){

    cin >> x;

    a[i] = x;

  }

  vector <lli> b(n);

  b[0] = 0;

  b[1] = abs(a[0] - a[1]) + b[0];

  fore (i,2,n){

    if ((abs(a[i - 1] - a[i]) + b[i - 1]) < (abs(a[i - 2] - a[i]) + b[i - 2])){

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

    }

    else{

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

    }

  }

  cout << b[n - 1] << ENDL;

  return 0;

}

// Hola, si estás viendo esto te notifico que te detuviste a leer mi código.

// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define endl '\n'

#define ll long long

using namespace std;



const int MXN = 1e5 + 5;

int n;

int h[MXN];

int dp[MXN];



int Dp(int idx) {

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

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

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

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

    return dp[idx] = ans; // guardar

}



int main() {

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

    cin >> n;

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

        cin >> h[i];

    }

    // memset(dp, -1, sizeof dp);

    // cout << Dp(0) << endl;

    for(int i = n - 2; i >= 0; i--) {

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

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

    }

    cout << dp[0] << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define ll long long

#define pb push_back

#define popb pop_back

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

#define dic unordered_map //Diccionario

#define bpc __builtin_popcountll //numero de bits para long long

#define bclz __builtin_clzll //leading zeros

 

using namespace std;

 

//Funtions here

int main () {

	ios::sync_with_stdio(false);

	cin.tie(0);

	int n;

	cin>>n;

	vector<int> a(n);

	vector<int> dp(n,INT_MAX);

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

	dp[0]=0;

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

		if(i+1<n) dp[i+1]=min(dp[i+1],dp[i]+abs(a[i+1]-a[i]));

		if(i+2<n) dp[i+2]=min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));

	}

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

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cmath>

using namespace std;

int h[100005];

int dp[100005];

int main()

{

	int n;

	cin>>n;

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

	cin>>h[i];

	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;

}

// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

#include<cmath>

#include<cstdlib>

#include<cstdio>

#include<cstring>

#include<iomanip>

#include<string>

#include<set>

#include<map>

#include<vector>

#include<queue>

#include<stack>

#include<utility>

#define PI acos(-1.0)

using namespace std;

int main() {

	int n;

	cin >> n;

	vector<int> a(n + 1);

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

	vector<int> dp(n + 1,0);

	a[0] = a[1];

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

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

	}

	cout << dp[n] << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

const int N=1e5+5;

int v[N],memo[N];

int main(){

	int n;cin>>n;

	if(n==2){

		int x,y;cin>>x>>y;

		cout<<abs(x-y);return 0;

	}

	long long ans=0LL;



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

		cin>>v[i];

		if(i==1)memo[i]=0;	

		else if(i==2)memo[i]=abs(v[i]-v[i-1]);

		

		else{

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

		}

	}

	cout<<memo[n];

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int N;

int main(){

	cin >> N;

	int arr[N];

	int mem[N];

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

		cin >> arr[i];

	mem[0] = 0;

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

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

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

	cout << mem[N-1] << "\n";

}


// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

 

int main() {

	int n; 

	cin>>n;

	vector<int> arr(n), dp(n);

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

	dp[0]=0;

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

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

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

	}

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

	

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#include <cstdlib>

using namespace std;

int main()

{

    long long n,i;

    static long long ara[100002],t[100002];

    cin>>n;

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

        cin>>ara[i];

    t[0]=0;

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

    {

        if(i==1)

            t[i]=abs(ara[i]-ara[i-1]);

        else

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

    }

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

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

  for(int i=3;i<=s;i++){

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

const int maxn=100000+10;

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

int main()

{

	cin>>n;

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

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

	dp[1]=0;

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

	{

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

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

	}

	cout<<dp[n]<<endl;

	return 0;

}

//Phoenix-ZH

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define ll long long

using namespace std;



int dp[100005], a[100005];

int n;



int main()

{

    cin>>n;

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

        cin>>a[i];



    dp[1]=0;

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

    {

        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;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>





using namespace std;

int n;

vector<int> vec;



int meme[100007];



int solve(int index){



    if(index==n-1){

        return 0;

    }

    if(meme[index]!=-1){

        return meme[index];

    }

    

    int ret1 = 100000000;

    int ret2 = 100000000;

    if(index+1<n){

         ret1 = abs (vec[index]- vec[index+1]) + solve(index+1); 

    }

    if(index+2<n){

         ret2 = abs (vec[index]- vec[index+2]) + solve(index+2); 

    }





    return meme[index] = min(ret1,ret2);

}



int main(){

    cin>>n;

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

    int num;

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

        cin>>num;

        vec.push_back(num);

    }

    cout<<solve(0)<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define ll long long

using namespace std;



int dp[100005], a[100005];

int n;



int main()

{

    cin>>n;

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

        cin>>a[i];



    dp[1]=0;

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

    {

        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;

}




// Fastest known solution for this problem: