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

using namespace std;



typedef long double LD;

typedef long long ll;

typedef map<int,int> mii;

typedef pair<int,int> pii;

typedef vector<pii> vpii;



#define pb              push_back

#define mp              make_pair

#define F               first

#define S               second

#define mod             1000000007

#define INF             2147483647

#define Endl            "\n"

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

#define precision(a)    cout << fixed << setprecision(a)

#define bug(a,b)        cout<<a<<"\t"<<b<<"\n";

#define Case(a,b)       cout<<"Case "<<a<<": "<<b<<"\n";

#define reset(a,b)      memset(a,b,sizeof(a));

#define srt(a)      sort(a.begin(),a.end());



const int MAXN = 1000005;

const int SQRTN = 1003;

const int LOGN = 22;

const double PI=acos(-1);

const int sz=1e5+9;



int strtoint(string str){

    stringstream ss(str);

    int x = 0;

    ss >> x ;

    return x ;

}

string intostr(int x){

    stringstream ss;

    ss << x;

    string str = ss.str();

    return str;

}

void rem(string &s, const string &c) {

	auto pos = s.find(c);

	if (pos == string::npos) {

		cout << -1 << endl;

		exit(0);

	}

	s.erase(0, pos + 1);

}

void println (int n){

    cout<<n<<"\n";

}

void printvec(vector <int> &a){

    for (int i=0;i<a.size();i++){

        cout<<a[i]<<" ";

    }

    cout<<"\n";

}



void printgraph(vector <int> g[],int e){

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

        cout<<i<<" --> ";

        for (int j=0;j<g[i].size();j++){

            cout<<g[i][j]<<" ";

        }

        cout<<"\n";

    }

}



void printmap (map <int,int> &mymap){

    for (auto itr = mymap.begin(); itr != mymap.end(); ++itr) {

        cout << '\t' << itr->first

             << '\t' << itr->second << '\n';

    }

    cout << "\n";

}



int n,x,arr[sz],dp[sz];





int rec (int i){

    if (i==n) return 0;

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

    int left = abs(arr[i]-arr[i+1])+rec(i+1);

    int right = INF;

    if (i+2<=n){

        right = abs(arr[i]-arr[i+2])+rec (i+2);

    }

    return dp[i]= min(left,right);

}





void solve(){



    cin>>n;

    reset (dp,-1);

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





    cout << rec (1) << Endl;



    //printvec(v);

}





int main(){

    //FasterIO;



    solve();

    return 0;

}


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



using namespace std;



int N, ns[100000+9];

int dp[100000+9];

int main(){

    scanf("%d",&N);

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

    dp[0]=0, dp[1]=abs(ns[0]-ns[1]);

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

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

    }

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

    return 0;

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



using namespace std;



const int N = 1e5; // Maximum stones as per problem



int n, stones[N];



int memo[N]; // Memoization Table



int jumps(int ind) {

    if (ind == (n - 1)) return 0; // If we are last stone, then the answer will be 0.

    if (ind >= n) return INT_MAX; // Checking the boundary condition





    // If you are done with the whole function, then only read

    // Since we stored the minimum cost for a stone, now we will use the stored cost

    // We are initializing the table to -1, if the value stored is not -1, then we have calculated the minimum cost

    // So just return that cost

    if (memo[ind] != -1) return memo[ind]; // If reading for first time, then ignore this line



    // Calculate the cost for jumping to next stone (ind + 1) and recursively doing it for next stone

    int oneJump = abs(stones[ind] - stones[ind + 1]) + jumps(ind + 1);



    // Initializing the twoJumps because there can be a case in which there can be only one stone.

    int twoJumps = INT_MAX;



    // Checking if there are more than 2 stones

    if (ind + 2 < n) {

        // Calculate the cost for jumping to next to next stone (ind + 2) and recursively doing it for next to next stone

        twoJumps = abs(stones[ind] - stones[ind + 2]) + jumps(ind + 2);

    }



    // Storing the minimum cost in the memoization table and returning the minimum cost

    // After this,  go to the ignored line.

    return memo[ind] = min(oneJump, twoJumps);

}





int main() {

    // Initializing the memoization table to -1

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



    cin >> n;

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

        cin >> stones[i];

    }



    // We will start from first stone

    cout << jumps(0) << endl;



    return 0;

}

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



using namespace std;



int N, ns[100000+9];

int dp[100000+9];

int main(){

    scanf("%d",&N);

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

    dp[0]=0, dp[1]=abs(ns[0]-ns[1]);

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

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

    }

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

    return 0;

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

using namespace std;

#define ll long long

#define ull unsigned long long

#define INF 1e18

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

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

typedef vector<int> vi;

typedef vector<ll> vll;

typedef pair<int,int> pi;



#define M_PI 3.14159265358979323846



int a[100005];

const int oo = 1e9+10;

const int mod = 7901;



ll gcd(ll a, ll b){return a==0 ? b : gcd(b%a, a);}



int dp[100005];

int n;

int memo[100005];



int dpF(int i){

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

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

	

	int ans = abs(a[i] - a[i+1])+dpF(i+1);

	if(i+2 <= n-1){

		ans = min(ans, abs(a[i]-a[i+2])+dpF(i+2));

	}



	return memo[i] = ans;

}



void solve(){

	cin>>n;

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

	

	memset(memo, -1 , sizeof memo);

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

	return;

	dp[0] = 0;

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

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

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

	}

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

}

int main(){   

    ios::sync_with_stdio(0);cin.tie(0);

	int t=1;

	while(t--){

		solve();

	}

}

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



using namespace std;



int N, ns[100000+9];

int dp[100000+9];

int main(){

    scanf("%d",&N);

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

    dp[0]=0, dp[1]=abs(ns[0]-ns[1]);

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

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

    }

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

    return 0;

}
// 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.4256095425412725x):
#include <iostream>



using namespace std;



int N, ns[100000+9];

int dp[100000+9];

int main(){

    scanf("%d",&N);

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

    dp[0]=0, dp[1]=abs(ns[0]-ns[1]);

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

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

    }

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

    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.4133000743901498x):
#include <iostream>



using namespace std;



int N, ns[100000+9];

int dp[100000+9];

int main(){

    scanf("%d",&N);

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

    dp[0]=0, dp[1]=abs(ns[0]-ns[1]);

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

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

    }

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

    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.4242386670409568x):
#include <iostream>



using namespace std;



int N, ns[100000+9];

int dp[100000+9];

int main(){

    scanf("%d",&N);

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

    dp[0]=0, dp[1]=abs(ns[0]-ns[1]);

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

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

    }

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

    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.6444676676310475x):
#include <iostream>



using namespace std;



int N, ns[100000+9];

int dp[100000+9];

int main(){

    scanf("%d",&N);

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

    dp[0]=0, dp[1]=abs(ns[0]-ns[1]);

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

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

    }

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

    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.8442317788804257x):
#include <iostream>



using namespace std;



int N, ns[100000+9];

int dp[100000+9];

int main(){

    scanf("%d",&N);

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

    dp[0]=0, dp[1]=abs(ns[0]-ns[1]);

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

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

    }

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

    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.8315141119953695x):
#include <iostream>



using namespace std;



int N, ns[100000+9];

int dp[100000+9];

int main(){

    scanf("%d",&N);

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

    dp[0]=0, dp[1]=abs(ns[0]-ns[1]);

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

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

    }

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

    return 0;

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

using namespace std;

int dif(int a, int b)

{

    int ans=a-b;

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

    return ans;

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

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

    int f1,f2;

    cin>>N;

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

        cin>>h[i];

    int M[100005]={0};

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

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

    {

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

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

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

    }

    cout<<M[0]<<endl;

    return 0;

}


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



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

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

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

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

using namespace std;

typedef long long LL;

typedef pair<LL, LL> ii;

typedef vector<LL> vi;



template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }



void dbg_out() { cerr << "\n"; }

template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }



void solve(){

    int n;

    cin >> n;

    vi h(n);

    for(auto &it: h) cin >> it;



    vi dp(n, 1e9+5);

    dp[0] = 0;

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

        for(int j = max(i-2, 0); j < i; ++j){

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

        }

    }

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

}



int main()

{

    Fast;

    //louisfghbvc{

        solve();

    //}

    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: 4.947591708553337x):
#include <bits/stdc++.h>



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

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

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

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

using namespace std;

typedef long long LL;

typedef pair<LL, LL> ii;

typedef vector<LL> vi;



template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }



void dbg_out() { cerr << "\n"; }

template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }



void solve(){

    int n;

    cin >> n;

    vi h(n);

    for(auto &it: h) cin >> it;



    vi dp(n, 1e9+5);

    dp[0] = 0;

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

        for(int j = max(i-2, 0); j < i; ++j){

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

        }

    }

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

}



int main()

{

    Fast;

    //louisfghbvc{

        solve();

    //}

    return 0;

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

using namespace std;



typedef signed long long ll;

const int MX = 1e5 + 5;

const int INF = 1e9 + 5;

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



int solve(int pos) {

    if(pos > n) return INF;

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

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

    int ans = INF;

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

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

    return dp[pos] = ans;

}



int main() {

    scanf("%d", &n);



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

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

    }

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

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

    return 0;

}

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



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

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

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

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

using namespace std;

typedef long long LL;

typedef pair<LL, LL> ii;

typedef vector<LL> vi;



template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }



void dbg_out() { cerr << "\n"; }

template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }



void solve(){

    int n;

    cin >> n;

    vi h(n);

    for(auto &it: h) cin >> it;



    vi dp(n, 1e9+5);

    dp[0] = 0;

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

        for(int j = max(i-2, 0); j < i; ++j){

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

        }

    }

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

}



int main()

{

    Fast;

    //louisfghbvc{

        solve();

    //}

    return 0;

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

#include<cmath>

#include<algorithm>

#include<cstring>

using namespace std;



int h[100055],dp[100055];

const int inf = 0x3f3f3f;

int main()

{

	int n;

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

	cin>>n;

	h[1]=inf;

	h[0]=inf;

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

		cin>>h[i];

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

	{

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

	}

		

	cout<<dp[n]<<endl;

	return 0;

} 

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

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



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

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

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

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

using namespace std;

typedef long long LL;

typedef pair<LL, LL> ii;

typedef vector<LL> vi;



template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }



void dbg_out() { cerr << "\n"; }

template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }



void solve(){

    int n;

    cin >> n;

    vi h(n);

    for(auto &it: h) cin >> it;



    vi dp(n, 1e9+5);

    dp[0] = 0;

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

        for(int j = max(i-2, 0); j < i; ++j){

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

        }

    }

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

}



int main()

{

    Fast;

    //louisfghbvc{

        solve();

    //}

    return 0;

}