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

#include <algorithm>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cstring>

#include <vector>

#include <string>

#include <climits>

#include <map>

#include <set>

#include <stack>

#include <queue>

#include <deque>

#include <stdio.h>

//#define int long long

using namespace std;

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

#define endl '\n'

#define OnlineJudgec

#define F first

#define S second

#define  precision(n)  cout << fixed << setprecision(n)

#define clr(v,d ) memset(v, d, sizeof(v))

typedef long long ll;

typedef vector<int> vi;

void init()

{

    cin.tie(0);

    cin.sync_with_stdio(0);

    cout.tie(0);

    #ifdef OnlineJudge

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

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

    #endif

}

ll S(ll x){ll s = 0;while(x){s += x % 10;x /= 10;}return s;} /// sum of digits.

ll powe(ll a , ll n){if(n == 1)return a;return a * powe(a ,n-1);}

ll com(int n,int m){ll z = 1;for(int i = 0; i < m;i++){z = z * ( n - i) / (i + 1) ;}return z;}

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

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

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

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

/// <<------------------------------------------------------------------------------>>

const int mx = 100009;

int n;

int arr[mx];

int dp[mx];

int solve(int idx)

{

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

    int &rst = dp[idx];

    if(~rst) return rst;

    int choice = 1e9 , choice2 = 1e9;

    if(idx + 1 < n)

        choice = solve(idx+1) + abs(arr[idx] - arr[idx + 1]);

    if(idx + 2 < n)

       choice2 = solve(idx+2) + abs(arr[idx] - arr[idx + 2]);

    return rst = min(choice , choice2);

}

/// <<------------------------------------------------------------------------------>>

int main()

{

    init();

    cin >> n;

    loop(n) cin >> arr[i];

    clr(dp,-1);

    cout<<solve(0);

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    {

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

    }

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

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

using namespace std;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

    for(i=N-3;i>=0;i--)

    {

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

    }

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



    return 0;

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    {

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

    }

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

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

#include <vector>

#include <string>

#include <cmath>

#include <set>

#include <stdio.h>

#include <algorithm>

#include <map>

#include <queue>

#include <unordered_map>

#define ll long long

#define pii pair <int, int>

#define pll pair <long long, long long>

#define plxy pair <long long, pll>

#define INT_MAX 1e18

#define Keep_calm_You_are_still_learning ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

using namespace std;

const int mod=1e9+7;

const int N=1e5+5;

ll dp[N];

int main()

{

    ll n,arr[N];

    cin>>n;

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

        cin>>arr[i];

    dp[0]=0;

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

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

    {

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

    }

    cout<<dp[n-1];

    return 0;

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    {

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

    }

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

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

using namespace std;

int main()

{

    int n;

    cin>>n;

    int arr[n];

    long long 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-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i-2]-arr[i]));

   }

   cout<<dp[n-1];

   return 0;

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    {

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

    }

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

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

using namespace std;

typedef long long ll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)

#define x first

#define y second





int main() {

    fast;

    int n;

    cin>>n;

    vector<int> arr(n);

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

        cin>>arr[i];

    }

    vector<int> dp(n);

    dp[0] = 0;

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

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

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

    }

    cout<<dp[n-1];

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    {

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

    }

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

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



#include <bits/stdc++.h>



typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

#define F first

#define S second

#define pii pair<int,int>

#define pll pair<ll, ll>

#define vi vector<int>

#define vll vector<ll>

#define vii vector<pii>

#define read(FILE)  freopen(FILE, "r", stdin);

#define out(FILE) freopen(FILE, "w", stdout);

#define clr(x, y) memset(x,y,sizeof(x));

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

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

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

#define forr(i, m, n) for(int i=m ; i<=n ; i++)

#define endl '\n'

#define pb push_back

#define re return

const int N = 1e5 + 5;

const ll OO = 2e8;

using namespace std;



int n, cost[N], dp[N],res=0;



bool valid(int i) {

    re i < n;

}



int main() {

    //IO;

    cin >> n;

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

    //memset(dp,OO, sizeof(dp));

    dp[0] = 0;

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

    rep(i,2,n){

        int next=OO,nextawy=OO;

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

        nextawy=dp[i-2]+abs(cost[i-2]-cost[i]);

        dp[i]=min(next,nextawy);

        //cout<<dp[i]<<" ";

    }

    //n--;

    cout<<dp[n-1];

    //cout<<endl;





}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    {

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

    }

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

}
// 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: 5.295427914804577x):
#include <stdio.h>

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    {

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

    }

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

}
// 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: 15.728104907852751x):
#include <stdio.h>

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    {

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

    }

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

}
// 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: 5.281679373552101x):
#include <stdio.h>

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    {

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

    }

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

}
// 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: 5.225774053098909x):
#include <stdio.h>

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    {

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

    }

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

}
// 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: 5.23552000660696x):
#include <stdio.h>

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    {

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

    }

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

}
// 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: 5.234292417621831x):
#include <stdio.h>

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

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

    }

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

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

    {

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

    }

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

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

using namespace std;

const int mx = 100005;

int dp[mx];

int A[mx];

void memo(int i,int n)

{

	if(i>n) return;

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

	memo(i+1,n);

}

int main()

{

     int n;cin>>n;

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

     	cin>>A[i];

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

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

     memo(3,n);

     cout<<dp[n]<<endl;

     return 0;

}

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

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

using namespace std;



#define INF 1e18;

#define MAX_N 100005

long long N, h[MAX_N], memo[MAX_N];



long long dp(int pos) {

  if (pos < 1) {

  	return INF;

  }

  if (pos == 1) {

  	return 0;

  }

  if (pos == 2) {

  	return abs(h[2] - h[1]);

  }

  if (memo[pos] != -1) {

  	return memo[pos];

  }

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

}



int main() {

  cin >> N;

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

  	cin >> h[i];

  }

  /*

  memo[2] = abs(h[2] - h[1]);

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

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

  }

  */

  /*

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

  	cout << i << ' ' << memo[i] << '\n';

  }

  */

  // cout << memo[N] << '\n';

  memset(memo, -1, sizeof memo);

  cout << dp(N) << '\n';

}

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

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

using namespace std;

int n , a[1000000] , frog , memo[1000000];



int f(int n){

	if(n == 1)return 0;

	if(n == 2)return abs(a[1] - a[2]);

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

	memo[n] = min(f(n-1) + abs(a[n] - a[n-1]) , f(n-2) + abs(a[n] - a[n-2]));

	return memo[n];

}

int main(){

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

	scanf("%d" , &n);

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

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

	}

	printf("%d" , f(n));

}

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

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

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f3f3f3f

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

#define pb push_back

#define ms(a, x) memset(a, x, sizeof(a))

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

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

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

using namespace std;

const int mod = 1e9;

const int N = 1e5+10;

/*=======================================================================*/



int n, h[N], sum;

int f[N];



int main() {

   scanf("%d", &n);

   for1(i, n) {

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

   }

   ms(f, inf);

   f[n] = 0;

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

      if(i == 2) {

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

      } else {

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

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

      }

      // if(i == 2) {

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

      //    i--;

      // } else {

      //    if(abs(h[i] - h[i-1]) < abs(h[i] - h[i-2])) {

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

      //       i -= 1;

      //    } else {

      //       sum += abs(h[i] - h[i-2]);

      //       i -= 2;

      //    }

      // }

   }

   cout << f[1] << endl;

   return 0;

}

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

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

using namespace std;



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.4027522265802455x):
#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] ;

}
// 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 ppt = 1e5+3;

int n;

int dp[ppt];

int a[ppt];

int f(int i){

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

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

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

	if(i!=n-2) jpr = min(jpr, abs(a[i]-a[i+2])+f(i+2));

	return dp[i]=jpr;

}

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.4027522265802455x):
#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] ;

}
// 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.4027522265802455x):
#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] ;

}