stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <cstdlib>

using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



const long long INF = 1LL << 60;



// 入力

int N;

long long h[100010];



// DP テーブル

long long dp[100010];



int main() {

    int N; cin >> N;

    for (int i = 0; i < N; ++i) cin >> h[i];



    // 初期化 (最小化問題なので INF に初期化)

    for (int i = 0; i < 100010; ++i) dp[i] = INF;



    // 初期条件

    dp[0] = 0;



    // ループ

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

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

        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));

    }



    // 答え

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

}

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

using namespace std;



typedef long long ll;

const ll INF = 1LL << 60;



template<class T> inline bool chmin(T &a,T b){

    if(a > b){

        a = b;

        return 1;

    }

    return 0;

}





int main(void){

    int N;

    cin >> N;

    ll h[N];

    ll dp[N];

    

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

        cin >> h[i];

    }

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

        dp[i] = INF;

    }

    

    dp[0] = 0;

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

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

        if(i > 1){

            chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));

        }

    }

    

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

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

#include <vector>

#include <cstdlib>

using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



const long long INF = 1LL << 60;



// 入力

int N;

long long h[100010];



// DP テーブル

long long dp[100010];



int main() {

    int N; cin >> N;

    for (int i = 0; i < N; ++i) cin >> h[i];



    // 初期化 (最小化問題なので INF に初期化)

    for (int i = 0; i < 100010; ++i) dp[i] = INF;



    // 初期条件

    dp[0] = 0;



    // ループ

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

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

        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));

    }



    // 答え

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

}

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

using namespace std;



typedef long long ll;

const ll INF = 1LL << 60;





int main(void){

    int N;

    cin >> N;

    ll h[N];

    ll dp[N];

    

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

        cin >> h[i];

    }

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

        dp[i] = INF;

    }

    

    dp[0] = 0;

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

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

        if(i > 1){

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

        }

    }

    

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

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

#include <vector>

#include <cstdlib>

using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



const long long INF = 1LL << 60;



// 入力

int N;

long long h[100010];



// DP テーブル

long long dp[100010];



int main() {

    int N; cin >> N;

    for (int i = 0; i < N; ++i) cin >> h[i];



    // 初期化 (最小化問題なので INF に初期化)

    for (int i = 0; i < 100010; ++i) dp[i] = INF;



    // 初期条件

    dp[0] = 0;



    // ループ

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

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

        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));

    }



    // 答え

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

}

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

using namespace std;



typedef long long ll;

const ll INF = 1LL << 60;



template<class T> inline bool chmin(T &a,T b){

    if(a > b){

        a = b;

        return 1;

    }

    return 0;

}





int main(void){

    int N;

    cin >> N;

    ll h[100010];

    ll dp[100010];

    

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

        cin >> h[i];

    }

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

        dp[i] = INF;

    }

    

    dp[1] = 0;

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

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

        chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));

    }

    

    cout << dp[N] << endl;

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



using namespace std;



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

#define pi acos(-1)

#define eps 1e-6

#define inf 1e14



typedef long long ll;

typedef vector<int> vi;

typedef pair<int, int> ii;

typedef vector<ii> vii;

typedef vector<vi> vvi;



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

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

const int maxn = 2 * 1e5;

const int mod = 1e9 + 7;

const int maxa = 2 * 1e5;



int mul(int a, int b) { return a * 1LL * b % mod;}

int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b;}

int sub(int a, int b) { return a >= b ? a - b : a - b + mod;}

int pow(int a, int k)

{

    int res = 1;

    while (k)

    {

        if (k % 2) res = mul(res, a);

        a = mul(a, a);

        k /= 2;

    }



    return res;

}



int inv(int a)

{

    return pow(a, mod - 2);

}



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



int f(int id)

{

    if (id == n - 1)

        return 0;



    if (dp[id] != -1)

        return dp[id];



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

    

    if (id + 2 <= n - 1)

        dp[id] = min(dp[id], f(id + 2) + abs(h[id] - h[id + 2]));

                     

    return dp[id];

}



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

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

    cin >> n;

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

        cin >> h[i];



    cout << f(0);

}


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



using namespace std;



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

#define pi acos(-1)

#define eps 1e-6

#define inf 1e14



typedef long long ll;

typedef vector<int> vi;

typedef pair<int, int> ii;

typedef vector<ii> vii;

typedef vector<vi> vvi;



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

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

const int maxn = 2 * 1e5;

const int mod = 1e9 + 7;

const int maxa = 2 * 1e5;



int mul(int a, int b) { return a * 1LL * b % mod;}

int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b;}

int sub(int a, int b) { return a >= b ? a - b : a - b + mod;}

int pow(int a, int k)

{

    int res = 1;

    while (k)

    {

        if (k % 2) res = mul(res, a);

        a = mul(a, a);

        k /= 2;

    }



    return res;

}



int inv(int a)

{

    return pow(a, mod - 2);

}



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



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cin >> n;

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

        cin >> h[i];



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

    {

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

        if (i > 1)

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

    }

    

    cout << dp[n - 1];

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

using namespace std;



#define INF 0x3f3f3f3f

#define MAXN 100010

#define endl "\n"

#define abs(a, b) ((a > b) ? a-b : b-a)



typedef long long int ll;



/* End */



int n;

ll a[MAXN];

ll pd[MAXN];



ll solve(int i) {

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

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

	return pd[i] = min(solve(i+1) + abs(a[i], a[i+1]),

			   (i < n-2) ?  solve(i+2) + abs(a[i], a[i+2]) : INF);

}



int main() {

	cin.tie(NULL);

	ios_base::sync_with_stdio(false);

	

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



	cin >> n;

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



	cout << solve(0) << endl;



	return 0;

}


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

using namespace std;



#define INF 0x3f3f3f3f

#define MAXN 100010

#define endl "\n"

#define abs(a, b) ((a > b) ? a-b : b-a)



typedef long long int ll;



/* End */



int n;

ll a[MAXN];

ll pd[MAXN];



int main() {

	cin.tie(NULL);

	ios_base::sync_with_stdio(false);

	

	cin >> n;

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



	pd[n-1] = 0;

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

		if (i < n-2) pd[i] = min(pd[i+1] + abs(a[i], a[i+1]),

			                 pd[i+2] + abs(a[i], a[i+2]));

		else pd[i] = abs(a[i], a[i+1]);

	}



	cout << pd[0] << endl;



	return 0;

}
// Slower C++ solution:
// Author : Mohamed Sameh

#include <bits/stdc++.h>

typedef long long ll ;

#define pb push_back

#define f first

#define s second

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

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

#define SZ(a) (int)a.size()

#define Flush fflush(stdout);

using namespace std ;

const int M = 1e5 + 2 ;

int n;

int a[M];

int dp[M];

int solve (int i )

{

    if (i >= n )return 1e9 ;

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

    int &ret = dp[i];

    if (~ret)return ret ;

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

}

int main()

{

    scanf ("%d" , &n );

    for (int i =0 ; i < n ;i++)scanf ("%d" , a+i );

    a[n] =0 ;

    a[n+1] = 0;

    memset(dp , -1 ,sizeof dp );

    cout << solve(0) <<"\n";

}


// Faster C++ solution for the same problem (measured speedup: 1.4008049126459865x):
// Author : Mohamed Sameh

#include <bits/stdc++.h>

typedef long long ll ;

#define pb push_back

#define f first

#define s second

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

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

#define SZ(a) (int)a.size()

#define Flush fflush(stdout);

using namespace std ;

const int M = 1e5 + 2 ;

int n;

int a[M];

int dp[M];

int main()

{

    scanf ("%d" , &n );

    for (int i =0 ; i < n ;i++)scanf ("%d" , a+i );

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

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

    {

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

    }

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

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



using namespace std;



int n;

int a[100000];

int dp[100000];



int solve(int i)

{

	if (i == n - 1)

		return dp[i] = 0;

	if (dp[i] != -1)

		return dp[i];

	int ans = INT_MAX;

	if (i < n - 1)

		ans = min(ans, abs(a[i] - a[i + 1]) + solve(i + 1));

	if (i < n - 2)

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

	return dp[i] = ans;

}

int main()

{

	cin >> n;

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

		cin >> a[i];

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

	cout << solve(0) << endl;

	return 0;

}


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



using namespace std;



int n;

int a[100000];

int dp[100000];



int main()

{

	cin >> n;

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

		cin >> a[i];

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

	return 0;

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

using namespace std;

 

#define DEBUG if(1)

#define MAX INT_MAX

#define MAXLL INT_MAX

#define MAXU ULLONG_MAX

#define MIN -2000000

#define endl "\n"

#define INF INT_MAX

#define MOD 1000000007

#define s(n) scanf("%d", &n)

#define ss(a,b) scanf("%d %d",&a,&b)

#define pb push_back

#define mp make_pair

#define M_PI 3.14159265358979323846

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

#define lli long long int

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

#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef pair<lli,lli> ii;

#define DEBUG if(1)

#define F first

#define S second

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

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

int ddx[] = {1, 0};

int ddy[] = {1, 1};

#define MAXN 200010

#define MAXL 20



int n;

vi vec;



lli pd[MAXN][2];



lli solve(int i, int last){

	if(i == sz(vec) - 1) return 0;



	lli &ans = pd[i][last];

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



	lli a = INT_MAX, b = INT_MAX;

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



		if(i < sz(vec) - 2)

		b = solve(i+2, 2) + abs(vec[i] - vec[i+2]);



	return ans = min(a, b);

}



int main(){

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);



  cin >> n;

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

  	int a;

  	cin >> a;

  	vec.pb(a);

  }



  memset(pd, -1, sizeof pd);



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



  return 0;

}

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

using namespace std;

 

#define DEBUG if(1)

#define MAX INT_MAX

#define MAXLL INT_MAX

#define MAXU ULLONG_MAX

#define MIN -2000000

#define endl "\n"

#define INF INT_MAX

#define MOD 1000000007

#define s(n) scanf("%d", &n)

#define ss(a,b) scanf("%d %d",&a,&b)

#define pb push_back

#define mp make_pair

#define M_PI 3.14159265358979323846

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

#define lli long long int

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

#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef pair<lli,lli> ii;

#define DEBUG if(1)

#define F first

#define S second

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

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

int ddx[] = {1, 0};

int ddy[] = {1, 1};

#define MAXN 200010

#define MAXL 20



int n;

vector<lli> vec;



lli pd[MAXN][2];



int main(){

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);



  cin >> n;

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

  	int a;

  	cin >> a;

  	vec.pb(a);

  }



  for(int i=0;i<=n;i++) for(int j=0;j<=2;j++) pd[i][j] = INT_MAX;



  pd[1][1] = abs(vec[1] - vec[0]);

	pd[2][2] = abs(vec[2] - vec[0]);



  for(int i=1;i<sz(vec);i++){



  	pd[i+1][1] = min(pd[i+1][1], pd[i][1] + abs(vec[i] - vec[i+1]));

  	pd[i+1][1] = min(pd[i+1][1], pd[i][2] + abs(vec[i] - vec[i+1]));

  	pd[i+2][2] = min(pd[i+2][2], pd[i][2] + abs(vec[i] - vec[i+2]));

  	pd[i+2][2] = min(pd[i+2][2], pd[i][1] + abs(vec[i] - vec[i+2]));



  }



 // for(int i=0;i<sz(vec);i++){

  //	for(int j=1;j<=2;j++) cout << pd[i][j] << " ";

  	//	cout << endl;

  //}



  cout << min(pd[n-1][1], pd[n-1][2]);



  return 0;

}
// Slower C++ solution:
// {{{ Headers

// vim:filetype=cpp:foldmethod=marker:foldmarker={{{,}}}



#include <cassert>

#include <cctype>

#include <cmath>

#include <climits>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <ctime>



#include <algorithm>

#include <deque>

#include <functional>

#include <iterator>

#include <list>

#include <map>

#include <numeric>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <utility>

#include <vector>



#include <fstream>

