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

#include<cstdio>

#include<cmath>

#include<cstring>

#define Max(a,b) (a>b?a:b)

#define Min(a,b) (a<b?a:b)

using namespace std;

const int MAXN = 1e5+10, INF = 0x3f3f3f3f;

int A[MAXN], dp[MAXN], N;



int main()

{

	scanf("%d", &N);

	int i;

	for(i=1;i<=N;i++) scanf("%d", &A[i]), dp[i] = INF;

	dp[1] = 0;

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

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

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

	return 0;

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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

#include <vector>

#include <algorithm>

#include <stdio.h>

#include <map>

using namespace std;

#define min(a,b) (a>b?b:a);

int main(){

	int n;

	cin>>n;

	vector<int> path(n);

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

	vector<int> dp(n);

	dp[0]=0;

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

	if(n==2){

		cout<<dp[1]<<endl;

		return 0;

	}

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

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

	}

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

	return 0;

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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

#include<stdio.h>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

#define maxn 100005

int dp[maxn];

int h[maxn];

int n;

int main(){

    scanf("%d",&n);

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

    memset(h,0,sizeof(h));

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

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

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

        if(i-1>=1&&i-2>=1)

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

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

        else if(i-2>=1) dp[i] = dp[i-2]+abs(h[i]-h[i-2]);

    }

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

    return 0;

}


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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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

#include<algorithm>

#define MAXN 100010 

using namespace std;

int h[MAXN];

int dp[MAXN];

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-1; i++) {

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

		

	}

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

	//system("pause");

	return 0;

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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



using namespace std;

int v[100010];

int memo[100010];

int c;



int f(int i)

{



    if(memo[i]!=-1)

        return memo[i];



    if(i == 0)

        return memo[0] = 0;



    if(i == 1)

        return memo[1] = abs(v[0] - v[1]);



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

}



int main()

{

    ios_base::sync_with_stdio(false);

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

    cin>>c;



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

    {

        cin>>v[i];

    }



    cout<<f(c-1)<<endl;



    return 0;

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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

using namespace std;

#define Me3za() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))

#define endl "\n"

int n;

int arr[100005];

int mem[100005];

long long solve(int i,int cur){

if(i>=n)return 1e9;

//cout<<i<<" "<<cur<<endl;

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

long long ch1=solve(i+1,arr[i+1])+abs(cur-arr[i+1]);

long long ch2=0;

if(i+2<=n)ch2=solve(i+2,arr[i+2])+abs(cur-arr[i+2]);

return mem[i]=min(ch1,ch2);

}

int main() {

Me3za();

cin>>n;

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

    cin>>arr[i];

}

memset(mem,-1,sizeof mem);

cout<<solve(0,arr[0]);

}




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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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

using namespace std;



int const N=1e5+5, M=1e9+7, OO = 0x3f3f3f3f;



int n;

int arr[N];



int mem[N];

int solve(int i)

{

    if(i==n-1)

        return 0;

    if(mem[i]!=-1)

        return mem[i];

    int op1=solve(i+1)+abs(arr[i]-arr[i+1]);

    int op2=(i<=n-3) ? solve(i+2)+abs(arr[i]-arr[i+2]) : OO;

    return mem[i]=min(op1,op2);

}





int main()

{

//    freopen("input.txt","rt",stdin);

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

    scanf("%d",&n);

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

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

    memset(mem, -1, sizeof mem);

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



    return 0;

}


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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

// 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 N = 1e5 + 9;

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



int sol(int i){

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

    if(i == n)  return 1e9;



    int &ret = dp[i];

    if(~ret)    return ret;



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

}





int main() {



    cin >> n;



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



    memset(dp, -1, sizeof dp);



    cout << sol(0);

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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



using namespace std;



const int N=1e5;

int n;

int arr[N];

int mem[N];



int solve(int i){

    if(i==n-1)

        return 0;

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

    int op1=solve(i+1)+abs(arr[i]-arr[i+1]);

    int op2=i+2<=n-1?solve(i+2)+abs(arr[i]-arr[i+2]):1000000000;

    return mem[i]=min(op1,op2);

}



int main() {

    scanf("%d",&n);

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

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

    memset(mem,-1,sizeof mem);

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

    return 0;

}


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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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

#include <bitset>

using namespace std;

#define ll long long

#define mod 1000000009



// يلعن ابو الي يعقدها على نفسه تاني



int main()

{

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



    ll n; cin >> n;

    ll arr[100005];

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

        cin >> arr[i];

    }

    if(n == 2){

        cout << abs(arr[1]-arr[0]);

    }else{

        ll sol[100005] = {};

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

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

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

        }









        cout << sol[n-1];

    }















    return 0;

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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

 

using namespace std;

 

#define sf(n) scanf("%d", &n)

#define pd(n) printf("%.12lf", n)

#define pf(n) printf("%d", n)

#define p() printf("\n")

#define ps() printf(" ")

#define ll long long

#define ull unsigned long long

#define MAX 1e9

const int mod = 1000 * 1000 * 1000 + 7;

#define ex 1e18

#define dbl 2e09

#define qu(q) queue<int> q

#define pqu(q) priority_queue<int> q

#define len(s) s.length()

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

#define pb(x) push_back(x)

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

#define rall(x) x.rbegin(), x.rend()

#define F first

#define S second

#define clr(x) x.clear()

#define LOG(x) std::cout << x << std::endl;

 

const int INF = 0x3f3f3f3f;

const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

const double PI = 3.14159265359;

 

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

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



int a[100005];

int dp[100005];

int n;

