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

#define ll long long

#define ld long double

using namespace std;

const int N = 1e5+5;



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





int solve(int i)

{

    if(i == n-1)

        return 0;

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

    ll op1 = solve(i+1) + abs(h[i+1] - h[i]);

    ll op2 = op1;

    if(i + 2 < n)

        op2 = solve(i+2) + abs(h[i+2] - h[i]);

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

}



int table()

{

    dp[0] = 0;

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

    {

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

        if(i-2>=0)  dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));

    }

    return dp[n-1];

}



int main()

{

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin >> n;

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

        cin >> h[i];

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

    cout << table();

    // cout << solve(0);





    return 0;

}


// Optimized solution to the same problem (faster):
#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]);

}

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

using namespace std;

int numStones;

int heights[100005],b[100005];

int main(){

	cin>>numStones;

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

	    cin>>heights[i];

	}

	b[2]=abs(heights[1]-heights[2]);

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

	    b[i]=min(b[i-1]+abs(heights[i-1]-heights[i]),b[i-2]+abs(heights[i-2]-heights[i]));

	}

	cout<<b[numStones];

	return 0;

}

// Optimized solution to the same problem (faster):
#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]);

}

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

using namespace std;

 

typedef long long lld;

const int NN = 1e5 + 5;

lld aa[NN], dp[NN];

int nn;

 

int main() {

    ios::sync_with_stdio(0);

    cin.tie(0); 

    cout.tie(0);

        cin >> nn;

        for (int ii = 1; ii <= nn; ++ii)

            cin >> aa[ii];

        dp[1] = 0;

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

        for (int ii = 3; ii <= nn; ++ii)

            dp[ii] = min(dp[ii-1] + abs(aa[ii] - aa[ii - 1]), dp[ii-2] + abs(aa[ii] - aa[ii - 2]));

        cout << dp[nn];

    return 0;

}

// Optimized solution to the same problem (faster):
#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]);

}

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

using namespace std;

#define INF 1<<28

#define max 100005

 

 

typedef long long ll;

 

int n, a[100005];

int dp[max];

 

int main()

{

    cin>>n;

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

        cin>>a[i];

    dp[1] = 0;

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

        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;

    return 0;

}  

// Optimized solution to the same problem (faster):
#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]);

}

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

using namespace std;

#define ll long long

ll dp[100009];

ll n,x;

vector<ll>v;

ll frog(ll pos)

{

    if(pos<=0)

        return 0;

    if(pos==1)

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

        if(dp[pos]==-1)

        {

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

        }

    return dp[pos];

}



int main()

{

    cin>>n;

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

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

    {

        cin>>x;

        v.push_back(x);

    }

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

}


// Optimized solution to the same problem (faster):
#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]);

}

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



using namespace std;

int v[1000010];

int memo[1000010];

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()

{



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

}

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

using namespace std;

int h[100001];

int dp[100001];

int n;

int solve(int stone)

{

    if(stone+1==n) return dp[stone]=abs(h[stone]-h[stone+1]);

    if(stone+2==n) return dp[stone+2]=abs(h[stone]-h[stone+2]);

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

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

}



int main()

{

    int i;

    scanf("%d",&n);



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

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



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

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





    return 0;

}


// Optimized solution to the same problem (faster):
#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]);

}

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



using namespace std;



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



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+1]-h[i]) + sol(i+1),

                     abs(h[i+2]-h[i]) + 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 <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]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//#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);

}


// Optimized solution to the same problem (faster):
#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]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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]);

}

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

#include<cmath>

#include<algorithm>

using namespace std;



int dp[100004]={0};

int h[100005]={0};

int main(){

	int n;

	cin>>n;

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

		cin>>h[i];

	}

	

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

		int i1=i-1>0 ? i-1: 1,i2=i-2>0? i-2:1;

		dp[i]=min(dp[i1]+abs(h[i]-h[i1]),dp[i2]+abs(h[i]-h[i2]));

//		cout<<dp[i1]+abs(h[i]-h[i1])<<" "<<dp[i2]+abs(h[i]-h[i2])<<endl;

	}

//	for(int i=1;i<=n;i++) cout<<dp[i]<<" ";

	cout<<dp[n];

//	cout<<min(20 ,20);

	return 0;

}

// Optimized solution to the same problem (faster):
#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]);

}

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

#include <vector>

#include <iostream>

#include <cstdio>

#include <map>

#include <algorithm>

#include <queue>

#include <string>

#include <climits>

#include <list>

#include <cmath>

using namespace std;



int main() {

	int n;

	cin >> n;

	vector<int> v(n, 0);

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

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

	vector<int> dp(n, 0);

	dp[0] = 0;

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

	for (int i = 2; 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 - 1];

	return 0;

}

// Optimized solution to the same problem (faster):
#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]);

}

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

#include <cstdio>

#include <algorithm>

#include <vector>

#include <unordered_map>

#include <string>

#include <cstring>

#include <cctype>

#include <climits>

#include <cmath>

#include <set>

#include <map>

#include <unordered_set>

#include <sstream>

#include <queue>

#include <stack>

using namespace std;

vector<int> high;

int n;



int main(){

	scanf("%d",&n);

	high.resize(n+1);

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

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

	}

	vector<int> dp(n+1);

	dp[1]=0;

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

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

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

	}

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

	return 0;

}

// Optimized solution to the same problem (faster):
#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]);

}

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

using namespace std;

const int N = 1e5 + 100;

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



int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);



	cin >> n;



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

		cin >> h[i];

	}



	mem[n - 2] = abs(h[n - 1] - h[n - 2]);



	for (int i = n - 3; i >= 0; i--) {

		int a1 = mem[i + 1] + abs(h[i] - h[i + 1]);

		int a2 = mem[i + 2] + abs(h[i] - h[i + 2]);

		mem[i] = min(a1, a2);

	}



	cout << mem[0] << '\n';

	

	return 0;

}


// Optimized solution to the same problem (faster):
#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]);

}

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

using namespace std;

const long long mk=100005;

long long arr[mk];

long long n, dp[mk];

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

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

	}

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

}

// Optimized solution to the same problem (faster):
#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]);

}

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

using namespace std;

const int mx = 1e5+10;

int dp[mx];

int main()

{

    int n;

    cin>>n;

    int arr[n+1];

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

        cin>>arr[i];

    dp[0]=0;

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

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

    for(int i=3; 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]<<endl;

}

// Optimized solution to the same problem (faster):
#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]);

}

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

using namespace std;

#define maxn 100005

int h[maxn];

int dp[maxn];

int main()

{

    int n;

    cin>>n;

    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;

}


// Optimized solution to the same problem (faster):
#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]);

}

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

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<string>

#define ll long long int

using namespace std;

const int maxn=1000010;



int high[maxn];

int dp[maxn];



int main( )

{

    int i,n;;

    cin>>n;

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

    {

        cin>>high[i];

    }

    dp[1]=0;

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

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

    {

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

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

    }

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

	 return 0;

}


// Optimized solution to the same problem (faster):
#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]);

}

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

using namespace std;



#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void __f(const char* name, Arg1&& arg1) {

  cerr << name << " : " << arg1 << "\n";

}

template <typename Arg1, typename... Args>

void __f(const char* na, Arg1&& arg1, Args&&... args) {

  const char* c = strchr(na + 1, ',');

  cerr.write(na, c - na) << " : " << arg1 << " , ";

  __f(c + 1, args...);

}

#define endl "\n"

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

#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())

typedef long long LL;

typedef pair <int,int> pii;

const double pi = acos(-1.0);

const double eps = 1e-8;

const int mod = 1e9 + 7;

const int inf = 1e9;

const LL INF = 1e18;

const int N = 1e5 + 5;



int main() {

  ios_base::sync_with_stdio(false);

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

  #ifdef LOCAL

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

  #endif // LOCAL

  int n;

  cin >> n;

  vector <LL> h (n + 1);

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

  vector <LL> dp (n + 1, INF);

  dp[1] = 0;

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

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

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

}


// Optimized solution to the same problem (faster):
#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]);

}

// Fastest known solution for this problem: