stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

#define endl '\n'

#define ll long long

using namespace std;



const int MXN = 1e5 + 5;

int n;

int h[MXN];

int dp[MXN];



int Dp(int idx) {

    if(idx == n - 1) return 0; // caso base

    if(dp[idx] != -1) return dp[idx]; // caso dp

    int ans = Dp(idx + 1) + abs(h[idx] - h[idx + 1]);

    if(idx + 2 < n) ans = min(ans, Dp(idx + 2) + abs(h[idx] - h[idx + 2])); 

    return dp[idx] = ans; // guardar

}



int main() {

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

    cin >> n;

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

        cin >> h[i];

    }

    memset(dp, -1, sizeof dp);

    cout << Dp(0) << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4161243914284698x):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

ll dp[100005];

int main()

{

   ll n;

   cin>>n;

   ll a[n];

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

    cin>>a[i];

   }

   dp[n-1]=0;

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

    if(i==n-2){

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

    }

    else{

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

    }

   }

   cout<<dp[0];

    return 0;

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

using namespace std;



const int inf=0x3f;

int h[100005],dp[100005];



signed main()

{

	int n;

	while(cin>>n){

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

		memset(dp,inf,sizeof dp);

		

		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;

}

// Faster C++ solution for the same problem (measured speedup: 1.403896823097773x):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

ll dp[100005];

int main()

{

   ll n;

   cin>>n;

   ll a[n];

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

    cin>>a[i];

   }

   dp[n-1]=0;

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

    if(i==n-2){

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

    }

    else{

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

    }

   }

   cout<<dp[0];

    return 0;

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

using namespace std;

vector<int> dp(100001,-1);



int back(vector<int> &N, int index){

	if(index+2==N.size()){

		return abs(N[index]-N[index+1]);

	}

	if(index+1==N.size()){

		return 0;

	}

	if(dp[N.size()-index]!=-1)return dp[N.size()-index];

	int a = abs(N[index]-N[index+1]) + back(N,index+1);

	int b = abs(N[index]-N[index+2]) + back(N,index+2);

	

	dp[N.size()-index] = min(a,b);

	return dp[N.size()-index];

}



int main(){

//	10 30 40 20

	int n;

	cin>>n;

	vector<int> N(n);

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

		cin>>N[i];

	}

	dp[0]=0;

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



	cout<<back(N,0);	

}

// Faster C++ solution for the same problem (measured speedup: 1.414762636911768x):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

ll dp[100005];

int main()

{

   ll n;

   cin>>n;

   ll a[n];

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

    cin>>a[i];

   }

   dp[n-1]=0;

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

    if(i==n-2){

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

    }

    else{

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

    }

   }

   cout<<dp[0];

    return 0;

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

using namespace std;

#define mod 1000000009

#define ll long long

#define mp make_pair

#define pb push_back

#define ff first

#define ss second

#define set0(a) memset ((a), 0 , sizeof(a))

#define set1(a) memset((a),-1,sizeof (a))

#define pi pair<int, int>

#define ps pair<string, string>

#define pl pair<long, long>

#define pll pair<long long, long long>

#define vll vector<long long>

#define vl vector<long>

#define vi vector<int>

#define vs vector<string>

#define vps vector< ps >

#define vpi vector< pi >

#define vpl vector< pl >

#define vpll vector< pll >

#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);

#define tc(t,T) for(long long t=0;t<T;t++)

#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)

#define meax 100007

 vll a(meax,0);

  vll b(meax,meax);

  ll sum1=0;

ll maximize(ll i,ll n,ll prev){



    if(b[i]!=meax){

        return b[i];

    }

    if(i>=n){

        return meax;

    }



    if(i==n-1){

            b[i]=0;

        return b[i];

    }

    ll d1=maximize(i+1,n,a[i]);

    ll d2=maximize(i+2,n,a[i]);

    b[i]=min(abs(a[i]-a[i+1])+d1,abs(a[i+2]-a[i])+d2);

    return b[i];





}

int main(){

    ll n;

    cin>>n;



    rep(i,0,n,1){

        cin>>a[i];

    }

    ll d=maximize(0,n,a[0]);

    cout<<d<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 2.6268729653707856x):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

ll dp[100005];

int main()

{

   ll n;

   cin>>n;

   ll a[n];

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

    cin>>a[i];

   }

   dp[n-1]=0;

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

    if(i==n-2){

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

    }

    else{

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

    }

   }

   cout<<dp[0];

    return 0;

}
// Slower C++ solution:
/**

 * @author      : Luis Miguel Baez <es.luismiguelbaez@gmail.com>

 * @created     : Thursday August 13, 2020

 */



#include <bits/stdc++.h>



using namespace std;



#define endl '\n'

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

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

#define ms(arr, value) memset(arr, value, sizeof arr)

#define ll    int64_t



#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "



string to_string(string s) {

    return '"' + s + '"';

}



string to_string(bool b) {

    return (b ? "true" : "false");

}



// add template here



template <typename A>

string to_string(A v) {

    bool first = true;

    string res = "{";

    for (const auto &x : v) {

        if (!first) {

            res += ", ";

        }

        first = false;

        res += to_string(x);

    }

    res += "}";

    return res;

}



template<class T>

void println(const T &data) {

#ifndef ONLINE_JUDGE

    cout << to_string((T)data) << endl;

#endif

}





const int oo  = (int)(1e9);

const ll lloo  = (ll)(1e18);



const int N = 1e5 + 10;



class Task {

public:

    int n;

    vector<int> A;



    ll dp[N];



    ll go(int index) {

        if(index > n) return 0LL;

        if(index == n) {

            return 0LL;

        }



        ll &ans = dp[index];

        if(ans != -1) return ans;



        ll x = oo;

        ll y = oo;



        if(index+1 <= n) {

            x = abs(A[index]-A[index+1]) + go(index + 1);

        }

        

        if(index+2 <= n) {

            y = abs(A[index]-A[index+2]) + go(index + 2);

        }

        ll mn = min(x, y);

        if(mn == oo) {

            ans = 0;

            return ans;

        }

        ans = min(x, y);

        return ans;

    }



    ll solveOne(istream &in, ostream &out) {

        in >> n;

        A.resize(n+1);

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

            in >> A[i];

        }

        memset(dp, -1, sizeof dp);

        ll ans = go(1);

        return ans;  

    }

    

    void solve(istream &in, ostream &out) {

        int t = 1;

        while(t--) {

            out << solveOne(in, out) << endl;

        }

    }

};



auto main() -> int {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    

    Task solver;

    istream &in(cin);

    ostream &out(cout);

    solver.solve(in, out);

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.8319613664093284x):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

ll dp[100005];

int main()

{

   ll n;

   cin>>n;

   ll a[n];

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

    cin>>a[i];

   }

   dp[n-1]=0;

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

    if(i==n-2){

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

    }

    else{

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

    }

   }

   cout<<dp[0];

    return 0;

}
// Slower C++ solution:


#include<bits/stdc++.h>

#define lld         long long int

#define llf         long double

#define pb          push_back

#define mp          make_pair

#define IN          insert

#define loopN(n)    for(lld i=0;i<n;i++)

#define loop(p,n)   for(lld i=p;i<=n;i++)

#define rloop(p,n)  for(lld i=n;i>=p;i--)

#define loop2(p,n)  for(lld j=p;j<=n;j++)

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

#define F1          first

#define F2          second

#define INF         2e18

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

#define PI          2*acos(0.0)

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

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

#define case(z)     cout<<"Case "<<z<<": ";

using namespace std;

const lld mod=1e9+7;



lld n;

lld a[100005];

lld dp[100005];



lld fun(lld p)

{



    if(p==n-1)

    {

        return 0;

    }

    if(p==n-2)

    {

        return abs(a[p]-a[p+1]);

    }

    if(dp[p]!=-1)

    {

        return dp[p];

    }

    return dp[p]=min(abs(a[p]-a[p+2])+fun(p+2),abs(a[p]-a[p+1])+fun(p+1));





}



int main()

{

    ISO;



    //lld t;cin>>t;while(t--)

    mem(dp,-1);

    cin>>n;

    loopN(n)cin>>a[i];

    cout<<fun(0)<<endl;



    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.8193283152543211x):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

ll dp[100005];

int main()

{

   ll n;

   cin>>n;

   ll a[n];

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

    cin>>a[i];

   }

   dp[n-1]=0;

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

    if(i==n-2){

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

    }

    else{

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

    }

   }

   cout<<dp[0];

    return 0;

}
// Slower C++ solution:


#include <bits/stdc++.h>



using namespace std;





#define ll              long long

#define pb              push_back

#define nn           cout << "\n";





ll dp[100000],ht[100000];

int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    ll t,a,b,i,j,c,d,e,f,n,k,m,w;



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



    cin>>n;

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

    {

        cin>>a;

        ht[i]=a;



    }



    dp[n]=0;dp[n+1]=10000000;ht[n+1]=10000000;

    for(i=n-1;i>=1;i--)

    {

        

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

    }



    cout<<dp[1];

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.8184599142373163x):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

ll dp[100005];

int main()

{

   ll n;

   cin>>n;

   ll a[n];

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

    cin>>a[i];

   }

   dp[n-1]=0;

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

    if(i==n-2){

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

    }

    else{

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

    }

   }

   cout<<dp[0];

    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: 2.7628594006154987x):
#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)

#define cos(i) (long double)cos(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; }



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



int main()

{

    andrew;

    int n;

    cin >> n;

    vector<ll>v(n + 1);

    v[0] = 0;

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

        cin >> v[i];



    vector<ll>mem(100005, 1e9);

    

    mem[0] = 0;

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

    {

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

        {

            if (j < n)

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



        }

    }



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



    









}
// 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: 5.131061724048378x):
#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)

#define cos(i) (long double)cos(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; }



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



int main()

{

    andrew;

    int n;

    cin >> n;

    vector<ll>v(n + 1);

    v[0] = 0;

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

        cin >> v[i];



    vector<ll>mem(100005, 1e9);

    

    mem[0] = 0;

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

    {

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

        {

            if (j < n)

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



        }

    }



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



    









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



using namespace std;



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



int sol(int i, int choice){

    if(i==0) return 0;

    if(i<0) return 1E9;



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

    if(~ret) return ret;



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

}



int main()

{

    cin >> n;

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

        cin >> h[i];



    memset(dp, -1, sizeof dp);

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

}


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

#define cos(i) (long double)cos(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; }



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



int main()

{

    andrew;

    int n;

    cin >> n;

    vector<ll>v(n + 1);

    v[0] = 0;

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

        cin >> v[i];



    vector<ll>mem(100005, 1e9);

    

    mem[0] = 0;

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

    {

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

        {

            if (j < n)

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



        }

    }



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



    









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

using namespace std;

#define mod 1000000009

#define ll long long

#define mp make_pair

#define pb push_back

#define ff first

#define ss second

#define set0(a) memset ((a), 0 , sizeof(a))

#define set1(a) memset((a),-1,sizeof (a))

#define pi pair<int, int>

#define ps pair<string, string>

#define pl pair<long, long>

#define pll pair<long long, long long>

#define vll vector<long long>

#define vl vector<long>

#define vi vector<int>

#define vs vector<string>

#define vps vector< ps >

#define vpi vector< pi >

#define vpl vector< pl >

#define vpll vector< pll >

#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);

#define tc(t,T) for(long long t=0;t<T;t++)

#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)

#define meax 100007

 vll a(meax,0);

  vll b(meax,meax);

  ll sum1=0;

ll maximize(ll i,ll n,ll prev){



    if(b[i]!=meax){

        return b[i];

    }

    if(i>=n){

        return meax;

    }



    if(i==n-1){

            b[i]=0;

        return b[i];

    }

    ll d1=maximize(i+1,n,a[i]);

    ll d2=maximize(i+2,n,a[i]);

    b[i]=min(abs(a[i]-a[i+1])+d1,abs(a[i+2]-a[i])+d2);

    return b[i];





}

int main(){

    ll n;

    cin>>n;



    rep(i,0,n,1){

        cin>>a[i];

    }

    ll d=maximize(0,n,a[0]);

    cout<<d<<endl;

}


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

#define cos(i) (long double)cos(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; }



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



int main()

{

    andrew;

    int n;

    cin >> n;

    vector<ll>v(n + 1);

    v[0] = 0;

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

        cin >> v[i];



    vector<ll>mem(100005, 1e9);

    

    mem[0] = 0;

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

    {

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

        {

            if (j < n)

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



        }

    }



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



    









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

using namespace std;

typedef long long int ll;

ll dp[100005],ara[100005];

ll ans(ll n)

{

    if(n==1)

    {

        dp[1]=0;

    }

    if(n==2)

    {

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

        return dp[2];

    }

    if(dp[n]!=-1)

        return dp[n];

    dp[n]=min((ans(n-1)+abs(ara[n]-ara[n-1])),ans(n-2)+abs(ara[n]-ara[n-2]));

    return dp[n];

}

int main()

{

    ll n;

    int i;

    cin>>n;

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

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

    {

        cin>>ara[i];

    }

    cout<<ans(n)<<endl;

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.797465332864264x):
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

const int INF = 10e9+5;

int main()

{

    int n,x,i,j;

    cin>>n;

    vector<int>v;

    vector<int>dp(n,INF);

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

   {

       cin>>x;

       v.push_back(x);

   }

    dp[0]=0;

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

    {

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

        {

            if(j<n)

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

        }

    }

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

    return 0;

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

#include <vector>

#include <string>

#include <algorithm>

#include<climits>

using namespace std;



#define ll long long

#define tc                int T;cin>>T;while(T--)

int a[100000];

int main()

{

	int n, c, b ; cin >> n;

	for (int& e : a)cin >> e;

	vector<int> dp(n, INT_MAX);

	dp[0] = 0;

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

		for (int e : {i + 1, i + 2}) {

			if (e < n)

				if ((dp[i] + abs(a[e] - a[i])) < dp[e])

					dp[e] = dp[i] + abs(a[e] - a[i]);

		}

	}

	cout << dp[n - 1] << '\n';

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.1791541521885143x):
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

using namespace std;



#define ll long long

#define tc                int T;cin>>T;while(T--)

const int INF =1e9+5;

int main()

{

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

	int n, c, b ; cin >> n;

  	vector<int> a(n,0);

	for (int& e : a)cin >> e;

	vector<int> dp(n, INF);

	dp[0] = 0;

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

		for (int e : {i + 1, i + 2}) {

			if (e < n)

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

		}

	}

	cout << dp[n - 1] << '\n';

	return 0;

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

#include <vector>

#include <string>

#include <algorithm>

#include<climits>

using namespace std;



#define ll long long

#define tc                int T;cin>>T;while(T--)

int a[100000];

int main()

{

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

	int n, c, b ; cin >> n;

	for (int& e : a)cin >> e;

	vector<int> dp(n, INT_MAX);

	dp[0] = 0;

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

		for (int e : {i + 1, i + 2}) {

			if (e < n)

				if ((dp[i] + abs(a[e] - a[i])) < dp[e])

					dp[e] = dp[i] + abs(a[e] - a[i]);

		}

	}

	cout << dp[n - 1] << '\n';

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.955354952763806x):
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

using namespace std;



#define ll long long

#define tc                int T;cin>>T;while(T--)

const int INF =1e9+5;

int main()

{

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

	int n, c, b ; cin >> n;

  	vector<int> a(n,0);

	for (int& e : a)cin >> e;

	vector<int> dp(n, INF);

	dp[0] = 0;

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

		for (int e : {i + 1, i + 2}) {

			if (e < n)

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

		}

	}

	cout << dp[n - 1] << '\n';

	return 0;

}