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

#define ll long long

using namespace std;

const int maxn = 1e5+5;

int a[maxn], dp[maxn];



int main(){

	int n; cin >> n;

	memset(dp, 0x3f, sizeof dp);

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

	dp[1] = 0;

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

		dp[i] = min(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;

}

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

#include <algorithm>

using std::min;

 

#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;

}

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

#include<stdlib.h>

#include<string.h>

#include<algorithm>

int h[100000];

int dp[100000];

int main()

{

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

	int n,temp,dp1,dp2;

	scanf("%d", &n);

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

	{

		scanf("%d", &temp);

		h[i] = temp;

	}

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

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

	{

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

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

		dp[i] = dp1 < dp2 ? dp1 : dp2;

	}

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

}

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

#include <algorithm>

using std::min;

 

#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;

}

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

#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

const int MAXN=100010;

int stones[MAXN];

int mins[MAXN]= {-1};

int main()

{

    int n;

    cin>>n;

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

    {

        cin>>stones[i];

    }

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

    {

        if(i==n-2)

        {

            mins[n-2]=abs(stones[i]-stones[i+1]);

        }

        else if(i==n-3)

        {

            int one=abs(stones[i]-stones[i+1])+mins[i+1];

            int two=abs(stones[i]-stones[i+2]);

            mins[i]=min(one,two);

        }

        else

        {

            int one=abs(stones[i]-stones[i+1])+mins[i+1];

            int two=abs(stones[i]-stones[i+2])+mins[i+2];

            mins[i]=min(one,two);

        }

    }

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

    return 0;

}


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

#include <algorithm>

using std::min;

 

#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;

}

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

#include <queue>

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int maxn = 100010;

int H[maxn];

int main(){

    int n;

    scanf("%d",&n);

    int dp[n+1];

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

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

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

    }

    dp[1]=0;

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

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

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

    }

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

    return 0;



}

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

#include <algorithm>

using std::min;

 

#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;

}

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

using ll = long long;

using namespace std;



int n, k = 2;

int arr[100100], dp[100100];

bool vis[100100];



int func( int pos ) {

  if (pos == n) return 0;

  if (vis[pos]) return dp[pos];

  vis[pos] = 1;

  int res = INT_MAX;

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

    if (pos + i > n) break;

    res = min(res, func(pos + i) + abs(arr[pos] - arr[pos + i]));

  }

  return dp[pos] = res;

}



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0), cout.tie(0);



  cin >> n;

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

  cout << func(1) << endl;

  return 0;

}


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

#include <algorithm>

using std::min;

 

#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define _CRT_SECURE_NO_WARNINGS

/*                   وتزودوا فإن خير الزاد التقوى                    */

/*       وما تدري نفس ماذا تکسب غدا وما تدري نفس باي ارض تموت      */

#include <bits/stdc++.h>

#include<unordered_map>

#include<iomanip>

#include<fstream>

using namespace std;

#include<iostream>

#define endl '\n'

#define ll long long

#define ull unsigned long long

#define dll double

#define PI acos(-1)

#define watch(x) cout<<#x<<" = { "<<x<<" }\n"

#define sz(n) n.size()

#define M_Sayed fast() 

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

#define allr(v) v.rbegin(),v.rend()

#define RT(v) return cout<<v,0

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

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

const double EPS = (1e-7);

ll Ceil(ll x, ll y) { return (x + y - 1) / y; }

void run() {

#ifndef ONLINE_JUDGE

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

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

#else

#endif

}

ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }

ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

ll power(ll x, ll y, ll mod) {

	if (y == 0) return 1;

	if (y == 1) return x % mod;

	ll r = power(x, y >> 1, mod);

	return (((r * r) % mod) * power(x, y & 1, mod)) % mod;

}

void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }

ll n, m, k,su,cnt;

ll vis[100009];

vector<ll>v;