int solve(int idx){

    if(idx==(n-1))

        return 0;

    if(idx>=n)

        return INF;

    int &ret = dp[idx];

    if(~ret)

        return ret;

    ret = INF;

    ret=min(ret,solve(idx+1)+abs(a[idx+1]-a[idx]));

    ret=min(ret,solve(idx+2)+abs(a[idx+2]-a[idx]));

    return ret;

}







int main(){



    cin>>n;

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

        cin>>a[i];

    }

    memset(dp,-1,sizeof dp);

    cout<<solve(0)<<endl;

    return 0;

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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

using namespace std;

int abssub(int a,int b){

	if(a>b)return a-b;

	return b-a;

}

int main(){

	int n,h[100001],bp[100001]={0};

	cin>>n; 

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

		cin>>h[i];

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

		if(i==2)bp[i]=bp[i-1]+abssub(h[i],h[i-1]);

		else{

			bp[i]=min(bp[i-1]+abssub(h[i],h[i-1]),bp[i-2]+abssub(h[i],h[i-2]));

		}

	}

	cout<<bp[n]<<endl;

	return 0;

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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

#include<bits/stdc++.h>

#include<iostream>

#include<algorithm>

#include<iomanip>

#include<string>

#include<cmath>

#include<vector>

#include<set>

#include<queue>

#include<stack>

#include<fstream>

#include<map>

#include<bitset>

#include<unordered_map>

#include<cstring>

#include<cctype>

using namespace std;

#define  ll long long

#define  ull unsigned long long

#define  ul unsigned long

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

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

#define pb(s) push_back(s);

#define format(n) fixed<<setprecision(n)

#define finl "\n"

#define Mohammed_Atef_Hassan fast();

#define mod 1000000007

#define INF LLONG_MAX

#define PI acos(-1)

#define clr(dp,n) memset(dp,n,sizeof dp)

#define ex(n) return cout<<n<<finl,0;

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

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

ll fix_mod(ll x, ll y)

{

	return (y + x % y) % y;

}

void fast() {

	std::ios_base::sync_with_stdio(false);

	cin.tie(nullptr); cout.tie(nullptr);





}

int n;

vector<ll>v;

ll mem[(int)1e5 + 10];

ll solve(int i)

{

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

	ll& ret = mem[i];

	if (~ret)return ret;

	ret = solve(i + 1) + abs(v[i + 1] - v[i]);

	if (i + 2 < n)

		ret = min(ret, solve(i + 2) + abs(v[i + 2] - v[i]));

	return ret;

}

int main()

{

	Mohammed_Atef_Hassan

		clr(mem, -1);

		cin >> n;

	v = vector<ll>(n);

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

	ex(solve(0));

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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

#include<cmath>

#include<algorithm>

using namespace std;

const int maxn = 100005;

const int INF = 1000000000;



int A[maxn];//石头高度

int dp[maxn] = {0}; 

int n;



int main(){

//	freopen("4.txt","r",stdin);

	scanf("%d",&n);

	fill(dp,dp+maxn,INF);

	

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

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

	}

	dp[1] = 0;

	for(int i=2;i<=n;i++){//跳到i上 

		int j1 = i-2, j2 = i-1;

		if(j1>=1){//

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

		}

		if(j2>=1){//

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

		}

	}

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

	

	return 0;

} 

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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

#include<algorithm>

using namespace std;

int main(){

    int dp[100001]={0};

    int stone[100001];

    int n;

    scanf("%d",&n);

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

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

    }

    dp[1] = 0;

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

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

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

    }

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

}


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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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

#include<algorithm>

using namespace std;

const int maxn=100001;

int a[maxn],dp[maxn];



int main(){

	int n;

	cin>>n;

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

		cin>>a[i];

	}

	dp[n]=0;

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

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

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

	}

	cout<<dp[1];

	return 0;

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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

#include<iostream>

#include<iomanip>

#include<map>

#include<cmath>

#include<algorithm>

#include<string>

#include<vector>

#include<queue>

#include<set>

#include<deque>

#include<stack>

#include<bitset>

#include<fstream>

#include<map>

#include<unordered_map>

using namespace std;

typedef int me;

typedef long long ll;

typedef unsigned long long ull;

#define andrew  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define endl '\n'

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

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

#define PI 3.1415926535

#define sin(i) (long double)sin(i*PI/180.0);

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }

ull lcm(ll x, ll y) { return x / gcd(x, y) * y; }

void the_end() {

#ifndef ONLINE_JUDGE;

    system("pause");

#endif

}

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

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

int id8[] = { 0, 1,2,3,4, 5,6, 7 };

// you can be specialist 

// soon will be (Cyain)

ll n;

vector<ll>v;

map<int, ll>m;

ll solve(int i)

{

    if (i == 0)

        return 0;

    if (i == 1) {

        return abs(v[i] - v[i - 1]);

    }

    if (m.find(i) != m.end())

        return m[i];

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

}

int main()

{

    andrew;

    cin >> n;

    v.resize(n);

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

    cout << solve(n-1)<< endl;

    the_end();

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

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

#include<iostream>

#include<functional>

#include <bitset>

#include<algorithm>

#include<fstream>

#include<string>

#include <cstring>

#include<stdio.h>

#include<iomanip>

#include<sstream>

#include<cmath>

#include<vector>

#include<assert.h>

#include<queue>

#include<deque>

#include<stack>

#include<set>

#include<map>

// never lose hope ..

typedef unsigned long long ull;

typedef long long ll;

typedef long double ld;

#define eps 1e-8

using namespace std;

double const  PI = 3.141592653;

const int OO = 1000000000 + 9;



void fast() {

	ios_base::sync_with_stdio(0);

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

}





int main()

{

	fast();



	int n;

	cin >> n;

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

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

		cin >> v[i];

	}

	dp[1] = 0;

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

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

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

	}

	cout << dp[n];





	return 0;

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

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

}

// Fastest known solution for this problem: