stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


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

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

using namespace std;

int dif(int a, int b)

{

    int ans=a-b;

    if(ans<0) ans*=-1;

    return ans;

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int N, h[100005],i,j;

    int f1,f2;

    cin>>N;

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

        cin>>h[i];

    int M[100005]={0};

    M[N-2]=dif(h[N-1],h[N-2]);

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

    {

        f1=dif(h[i+1],h[i])+M[i+1];

        f2=dif(h[i+2],h[i])+M[i+2];

        M[i]=min(f1,f2);

    }

    cout<<M[0]<<endl;

    return 0;

}


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

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

using namespace std;

int n;

int h[1000005], memo[1000005];

int f(int n) {

    if(n == 1) {                        // bisa juga base case nya n = 0, f(0) harus tinggi, misal 1e9;

        return 0;

    }

    if(n == 2) {

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

    } 

    else if(memo[n] != -1) {

        return memo[n];

    }

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

    return memo[n];

}



int main() {

    scanf("%d", &n);

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

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

    }

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

    f(n);

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

}

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

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

using namespace std;



typedef signed long long ll;

const int MX = 1e5 + 5;

const int INF = 1e9 + 5;

int n, A[MX], dp[MX];



int solve(int pos) {

    if(pos > n) return INF;

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

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

    int ans = INF;

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

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

    return dp[pos] = ans;

}



int main() {

    scanf("%d", &n);



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

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

    }

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

    printf("%d\n", solve(0));

    return 0;

}

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

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

#include<cmath>

#include<algorithm>

#include<cstring>

using namespace std;



int h[100055],dp[100055];

const int inf = 0x3f3f3f;

int main()

{

	int n;

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

	cin>>n;

	h[1]=inf;

	h[0]=inf;

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

		cin>>h[i];

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

	return 0;

} 

//max(h[i],h[i-2])-min(h[i],h[i-2])

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

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

using namespace std;

#define IO ios::sync_with_stdio(false), cin.tie(0)

typedef long long ll;

const int maxn = 1e6 + 5;

const int inf = 0x3f3f3f3f;

ll a[maxn];

ll dp[maxn];



int main()

{

    IO;

    int n, k=2;

    cin >> n ;

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

        cin >> a[i];

    memset(dp, inf, sizeof(dp));

    dp[1] = 0;

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

    {

        for (int j = 1; j <= k; ++j)

        {

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

        }

    }

    cout << dp[n] << endl;

}


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

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

using namespace std;

const int nax = 1e5+3;

int number;

int dyn[nax];

int a[nax];

int op1(int i){

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

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

	int res = abs(a[i]-a[i+1])+op1(i+1);

	if(i!=number-2) res = min(res, abs(a[i]-a[i+2])+op1(i+2));

	return dyn[i]=res;

}

int main(){

	cin>>number;

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

	memset(dyn, -1, sizeof dyn);

	cout<<op1(0)<<endl;

	return 0;

}


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

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

using namespace std;

int n, arr[100005], best, memo[100005];



int dp(int x){

	if(x==1 || x == 0){

		return 0;

	}

	if (x == 2){

		return abs(arr[x] - arr[x-1]);

	}

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

		return memo[x];

	}

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

	memo[x] = best;

	return best;

}



int main(){

	ios_base::sync_with_stdio(0);

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

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	cout << dp(n) << endl;

}

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

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

using namespace std;

int n, arr[100005], best, memo[100005];



int dp(int x){

	if(x==0 or x==1){

		return 0;

	}

	else if(x==2){

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

	}

	else if(memo[x]!=-1){

		return memo[x];

	}

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

	memo[x]=best;

	return best;

}



int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

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

	cin >> n;

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

		cin >> arr[i];

	}

	cout << dp(n) << endl;

}


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

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

using namespace std;

int arr[100010],n;

int dp[100010];

int f(int pos){

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

	int &ret=dp[pos];

	if(ret^-1)return ret;

	if(pos+1==n-1)return ret=abs(arr[pos+1]-arr[pos]);

	return ret=min(f(pos+1)+abs(arr[pos]-arr[pos+1]),f(pos+2)+abs(arr[pos]-arr[pos+2]));

}



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

{

	memset(dp,-1,sizeof dp);

	cin>>n;

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

		cout<<f(0)<<endl;

	return 0;

}

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

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

}

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

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

using namespace std;

int dif(int a, int b)

{

    int ans=a-b;

    if(ans<0) ans*=-1;

    return ans;

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int N, h[100005],i,j;

    int f1,f2;

    cin>>N;

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

        cin>>h[i];

    int M[100005]={0};

    M[N-2]=dif(h[N-1],h[N-2]);

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

    {

        f1=dif(h[i+1],h[i])+M[i+1];

        f2=dif(h[i+2],h[i])+M[i+2];

        M[i]=min(f1,f2);

    }

    cout<<M[0]<<endl;

    return 0;

}


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

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

using namespace std;

int n;

int h[1000005], memo[1000005];

int f(int n) {

    if(n == 1) {                        // bisa juga base case nya n = 0, f(0) harus tinggi, misal 1e9;

        return 0;

    }

    if(n == 2) {

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

    } 

    else if(memo[n] != -1) {

        return memo[n];

    }

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

    return memo[n];

}



int main() {

    scanf("%d", &n);

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

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

    }

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

    f(n);

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

}

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

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

using namespace std;



typedef signed long long ll;

const int MX = 1e5 + 5;

const int INF = 1e9 + 5;

int n, A[MX], dp[MX];



int solve(int pos) {

    if(pos > n) return INF;

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

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

    int ans = INF;

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

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

    return dp[pos] = ans;

}



int main() {

    scanf("%d", &n);



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

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

    }

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

    printf("%d\n", solve(0));

    return 0;

}

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

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

#include<cmath>

#include<algorithm>

#include<cstring>

using namespace std;



int h[100055],dp[100055];

const int inf = 0x3f3f3f;

int main()

{

	int n;

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

	cin>>n;

	h[1]=inf;

	h[0]=inf;

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

		cin>>h[i];

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

	return 0;

} 

//max(h[i],h[i-2])-min(h[i],h[i-2])

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

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

using namespace std;

#define IO ios::sync_with_stdio(false), cin.tie(0)

typedef long long ll;

const int maxn = 1e6 + 5;

const int inf = 0x3f3f3f3f;

ll a[maxn];

ll dp[maxn];



int main()

{

    IO;

    int n, k=2;

    cin >> n ;

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

        cin >> a[i];

    memset(dp, inf, sizeof(dp));

    dp[1] = 0;

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

    {

        for (int j = 1; j <= k; ++j)

        {

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

        }

    }

    cout << dp[n] << endl;

}


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

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

using namespace std;

const int nax = 1e5+3;

int number;

int dyn[nax];

int a[nax];

int op1(int i){

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

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

	int res = abs(a[i]-a[i+1])+op1(i+1);

	if(i!=number-2) res = min(res, abs(a[i]-a[i+2])+op1(i+2));

	return dyn[i]=res;

}

int main(){

	cin>>number;

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

	memset(dyn, -1, sizeof dyn);

	cout<<op1(0)<<endl;

	return 0;

}


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

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

using namespace std;

int n, arr[100005], best, memo[100005];



int dp(int x){

	if(x==1 || x == 0){

		return 0;

	}

	if (x == 2){

		return abs(arr[x] - arr[x-1]);

	}

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

		return memo[x];

	}

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

	memo[x] = best;

	return best;

}



int main(){

	ios_base::sync_with_stdio(0);

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

	cin.tie();

	cout.tie();

	cin >> n;

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

		cin >> arr[i];

	}

	cout << dp(n) << endl;

}

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

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

using namespace std;

int n, arr[100005], best, memo[100005];



int dp(int x){

	if(x==0 or x==1){

		return 0;

	}

	else if(x==2){

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

	}

	else if(memo[x]!=-1){

		return memo[x];

	}

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

	memo[x]=best;

	return best;

}



int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

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

	cin >> n;

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

		cin >> arr[i];

	}

	cout << dp(n) << endl;

}


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

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

using namespace std;

int arr[100010],n;

int dp[100010];

int f(int pos){

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

	int &ret=dp[pos];

	if(ret^-1)return ret;

	if(pos+1==n-1)return ret=abs(arr[pos+1]-arr[pos]);

	return ret=min(f(pos+1)+abs(arr[pos]-arr[pos+1]),f(pos+2)+abs(arr[pos]-arr[pos+2]));

}



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

{

	memset(dp,-1,sizeof dp);

	cin>>n;

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

		cout<<f(0)<<endl;

	return 0;

}

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

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

}

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

}