ll Jum(int x) {

	if (x+1 == n)

		return 0;

	ll &ret = vis[x];

	if (~ret)return ret;

	 ret = abs(v[x] - v[x + 1])+Jum(x + 1) ;

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

		if(i+x<n)ret = min(ret,Jum(x + i) + abs(v[x] - v[x + i]));

	}

	return ret;

}

int main()

{

	//run();

	M_Sayed;

	cin >> n ;

	memset(vis, -1, sizeof vis);

	v.resize(n);

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

		cin >> v[i];

	}

	k = 2;

	RT(Jum(0));

}

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

#include <algorithm>

using std::min;



#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//       Author: Mostafa Mounir Shehab

 

#include <bits/stdc++.h>

using namespace std;

 

#define PI  3.14159265  // PI = acos(-1)

#define EPS (1e-10)

#define endl "\n"

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

typedef long long ll;

typedef long double ld;

//template <class Type>

 

 

void Fast(){

	std::ios_base::sync_with_stdio(0);

	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);

}

 

inline int D(){

	int t;

	scanf("%d",&t);

	return t;

}

inline ll llD(){

	ll t;

	scanf("%lld",&t);

	return t;

}

 

 

ll MOD=1e9 + 7; 

const int N=1e5 + 5,M=50 + 1;

int arr[N];

ll dp[N];

ll OO=1e12; 

 

ll n,m,k,cnt,SU,idx,len,MN,MX;

ll l,r,mid;

ll a,b,c,d;



ll Solve(int idx){

	ll &ret = dp[idx];

	if(~ret)

		return ret;

		

	if(idx >= n)

		return ret = (idx == n) ? 0 : OO;

	

	

	ll x = abs(arr[idx] - arr[idx+1]) + Solve(idx+1);

	ll y = abs(arr[idx] - arr[idx+2]) + Solve(idx+2);

	

	return ret = min(x,y);

}







 

 

int main(){

	

	memset(dp, -1 ,sizeof dp);

	cin>>n;

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

		cin>>arr[i];



	cout<<Solve(1)<<endl;

	



	





}

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

#include <algorithm>

using std::min;



#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;

}

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

using namespace std;

const int maxn = 1e5 + 5;

int main(){

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

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

	scanf("%d",&n);

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

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

	dp[1] = 0;

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

		dp[i] = min(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]));

	}

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

	return 0;

}

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

#include <algorithm>

using std::min;



#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;

}

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



using namespace std;



const int N = 1e5 + 9;



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



int sol(int i, int prev){

    if(i >= n)  return 1e9;

    if(i == n - 1)  return abs(h[i] - h[i - 1 - (prev == 1)]);



    int &ret = dp[i][prev];

    if(~ret)    return ret;



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

}



int main(){

    cin >> n;

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

        cin >> h[i];



    memset(dp, -1, sizeof dp);



    cout << min(sol(1, 0), sol(2, 1));



    return 0;

}

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

#include <algorithm>

using std::min;



#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;

}

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



using namespace std;



int n, h[100002], dp[100002][3];



int sol(int i, int choice){

    if(i==0) return 0;

    if(i<0) return 1E9;



    int &ret = dp[i][choice];

    if(~ret) return ret;



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

}



int main()

{

    cin >> n;

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

        cin >> h[i];



    memset(dp, -1, sizeof dp);

    cout << min(sol(n-1, 1), sol(n-1, 2));

}


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

#include <algorithm>

using std::min;



#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):


#include <bits/stdc++.h>

using namespace  std;



int N;

const int SIZE = 100005;

long h [SIZE];

int mem [SIZE];



int dp (int i) {

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

  

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



  long ret = LLONG_MAX;



  if (i+1 < N) 

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

  if (i+2 < N)

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



  return  mem[i] = ret;

}



int main (){ 



  cin  >> N;

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

    cin >> h[i];

  }



  memset(mem, -1, sizeof mem);



  cout << dp(0);



}

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

#include <algorithm>

using std::min;



#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;

}

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

#define maxn 100005

using namespace std;