#include <iostream>

#include <sstream>



using namespace std;

// }}}



typedef long long int64;

const int INF = 0x3f3f3f3f;

template <class T> inline int len (const T &a) { return a.size (); }

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



const int MX = 100 * 1000 + 5;

int a [MX];

int dp [MX];



int

main () {

    int N;

    scanf ("%d", &N);

    for (int i = 0; i < N; i++) scanf ("%d", a + i);

    memset (dp, INF, sizeof (dp));

    dp [0] = 0;

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

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

            if (i >= j)

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

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



#ifdef LOCALHOST

	cerr << "time: " << (int64) clock () * 1000 / CLOCKS_PER_SEC << " ms" << endl;

#endif

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.4131657283010657x):
// {{{ Headers

// vim:filetype=cpp:foldmethod=marker:foldmarker={{{,}}}



#include <cassert>

#include <cctype>

#include <cmath>

#include <climits>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <ctime>



#include <algorithm>

#include <deque>

#include <functional>

#include <iterator>

#include <list>

#include <map>

#include <numeric>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <utility>

#include <vector>



#include <fstream>

#include <iostream>

#include <sstream>



using namespace std;

// }}}



typedef long long int64;

const int INF = 0x3f3f3f3f;

template <class T> inline int len (const T &a) { return a.size (); }

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



const int MX = 100 * 1000 + 5;

int a [MX];

int dp [MX];



int

main () {

    int N;

    scanf ("%d", &N);

    for (int i = 0; i < N; i++) scanf ("%d", a + i);

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

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

        if (i >= 2)

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

    }

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



#ifdef LOCALHOST

	cerr << "time: " << (int64) clock () * 1000 / CLOCKS_PER_SEC << " ms" << endl;

#endif

    return 0;

}
// Slower C++ solution:
//srinivas

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>

// #include <ext/pb_ds/tree_policy.hpp>

// #include <ext/pb_ds/assoc_container.hpp>

//#include <boost/multiprecision/cpp_int.hpp>

using namespace std;

//using namespace boost::multiprecision;

// using namespace __gnu_pbds;



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

#define endl "\n"

#define ff first

#define ss second

#define allr(c) (c).rbegin(),(c).rend()

#define fr(x,in,n,r) for(x=in;x<n;x+=r)

#define ifr(x,n) for(x=0;x<n;x++)

#define dfr(x,n) for(x=n;x>=1;x--)

#define pb(a) push_back(a)

#define pf(a) push_front(a)

#define pof(a) pop_front(a)

#define pob(a) pop_back(a)

#define eb(a) emplace_back(a)

#define ef(a) emplace_front(a)

typedef long long ll;

typedef map<ll,ll> mll;

typedef map<string,ll> msll;

typedef vector<ll> vll;

typedef pair<ll,ll> pll;

typedef long double ld;

#define mod 1000000007

#define N 100001



ll dp[N+2];



ll fun(ll a[],ll n)

{

	if(n==0 || n==1)

		return dp[n];

	if(dp[n]!=-1)

		return dp[n];

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

	return dp[n];

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

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

    ll n,i,j;

    cin>>n;

	ll a[n];

	ifr(i,N) dp[i]=-1;

	ifr(i,n)

		cin>>a[i];

	dp[0]=0;

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

	fun(a,n-1);

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.7929571138767555x):
//srinivas

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>

// #include <ext/pb_ds/tree_policy.hpp>

// #include <ext/pb_ds/assoc_container.hpp>

//#include <boost/multiprecision/cpp_int.hpp>

//using namespace boost::multiprecision;

// using namespace __gnu_pbds;

using namespace std;



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

#define endl "\n"

#define ff first

#define ss second

#define allr(c) (c).rbegin(),(c).rend()

#define fr(x,in,n,r) for(x=in;x<n;x+=r)

#define ifr(x,n) for(x=0;x<n;x++)

#define dfr(x,n) for(x=n-1;x>=0;x--)

#define pb(a) push_back(a)

#define pf(a) push_front(a)

#define pof(a) pop_front(a)

#define pob(a) pop_back(a)

#define eb(a) emplace_back(a)

#define ef(a) emplace_front(a)

typedef long long ll;

typedef map<ll,ll> mll;

typedef map<string,ll> msll;

typedef vector<ll> vll;

typedef pair<ll,ll> pll;

typedef long double ld;

#define mod 1000000007



struct chash{ 

    ll operator()(ll x) const {return hash<ll>{}(x);}

};



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

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

    ll n,i,j;

    cin>>n;

    ll a[n];

    ifr(i,n)cin>>a[i];

    if(n==1){

       	cout<<"0\n";

       	return 0;

    }

    ll dp[n];

    dp[0]=0;

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

    fr(i,2,n,1)

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

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

	return 0;

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

using namespace std;

#define INF 1000000000

int dp(int i);

int n;

int h[100009],memo[100009];



int main(){

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

  cin>>n;

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

  cout<<dp(0)<<endl;

  return(0);

}



int dp(int i){

  int rec=INF;

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

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

  if(i+1<n)rec=min(rec,dp(i+1)+abs(h[i]-h[i+1]));

  if(i+2<n)rec=min(rec,dp(i+2)+abs(h[i]-h[i+2]));

  return memo[i]=rec;

}


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

using namespace std;

int dp[100009];



int main(){

  int n;

  int h[100009];

  cin>>n;

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

    cin>>h[i];

  }

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

    if(i-2>=0){

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

    }

    else if(i-1>=0){

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

    }

  }

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

  return(0);

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

using namespace std;

#define INF 1000000000

int dp(int i);

int n;

int h[100009],memo[100009];



int main(){

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

  cin>>n;

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

  cout<<dp(0)<<endl;

  return(0);

}



int dp(int i){

  int rec=INF;

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

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

  if(i+1<n)rec=min(rec,dp(i+1)+abs(h[i]-h[i+1]));

  if(i+2<n)rec=min(rec,dp(i+2)+abs(h[i]-h[i+2]));

  return memo[i]=rec;

}


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

using namespace std;

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

#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)

#define fi first

#define se second

#define INF 1000000009

#define LLINF 1000000000000000009LL

using ll = long long;



int main(){

  int n;

  cin>>n;

  vector<int>h(n);

  rep(i,n)cin>>h[i];

  vector<int>dp(n,INF);

  dp[0]=0;

  rep(i,n){

    if(i+1<n){

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

    }

    if(i+2<n){

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

    }

  }

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

  return(0);

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

using namespace std;

#define ll long long int 

const ll ARR = 1e5 + 2;

const ll INF = 1e4+2;

#define pb(x) push_back(x)

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

#define gof for(long long int i = 0 ; i < n ; i++)



void solve(){



	ll n;

	cin >> n;

	ll a[ARR];

	gof cin >> a[i];

	ll dp[ARR] = {INF};

	dp[0] = 0;

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

	for(ll 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]));

	}

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

	return;

}



int main(){

	ll t = 1;

	//cin >> t;

	while(t--){

		solve();

	}

	return 0;

}


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

using namespace std;



#define ll 				long long int

#define gof 			for(long long int i = 0 ; i < n ; i++)

#define for1(i,s,e) 	for(long long int i = s ; i < e ; i++)

#define forr(i,e,s) 	for(long long int i = e ; i >= s; i--)

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

#define vi 				vector<long long int>

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

#define pb(x) 			push_back(x)

#define maxv(x) 		*max_element(x)

#define minv(x) 		*min_element(x)

#define mkvec(type,a,n) vector<type> a(n)



const ll ARR = 1e5;

const ll INF = 1e9;

const ll mod = 1e9+7;



void IO()

{

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

#ifndef ONLINE_JUDGE

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

    //freopen("output.txt", "w", stdout);

#endif

}



void solve(){



	int n;

	cin >> n;

	ll a[ARR+2];

	gof cin >> a[i];



	ll dp[ARR+2];

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



	for1(i,2,n){

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

	}



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



}



int main(){

	IO();

    ll t = 1;

    //cin >> t;

    while(t--) solve();

    return 0;

}