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



#define ll long long

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

#define pb push_back

const long double pi=3.141592654;

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

using namespace std;



const ll inf = 1e9 +5, mod = 1e9+7,N = 1e5+5;





int main()

{

    OSOS

	int n;

    cin>>n;

    int arr[n];

    lp(i,n)cin>>arr[i];

    int dp[n];

    dp[0] = 0;

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

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

    {

    	ll o1,o2;

    	o1 = dp[i-2]+abs(arr[i-2]-arr[i]);

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

    	dp[i] = min(o1,o2);

    }

    cout<<dp[n-1];

}




// Faster C++ solution for the same problem (measured speedup: 4.408298319864818x):
#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;

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



using namespace std;



#define F first

#define S second



int N;

int H[100005];

int dp[100005][5];



int solve(int cost, int ind, int j) {

	if (ind > N) return INT32_MAX;

	if (ind == N) return cost;



	if (~dp[ind][j]) return dp[ind][j];

	

	dp[ind][j] = cost;

	dp[ind][j] += min(solve(abs(H[ind] - H[ind + 1]), ind + 1, 0), 

					solve(abs(H[ind] - H[ind + 2]), ind + 2, 1));

	return dp[ind][j];

}



int main() {

	cin >> N; 

	H[0] = INT32_MAX; // to avoid RTE

	for (int i = 1; i <= N; i++) cin >> H[i];

	int ans = 0;

	

	memset(dp, -1, sizeof dp);

	cout << solve(0, 1, 0) << endl;



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 13.0932154219502x):
#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;

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



using namespace std;



int v[100007];

int main() {

int n; cin >> n;

vector<int> dp(n+1);

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

dp[n] = 0;

dp[n-1] = abs(v[n] - v[n-1]);

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

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

}



cout << dp[1] << endl;

}

// Faster C++ solution for the same problem (measured speedup: 4.396853036824624x):
#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;

}
// Slower C++ solution:
#define f(i,s,v) for(int i=(int)s;i<(int)v;++i)

#define rf(i,s,v) for(int i=(int)s-1;i>(int)v;--i)

#include<bits/stdc++.h>

typedef long long ll;

using namespace std;

const ll oo=1e15;

int n;

int a[100005];

bool calculated[100005];

ll value[100005];

ll solve(int idx){

    if(idx>=n) return oo;

    if(idx==n-1) return 0ll;

    if(calculated[idx]) return value[idx];

    ll best=oo;

    f(i,1,3)

        best=min(best,solve(idx+i)+abs(a[idx+i]-a[idx]));

    calculated[idx]=true;

    value[idx]=best;

    return best;

}

int main()

{

    scanf("%d",&n);

    f(i,0,n)

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

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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.350313392778802x):
#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;

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

#include<bits/stdc++.h>

#include<string>

#include<vector>

#include<stack>

#include<cstdio>

#include <algorithm>

using namespace std;

int abs(int x)

{

	return x>0?x:-x;

}

int main()

{

    int n;

    cin>>n;

    int* dp=new int[n+1];

    int* h=new int[n+1];

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

    dp[1]=0;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: 4.358426631437931x):
#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;

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

#include <cstdio>

#include <queue>

#include <vector>

#include <cmath>

using namespace std;



int height[100003];



int dp[100003];



int JumpFrog(int N){

    dp[1]=0;

    dp[2]=abs(height[2]-height[1]);

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

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

    }

    return dp[N];

}



int main()

{

    int N;

    while(cin>>N){

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

            cin>>height[i];

        }

        cout<<JumpFrog(N)<<endl;

    }



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.357404697318973x):
#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;

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

using namespace std ;

//priority_queue<int,vector<int>,greater<int> >x ;

int h[100008] , dp[100008] ;

int main(){

    int 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] ;

}

// Faster C++ solution for the same problem (measured speedup: 4.34817465790357x):
#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;

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

using namespace std;

#define ll long long

#define ull unsigned long long

#define PII pair<int,int>

#define PSI pair<string,int>

#define PIII pair< int, pair<int,int> >

const int MXN = 1e5;

int a[MXN+5], dp[MXN+5];

int N,K;



int rec(int pos){



    if(pos==N) return 0;

    if(pos>=N) return 1<<30;

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

    return dp[pos] = min( rec(pos+1) + abs(a[pos+1]-a[pos]) , rec(pos+2) + abs(a[pos+2]-a[pos]) );

}



void solve(){



    cin>>N;

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

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

    cout<< rec(1) << "\n";

}



int main(){



    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    solve();

}


// Faster C++ solution for the same problem (measured speedup: 6.156892440878212x):
#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;

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

using namespace std;

typedef long long int ll;



ll mini(ll a, ll b){

    return (a<b)? a : b;

}





int main(){

    ll n; cin>> n;

    ll a[n], b[n]={0};

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

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

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

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

    }

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

}


// Faster C++ solution for the same problem (measured speedup: 4.351650710495303x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 4.479975434829504x):
#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;

}
// Slower C++ solution:
#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);

}




// Faster C++ solution for the same problem (measured speedup: 4.349800623861634x):
#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;

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

using namespace std;



int n;

int h[100005];

int dp[100005];



int solve(int x){

    if (x >= n-1) return 0;

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

    else if (x == n-2){

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

    }

    else {

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

    }

}



int main(int argc, char const *argv[]) {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cin >> n;

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

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

        cin >> h[i];

    }

    cout << solve(0) << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.158130328811298x):
#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;

}
// Slower C++ solution:
#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];

}

// Faster C++ solution for the same problem (measured speedup: 4.4065607323329985x):
#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;

}
// Slower C++ solution:
#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;





}

// Faster C++ solution for the same problem (measured speedup: 4.390469698551198x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 4.540654548674489x):
#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;

}
// Slower C++ solution:
#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 ;



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

ll solve( int i ){

	if ( i < 0 ) return 0 ;

	ll &ret = dp[i] ;

	if ( ~ret ) return ret ;

	if ( i == 0 ) return ret = 0 ;

	if ( i == 1 ) return ret = abs( h[1] - h[0]) ; 

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

}



int _3102_{

	Gamed

	cin >> n ;

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

		cin >> h[i] ;

	}

	memset ( dp , -1 , sizeof dp ) ;

	cout << solve ( n - 1 ) ;



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 7.906473114077752x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 4.354641770859185x):
#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;

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



#define fst first

#define snd second

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

#define pb push_back

#define ALL(s) s.begin(),s.end()

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

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

#define DBG(x) cerr <<#x << " = " << (x) << "\n"



#define SQR(x) ((x) * (x))



#define PI 3.1415926535897932385

#define INF 1000111222

#define eps 1e-7

#define maxN 11



using namespace std;



typedef long long ll;

typedef vector<ll> vll;

typedef pair<ll,ll> pll;

typedef pair<int,int> pii;

typedef vector<string> vstr;

typedef vector<vll> vvll;

typedef vector<bool> vbool;

typedef vector<pll> vpll;

typedef vector<vpll> vvpll;

typedef vector<vbool> vvbool;



vll ns,dp;

ll n;



ll solve(ll pos){

	ll & d = dp[pos];

	if(d != -1) return d;

	ll v=INF;

	if((pos+1)<n)v = min(v,abs(ns[pos+1]-ns[pos])+solve(pos+1));

	if((pos+2)<n)v = min(v,abs(ns[pos+2]-ns[pos])+solve(pos+2));

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

	return d = v;

}



int main(){FIN

	

	cin >> n;

	ns.resize(n);

	dp.assign(100010,-1);

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

	

	solve(0);

	

	cout << dp[0] << "\n";



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 7.954814662614608x):
#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;

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

using namespace std;



#define fi first

#define se second

#define pb push_back

#define dbg(x) cout << #x << " = " << x << endl

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



typedef long long ll;

typedef long double ld;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<pii> vii;



const int MAX = 1e5;

const int INF = 1e9;

vi stone(MAX + 5);

vi dp(MAX + 5, -1);

int n;



int sol(int i){

    if(i >= n) return INF;

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

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

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

    if(i + 2 < n){

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

    }

    return dp[i];

}



int main(){

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    #ifdef LOCAL

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

    #else

        #define endl '\n'

    #endif

    cin >> n;

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

        cin >> stone[i];

    cout << sol(0) << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 7.984848775407787x):
#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;

}