stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

#include<iostream>

#include<algorithm>

#include<iomanip>

#include<string>

#include<cmath>

#include<vector>

#include<set>

#include<queue>

#include<stack>

#include<fstream>

#include<map>

#include<bitset>

#include<unordered_map>

#include<cstring>

#include<cctype>

using namespace std;

#define  ll long long

#define  ull unsigned long long

#define  ul unsigned long

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

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

#define pb(s) push_back(s);

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

#define finl "\n"

#define Mohammed_Atef_Hassan fast();

#define mod 1000000007

#define INF LLONG_MAX

#define PI acos(-1)

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

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

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

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

ll fix_mod(ll x, ll y)

{

	return (y + x % y) % y;

}

void fast() {

	std::ios_base::sync_with_stdio(false);

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





}

int n;

vector<ll>v;

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

ll solve(int i)

{

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

	ll& ret = mem[i];

	if (~ret)return ret;

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

	if (i + 2 < n)

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

	return ret;

}

int main()

{

	Mohammed_Atef_Hassan

		clr(mem, -1);

		cin >> n;

	v = vector<ll>(n);

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

	ex(solve(0));

}

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

#include <set>

using namespace std;

#define mp             make_pair

#define pb             push_back

#define fi             first

#define se             second

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

#define fill(x, y)     memset(x, y, sizeof(y))

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

typedef long long      ll;

typedef pair<int, int> ii;

typedef pair<ii, int>  iii;

typedef vector<int>    vi;

typedef vector<ii>     vii;

typedef vector<iii>    viii;



const int INF = 1e9 + 5;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int N;

  cin >> N;

  vi h(N+1);

  h[0] = INF;

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

    cin >> h[i];

  }

  vi dp(N, 0);

  dp[0] = 0;

  dp[1] = 0;

  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] << "\n";

  

  return 0;

}
// Slower C++ solution:
#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;

}


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

#include <set>

using namespace std;

#define mp             make_pair

#define pb             push_back

#define fi             first

#define se             second

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

#define fill(x, y)     memset(x, y, sizeof(y))

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

typedef long long      ll;

typedef pair<int, int> ii;

typedef pair<ii, int>  iii;

typedef vector<int>    vi;

typedef vector<ii>     vii;

typedef vector<iii>    viii;



const int INF = 1e9 + 5;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int N;

  cin >> N;

  vi h(N+1);

  h[0] = INF;

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

    cin >> h[i];

  }

  vi dp(N, 0);

  dp[0] = 0;

  dp[1] = 0;

  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] << "\n";

  

  return 0;

}
// Slower C++ solution:
#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;

}


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

#include <set>

using namespace std;

#define mp             make_pair

#define pb             push_back

#define fi             first

#define se             second

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

#define fill(x, y)     memset(x, y, sizeof(y))

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

typedef long long      ll;

typedef pair<int, int> ii;

typedef pair<ii, int>  iii;

typedef vector<int>    vi;

typedef vector<ii>     vii;

typedef vector<iii>    viii;



const int INF = 1e9 + 5;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int N;

  cin >> N;

  vi h(N+1);

  h[0] = INF;

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

    cin >> h[i];

  }

  vi dp(N, 0);

  dp[0] = 0;

  dp[1] = 0;

  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] << "\n";

  

  return 0;

}
// Slower C++ solution:
#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;

}       

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

#include <set>

using namespace std;

#define mp             make_pair

#define pb             push_back

#define fi             first

#define se             second

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

#define fill(x, y)     memset(x, y, sizeof(y))

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

typedef long long      ll;

typedef pair<int, int> ii;

typedef pair<ii, int>  iii;

typedef vector<int>    vi;

typedef vector<ii>     vii;

typedef vector<iii>    viii;



const int INF = 1e9 + 5;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int N;

  cin >> N;

  vi h(N+1);

  h[0] = INF;

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

    cin >> h[i];

  }

  vi dp(N, 0);

  dp[0] = 0;

  dp[1] = 0;

  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] << "\n";

  

  return 0;

}
// Slower C++ solution:
#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;

}


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

#include <set>

using namespace std;

#define mp             make_pair

#define pb             push_back

#define fi             first

#define se             second

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

#define fill(x, y)     memset(x, y, sizeof(y))

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

typedef long long      ll;

typedef pair<int, int> ii;

typedef pair<ii, int>  iii;

typedef vector<int>    vi;

typedef vector<ii>     vii;

typedef vector<iii>    viii;



const int INF = 1e9 + 5;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int N;

  cin >> N;

  vi h(N+1);

  h[0] = INF;

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

    cin >> h[i];

  }

  vi dp(N, 0);

  dp[0] = 0;

  dp[1] = 0;

  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] << "\n";

  

  return 0;

}
// Slower C++ solution:
#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;

}

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

#include <set>

using namespace std;

#define mp             make_pair

#define pb             push_back

#define fi             first

#define se             second

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

#define fill(x, y)     memset(x, y, sizeof(y))

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

typedef long long      ll;

typedef pair<int, int> ii;

typedef pair<ii, int>  iii;

typedef vector<int>    vi;

typedef vector<ii>     vii;

typedef vector<iii>    viii;



const int INF = 1e9 + 5;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int N;

  cin >> N;

  vi h(N+1);

  h[0] = INF;

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

    cin >> h[i];

  }

  vi dp(N, 0);

  dp[0] = 0;

  dp[1] = 0;

  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] << "\n";

  

  return 0;

}
// Slower C++ solution:
#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];

}

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

#include <set>

using namespace std;

#define mp             make_pair

#define pb             push_back

#define fi             first

#define se             second

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

#define fill(x, y)     memset(x, y, sizeof(y))

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

typedef long long      ll;

typedef pair<int, int> ii;

typedef pair<ii, int>  iii;

typedef vector<int>    vi;

typedef vector<ii>     vii;

typedef vector<iii>    viii;



const int INF = 1e9 + 5;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int N;

  cin >> N;

  vi h(N+1);

  h[0] = INF;

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

    cin >> h[i];

  }

  vi dp(N, 0);

  dp[0] = 0;

  dp[1] = 0;

  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] << "\n";

  

  return 0;

}
// Slower C++ solution:
#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;

}


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

#include <set>

using namespace std;

#define mp             make_pair

#define pb             push_back

#define fi             first

#define se             second

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

#define fill(x, y)     memset(x, y, sizeof(y))

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

typedef long long      ll;

typedef pair<int, int> ii;

typedef pair<ii, int>  iii;

typedef vector<int>    vi;

typedef vector<ii>     vii;

typedef vector<iii>    viii;



const int INF = 1e9 + 5;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int N;

  cin >> N;

  vi h(N+1);

  h[0] = INF;

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

    cin >> h[i];

  }

  vi dp(N, 0);

  dp[0] = 0;

  dp[1] = 0;

  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] << "\n";

  

  return 0;

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

using namespace std;

#define INF 100005

#define maxx 1000000000000



int n;

long long a[INF+5];

long long mem[INF];



long long rec(int pos)

{

    if(pos==n-1)

    {

        return 0;

    }

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

    long long tot=maxx;

    long long left=abs(a[pos]-a[pos+1]);

    long long right=abs(a[pos]-a[pos+2]);

    if(pos+1<n)

    {

        tot=min(tot,left+rec(pos+1));

    }

    if(pos+2<n)

    {

        tot=min(tot,right+rec(pos+2));

    }

    return mem[pos]=tot;

}



int main()

{

    memset(a,0,sizeof(a));

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

    scanf("%d",&n);

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

    {

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

    }

    long long ans=rec(0);

    printf("%lld\n",ans);

}


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

using namespace std;



int main(){

	int N; cin >> N;

  	int arr[N], dp[N];

  	

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

      cin >> arr[i];

    }

  	

  	dp[N-1] = 0;

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

  

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

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

       

    }

  	

  	cout << dp[0] << endl;

	return 0;

}
// Slower C++ solution:
// Created by ahmed_drawy on 10/09/19.

///dp educational contest atcoder - vjudge

#include <bits/stdc++.h>

#include <string.h>

#pragma clang diagnostic push

#pragma ide diagnostic ignored "OCUnusedMacroInspection"

using namespace std;

#define lp(i,start , end)       for(int i = start ; i<end ; ++i)

#define lllp(i,start , end)       for(ll i = start ; i<end ; ++i)

#define inN(arr ,  n) for(int i = 0 ; i< n ; ++i)  cin>>arr[i];

#define Rlp(i,start , end)      for(int i = start ; i>end ; --i)

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

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

#define clr(v,d)                memset(v , d , sizeof(v))

#define inf 0x3f3f3f3f

//#define dbg (v)    for(auto it : v)cout<<it<<' ';

typedef long long               ll;

typedef vector<int>             vi;

typedef vector  <ll>            vll;

typedef vector<vector<int> >    adj;

typedef pair<int ,int>          pii;

const double EPS =1e-7;

const int OO = 1e6;

#define endl '\n'

#define cint(c) (int)c -'0';

#define itc(c) (char)c +'A';

bool sortpair( const pair<int , int> & x, const pair<int , int> & y){

    return  x.first != y.first ? x.first < y.first : x.second > y.second ;

}

int dcomp(double x , double y){

    return fabs(x-y) <= EPS? 0: x>y?1:-1;

}



void smile() {

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

#ifndef ONLINE_JUDGE

//    freopen("/home/tw3/Desktop/Desktop/training/in.txt", "r", stdin);

//    freopen("/home/tw3/Desktop/Desktop/training/out.txt" , "w" , stdout);

#endif

}

#define fastin smile()



int n ;

const int N = 1e5 +3;

ll dp[N];

int h[N];

//ll solve(int indx , int state){

//    if(indx == n-1 )return 0 ;

//    ll &ret = dp[indx  ] [ state];

//    if(~ret )

//        return ret;

//    ret=  INT_MAX;

//    for (int i = 1; i <=2 && i+indx < n ; ++i) {

//        ret = min(ret , abs(h[indx]  - h[indx+ i])+solve(indx + i , i ));

//    }

//    return ret ;

//}

int main() {

    fastin;

    cin >> n;

    inN(h,  n );

    clr(dp , 0);

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

        if(j>=2){

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

        }

        else if(j ==1){

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

        }

    }

    cout << dp[n-1];

//

//    clr(dp , -1);

//    cout << solve(0, 1)<<endl;

}

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

using namespace std;



int main(){

	int N; cin >> N;

  	int arr[N], dp[N];

  	

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

      cin >> arr[i];

    }

  	

  	dp[N-1] = 0;

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

  

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

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

       

    }

  	

  	cout << dp[0] << endl;

	return 0;

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

using namespace std;

typedef long long int ll;

const int MAX=1e5+10;

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

int solve(int idx)

{

    if(idx==N)return 0;

    if(idx>N)return 1e9;

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

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

}

int  main ()

{

    memset(dp,-1,sizeof dp);

    cin >> N;

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

        cin >> A[i];

    }

    cout<<solve(1)<<endl;

    return 0;

}


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

using namespace std;



int main(){

	int N; cin >> N;

  	int arr[N], dp[N];

  	

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

      cin >> arr[i];

    }

  	

  	dp[N-1] = 0;

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

  

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

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

       

    }

  	

  	cout << dp[0] << endl;

	return 0;

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

using namespace std;



#define mp make_pair

#define pb push_back

#define st first

#define nd second

#define lb lower_bound

#define ub upper_bound



typedef long long ll;

typedef long double ld;

typedef pair<int,int> pi;

typedef pair<ll,ll> pll;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef vector<pi> vpi;

typedef vector<pll> vpll;



const ll oo=1e18;

const int MOD=1000000007;

const int INF=1000000000;

const ld EPS=0.000000001;



int dp[100005],h[100005],n,k=2;



signed main() {

    ios_base::sync_with_stdio(NULL);

    cin.tie(NULL);

    cout.tie(NULL);

    memset(dp,0x3f3f,sizeof dp);

    dp[1]=0;

    h[0]=0;

    cin>>n;

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

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

        for(int j=1;j<=min(k,i);++j) {

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

        }

    }

    cout<<dp[n];

    return 0;

}


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

using namespace std;



int main(){

	int N; cin >> N;

  	int arr[N], dp[N];

  	

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

      cin >> arr[i];

    }

  	

  	dp[N-1] = 0;

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

  

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

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

       

    }

  	

  	cout << dp[0] << endl;

	return 0;

}