int main(){

    int n;

    cin >> n;

    int h[maxn];

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

        cin >> h[i];

    }

    int dp[maxn];

    fill(dp, dp+maxn, 0x7fffffff);

    dp[0] = 0;

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

        int temp = 0;

        if(i+1 < n){

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

            if(temp < dp[i+1])

                dp[i+1] = temp;

        }

        if(i+2 < n){

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

            if(temp < dp[i+2])

                dp[i+2] = temp;

        }

    }

    cout << dp[n-1];

    return 0;

}


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

#include <algorithm>

using std::min;



#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;

}

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

#define ll long long

using namespace std;



int main(){

    int n;

    cin>>n;

    int a[n],dp[n];

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

        cin>>a[i];

        dp[i]=0;

    }

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

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



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

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

    }

    cout<<dp[n-1];

return 0;

}


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

#include <algorithm>

using std::min;



#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;

}

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

using ll = long long;

using namespace std;



int n, arr[100100], k = 2;

bool vis[100100];

int dp[100100];



int func( int pos ) {

  if ( pos == n ) return 0;

  if (vis[pos]) return dp[pos];

  vis[pos] = 1;

  int res = 1e9;

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

    if ( pos + i <= n ) 

      res = min(res, func(pos + i) + abs(arr[pos] - arr[pos + i]));

  }

  return dp[pos] = res;

}



int main() {

  cin >> n;

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

  cout << func(1) << endl;

  return 0;

}


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

#include <algorithm>

using std::min;



#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;

}

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

using namespace std ;

#define ll long long

inline int D(){

    int t ;

    scanf( "%d" , &t ) ;

    return t ;

}

inline ll LLD(){

    ll t ;

    scanf( "%lld" , &t ) ;

    return t ;

}

//################################################################

ll n;

ll a[1000005];

ll mem[1000005];



int main() {

    n = LLD();

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

    mem[0]=0;

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

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

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

    }

    printf("%lld",mem[n-1]);



}

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

#include <algorithm>

using std::min;



#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/**

     **author : _KMS_

     **created : 27-03-2020

**/

#include<bits/stdc++.h>

using namespace std;

const long long M =2e5+10,MOD=998244353;

typedef long long ll;

int arr[M];

int dp[M];

int main() {

   

  ios::sync_with_stdio(false);

  cin.tie(0);

  int n;

  cin>>n;

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

  cin>>arr[i];

 // dp[2]=abs(arr[1]-arr[2])

 arr[0]=arr[1];

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

  {

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

  }

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



  return 0;

} 

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

#include <algorithm>

using std::min;



#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;

}

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



using namespace std;

typedef long long ll;

typedef double dd;

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

#define endl "\n"

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



void fast() {



    cin.tie(0);

    cin.sync_with_stdio(0);

}

const int MAX = 1e5 + 9;

ll arr[MAX], n,dp[MAX];

int main() {

    fast();

    cin >> n;

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

        cin >> arr[i];

    }

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

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

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

    }

    cout<<dp[n-1];

}

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

#include <algorithm>

using std::min;



#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;

}

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

#include<cmath>

using namespace std;



int main(){

	int N;

	cin>>N;

	int a[N], i, j;

	long long dp[N];

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

	dp[0] = 0;

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

		int temp1=100000, temp2=100000;

		if(i > 0)temp1 = dp[i-1] + abs(a[i]-a[i-1]);

		if(i > 1)temp2 = dp[i-2] + abs(a[i]-a[i-2]);

		dp[i] = min(temp1, temp2);

	}

	cout<<dp[N-1];

	return 0;

} 

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

#include <algorithm>

using std::min;



#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;

}

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

#include <vector>

#include <cmath>

using namespace std;

int main() {

	int n, x;

	cin >> n;

	vector<int> v(n), u(n);

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

		cin >> v[i];

		if (i == 0) {

			u[i] = 0;

		} else if (i == 1) {

			u[i] = abs(v[i] - v[i - 1]);

		} else {

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

		}

	}

	cout << u[n - 1];

	return 0;

}

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

#include <algorithm>

using std::min;



#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;

}

// Fastest known solution for this problem: