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

#include<iostream>

#include<vector>

#include<algorithm>

#include<map>



using namespace std;



int n,a[100050];long long mem[100050];



long long solve(int idx)

{

    if(idx==n-1)

        return 0;

    if(idx>=n)

        return 1500000000;

    if(mem[idx]!=-1)

        return mem[idx];

    int op1,op2;

    //if(idx<n-1)

        op1=solve(idx+1)+abs(a[idx]-a[idx+1]);

    //if(idx<n-2)

        op2=solve(idx+2)+abs(a[idx]-a[idx+2]);

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

}



int main() {



    cin>>n;

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

    {

        cin>>a[i];

        mem[i]=-1;

    }

    solve(0);

    cout<<mem[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 <iostream>

#include<utility>

#include<iomanip>

#include<cmath>

#include<algorithm>

#include<cfloat>

#include<functional>

#include<string>

#include<numeric>

#include<vector>

#include<stack>

#include<queue>

#include<set>

#include<map>

#include<cctype>

#include<iterator>

#include <stdio.h>

#include <string.h>

#include <sstream>

// #include <bits/stdc++.h>

//#include<conio.h>

#define ReadFile freopen("input.txt","r",stdin)

#define WriteFile freopen("output.txt","w",stdout)

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

#define M_PI 3.14159265358979323846

#define mod 1000000007

#define endl "\n"

using namespace std;

using ll = long long;

using lli = long long int;

using ld = long double;





const int N = 5e5 + 6, inf = 2e9;

int n;

int arr[N], dp[N];

int main()

{

	MEGA_MIND



	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(abs(arr[i - 1] - arr[i]) + dp[i - 1], abs(arr[i - 2] - arr[i]) + 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 <bits/stdc++.h>



using namespace std;



int main()

{

    int n;

    cin>>n;

    int arr[n+5],dp[n+5];

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

        cin>>arr[i];

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

        dp[i]=1e9;



    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;



    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;

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(NULL);



    int n;

    cin>>n;

    vector<ll> dp(n+1,1e18);



    vector<int> arr(n+1);

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



    dp[1]=0;

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



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

    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 n, h[100000], dp[100000];



int main(){

	scanf("%d", &n);

	for (int i=0; i<n; i++) scanf("%d", &h[i]);

	dp[0]=0;

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

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

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

}

// 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 <sstream>

using namespace std;

#include <bits/stdc++.h>

#include<utility>

#include <algorithm>

#include<iterator>

#define  go return 0

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

#define rep(j,m) for(int j=0;j<m;++j)

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

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

#define len(s)   ((int)s.size())

#define F first

#define S second

#define pb push_back

#define pf push_front

#define mp make_pair

typedef long long ll;

typedef double db;

typedef vector<ll> ve;

typedef vector< vector <int> >vee;

typedef vector<pair<int,int> >vepa;

typedef set<char>se;

typedef map<ll,ll> mpp;

const ll N=1e5+5;

bool f;

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

ll solve(ll i=0)

{

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

  ll &ret=dp[i];

  if(~ret)return ret;

   return ret=min(solve(i+1)+abs(arr[i]-arr[i+1]) ,i+2<n? solve(i+2)+abs(arr[i]-arr[i+2]):12345 );

}

int main()

{

ios::sync_with_stdio(0);

cin.tie(0);

   cin>>n;

   memset(dp,-1,sizeof dp);

   rep(i,n)

    cin>>arr[i];

   cout<<solve();



go;

}


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

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

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

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

#define forv(i, v) for(int i = 0; i < sz(v); ++i)

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

using namespace std;



typedef long long       ll;

typedef long double     ld;

typedef vector<int>     vi;

typedef vector<double>  vd;

typedef vector< vi >    vii;

typedef vector< vd >    vdd;

typedef vector<string>  vs;





int main()

{

	int n;

	scanf("%d", &n);

	int h[n + 5];

	ll ans[n + 5];

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

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

	}

	ans[0] = 0;

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

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



		ll r1 = abs(h[i] - h[i - 1]) + ans[i - 1];

		ll r2 = abs(h[i] - h[i - 2]) + ans[i - 2];

		ans[i] = min(r1, r2);

	}

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

	return 0;

}


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

using namespace std;



vector<long long int> dp(100005,-1);

long long int n,ara[100005];

int f(long long int i){



    if(i==n) return 0;



    if(i==n-1) return abs(ara[i+1]-ara[i]);



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



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

    return dp[i];





}









int main()

{

    long long int i;

    cin>>n;

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

        scanf("%lld",&ara[i]);

    }



    cout<<f(1)<<endl;



    return 0;

}


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

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

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

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

#define forv(i, v) for(int i = 0; i < sz(v); ++i)

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

using namespace std;



typedef long long       ll;

typedef long double     ld;

typedef vector<int>     vi;

typedef vector<double>  vd;

typedef vector< vi >    vii;

typedef vector< vd >    vdd;

typedef vector<string>  vs;





int main()

{

	int n;

	scanf("%d", &n);

	int h[n + 5];

	ll ans[n + 5];

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

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

	}

	ans[0] = 0;

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

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



		ll r1 = abs(h[i] - h[i - 1]) + ans[i - 1];

		ll r2 = abs(h[i] - h[i - 2]) + ans[i - 2];

		ans[i] = min(r1, r2);

	}

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

	return 0;

}


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

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

#define ii          pair<int,int>

#define F           first

#define S           second

#define pb          push_back

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

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

#define fore(i,a,b) for(int i = a;i < b; i+= 1)

#define forr(i,a)   for(int i = a; i >= 0; i--)

#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 

#define w(t)        while(t--)

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

#define cls(a,car)  memset(a,car,sizeof (a))

#define db(x)       cerr << #x << " is " << x << '\n'

#define FL          freopen("in", "r", stdin),freopen("out", "w", stdout);

#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

#define angle(x)    double(x * acos(-1) / 180.0)

using namespace std;

typedef long long   ll;

typedef vector<int> vi;

typedef vector<ii>  vii;

const int N = 1 * 1e5 + 5;

const ll mod = 1e9 + 7;

const double E = 1e-9;

//int dx[] = {1, 0}, dy[] = {0, 1};

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

//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};

// fflush(stdout)

// cout << flush

// a + b = a ^ b + 2 * (a & b)

int n, k;

int v[N];

int dp[N];

int f(int i){

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

    int &ans = dp[i];

    if(ans != -1)return ans;

    ans = 1e9;

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

        if(i + j < n)

            ans = min(ans, f(i + j) + abs(v[i] - v[i + j]));

    }

    return ans;

}

int main(){

    //FL;

    FIN;

    cin >> n;

    fore(i, 0, n)cin >> v[i];

    cls(dp, -1);

    cout << f(0) << '\n';

    EjecuteTime;

    return 0;

}       

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

#include <cstring>

#include <cstdio>

#include <vector>

#include <map>

#include <queue>

#include <algorithm>

#include <cmath>

#include <cstdio>

#include <utility>

using namespace std;

const int N=1e5+10;

int f[N],a[N];



int main()

{

	int n;

	scanf("%d",&n);

	for(int i=1;i<=n;i++)scanf("%d",&a[i]);

	f[1]=0,f[2]=abs(a[2]-a[1]);

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

	{



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

		//printf("%d...\n",f[i]);

	}

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

   return 0;

}


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



#define clr(x) memset((x), 0, sizeof(x))

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

#define pb push_back

#define mp make_pair

#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)

#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)

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

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

#define ford(i, n) for(int i=(n)-1; i>=0; i--)

#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)

#define in(x) int (x); input((x));

#define x first

#define y second

#define less(a,b) ((a) < (b) - EPS)

#define more(a,b) ((a) > (b) + EPS)

#define eq(a,b) (fabs((a) - (b)) < EPS)

#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))

#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))

#define salfinal(x) cout<<x<<endl;

using namespace std;

const int MAX =1e5+1;

int v[MAX];

int memo[MAX];

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 <iostream>

#include <cstring>

#include <cstdio>

#include <vector>

#include <map>

#include <queue>

#include <algorithm>

#include <cmath>

#include <cstdio>

#include <utility>

using namespace std;

const int N=1e5+10;

int f[N],a[N];



int main()

{

	int n;

	scanf("%d",&n);

	for(int i=1;i<=n;i++)scanf("%d",&a[i]);

	f[1]=0,f[2]=abs(a[2]-a[1]);

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

	{



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

		//printf("%d...\n",f[i]);

	}

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

   return 0;

}


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





using namespace std;

int n;

vector<int> vec;



int meme[100007];



int solve(int index){



    if(index==n-1){

        return 0;

    }

    if(meme[index]!=-1){

        return meme[index];

    }

    

    int ret1 = 100000000;

    int ret2 = 100000000;

    if(index+1<n){

         ret1 = abs (vec[index]- vec[index+1]) + solve(index+1); 

    }

    if(index+2<n){

         ret2 = abs (vec[index]- vec[index+2]) + solve(index+2); 

    }





    return meme[index] = min(ret1,ret2);

}



int main(){

    cin>>n;

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

    int num;

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

        cin>>num;

        vec.push_back(num);

    }

    cout<<solve(0)<<endl;

    return 0;

}

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

#include <cstring>

#include <cstdio>

#include <vector>

#include <map>

#include <queue>

#include <algorithm>

#include <cmath>

#include <cstdio>

#include <utility>

using namespace std;

const int N=1e5+10;

int f[N],a[N];



int main()

{

	int n;

	scanf("%d",&n);

	for(int i=1;i<=n;i++)scanf("%d",&a[i]);

	f[1]=0,f[2]=abs(a[2]-a[1]);

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

	{



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

		//printf("%d...\n",f[i]);

	}

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

   return 0;

}


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

#define ll long long

using namespace std;

#define inf 0x3f3f3f3f 

int main(){

	ll t , h[100001] , dp[100001] = {0};

    cin >> t;

	for(int i = 0 ; i < t ; ++i) scanf("%lld",h+i);

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

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

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

        cout<<dp[t-1];

}

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

#include <cstring>

#include <cstdio>

#include <vector>

#include <map>

#include <queue>

#include <algorithm>

#include <cmath>

#include <cstdio>

#include <utility>

using namespace std;

const int N=1e5+10;

int f[N],a[N];



int main()

{

	int n;

	scanf("%d",&n);

	for(int i=1;i<=n;i++)scanf("%d",&a[i]);

	f[1]=0,f[2]=abs(a[2]-a[1]);

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

	{



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

		//printf("%d...\n",f[i]);

	}

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

   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;

typedef vector<int> vi;

typedef vector<ll> vl;

typedef pair<int,int> pii;



const int mx=1e5+11;

const double PI = acos(-1);

#define MOD 1000000007





#define nl '\n'

#define pb push_back

#define F first

#define S second

#define I insert

#define mp make_pair



#define sz(x) x.size()

#define sa(v) sort(v.begin(),v.end())

#define sd(v) sort(v.begin(),v.end(),greater<>())

#define rev(s) reverse(s.begin(),s.end())

#define tt int t; cin>>t; while(t--)

#define lo(i,a,b) for(ll i=a;i<b;i++)

#define be(a) (a).begin(),(a).end()

#define rbe(a) (a).rbegin(),(a).rend()



#define sqr(a) ((a) * (a))

#define gcd(a,b) __gcd(a,b)

#define lcm(a,b) (a*(b/gcd(a,b)))

#define mem(a,b) memset(a,b,sizeof(a))



#define yes cout<<"YES"<<nl;

#define no cout<<"NO"<<nl;



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

#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);



#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu ()

{

    cerr << endl;

}

template < typename T, typename ... hello>void faltu( T arg, const hello &... rest)

{

    cerr << arg << ' ';

    faltu(rest...);

}



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



int solve (int i)

{

    if ( i >= n )

        return 0;

    if ( dp[i]!= -1 )

        return dp[i];



    int ret1 = INT_MAX, ret2 = INT_MAX;



    if (i+1<=n )

        ret1 = abs(a[i]-a[i+1])+ solve (i+1);



    if(i+2<=n)

        ret2 = abs(a[i]-a[i+2])+solve (i+2);

    ///dbg(i);

    dp[i]= min ( ret1, ret2 );



    return dp[i];

}



int main()

{

    su;



    mem ( dp, -1 );



    cin>>n;



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

    {

        cin >>a[i];

    }



    cout << solve( 1 )<< nl;





    return 0;

}


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

#include <cstring>

#include <cstdio>

#include <vector>

#include <map>

#include <queue>

#include <algorithm>

#include <cmath>

#include <cstdio>

#include <utility>

using namespace std;

const int N=1e5+10;

int f[N],a[N];



int main()

{

	int n;

	scanf("%d",&n);

	for(int i=1;i<=n;i++)scanf("%d",&a[i]);

	f[1]=0,f[2]=abs(a[2]-a[1]);

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

	{



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

		//printf("%d...\n",f[i]);

	}

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

   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;

int h [SIZE];

int mem [SIZE];



int dp (int i) {



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

  

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

  

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



  int ret = INT_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<bits/stdc++.h>

using namespace std;





int main()

{

	int n;

	scanf("%d",&n);

	

	vector<int> v(n+1);

	

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

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

	

	vector<int> dp(n+1);

	

	dp[1] = 0;

	int x = fabs(v[1]-v[2]);

	dp[2] = x;

	

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

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

	

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

	

	return 0;

}

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

#include <queue>

#include <set>

#include <list>

#include <deque>

#include <vector>

#include <map>

#include <utility>

#include <algorithm>

#include <cmath>

#include <cstdio>

#include <string>

#include <iterator>

#define ll long long

#define pb push_back

#define pf push_front

#define ppb pop_back

#define ppf pop_front

#define powr(x,n,p) for(int axy=0 ; axy<p ; axy++){x=x*n;}

#define YES printf("YES\n")

#define Yes printf("Yes\n")

#define yes printf("yes\n")

#define NO printf("NO\n")

#define No printf("No\n")

#define no printf("no\n")

#define nl printf("\n")

#define fr0(n,q) for(q=0 ; q<n ; q++)

#define fr1(n,q) for(q=1 ; q<=n ; q++)

#define mp make_pair

#define scl(x) scanf("%lld",&x)

#define sci(x) scanf("%d",&x)

#define lst(x) x[x.size()-1]

#define llst(x) x[x.size()-2]

#define md 1000000007

#define check(x,y) (x&(1<<y))

#define set(x,y) x=x|(1<<y)

using namespace std;

int dp[100005];

int arr[100005];

int n;

int solve(int x){

	if(x>=n) return 0;

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

	int ret;

	if(x==n-1) ret=abs(arr[x+1]-arr[x])+solve(x+1);

	else ret=min(abs(arr[x+1]-arr[x])+solve(x+1),abs(arr[x+2]-arr[x])+solve(x+2));

	return dp[x]=ret;

}

int main()

{

	int i;

	cin>>n;

	for(i=0 ; i<100005 ; i++) dp[i]=-1;

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

	cout<<solve(1);

	nl;

	return 0;

}


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

using namespace std;





int main()

{

	int n;

	scanf("%d",&n);

	

	vector<int> v(n+1);

	

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

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

	

	vector<int> dp(n+1);

	

	dp[1] = 0;

	int x = fabs(v[1]-v[2]);

	dp[2] = x;

	

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

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

	

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

	

	return 0;

}

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

using namespace std;

#define ll long long int





ll a[100005];

vector<ll> cache(100005,-1);

ll n;



ll frog1(ll x)

{

	if(cache[x]!=-1)

		return cache[x];

	if(x>=n)

		return INT_MAX;

	if(x==n-1)

		return 0;

	else

		return cache[x] = min( abs(a[x+1]-a[x])+frog1(x+1), abs(a[x+2]-a[x])+frog1(x+2));

}



int main()

{

	cin>>n;

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

	{

		cin>>a[i];

	}

	cout<<frog1(0);

	return 0;

}

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

using namespace std;

#define ll long long int





//ll a[100005];

//vector<ll> cache(100005,-1);

//ll n;

//

//ll frog1(ll x)

//{

//	if(cache[x]!=-1)

//		return cache[x];

//	if(x>=n)

//		return INT_MAX;

//	if(x==n-1)

//		return 0;

//	else

//		return cache[x] = min( abs(a[x+1]-a[x])+frog1(x+1), abs(a[x+2]-a[x])+frog1(x+2));

//}

//

//int main()

//{

//	cin>>n;

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

//	{

//		cin>>a[i];

//	}

//	cout<<frog1(0);

//	return 0;

//}



int main()

{

	ll n;

	cin>>n;

	vector<int> a;

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

	{

		int x;

		cin>>x;

		a.push_back(x);

	}

	vector<int> dp(n,INT_MAX);

	dp[0] = 0;

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

	{

		for(int j=i+1;j<=i+2;j++)

		{

			if(j<n)

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

		}

	}

	cout<<dp[n-1];

	return 0;

}

// Fastest known solution for this problem: