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

using namespace std;



long dp[100001], a[100001], n;



long magic(int i){

	if(i == n)

		return 0;

	if(i > n)

		return 1e9 + 7;

	long &ret = dp[i];

	if(~ret)

		return ret;

	long p1, p2;

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

	p2 = abs(a[i] - a[i + 2]) + magic(i + 2);

	return ret = min(p1, p2);

}



int main(){

 

	ios::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);



	memset(dp, -1, sizeof dp);

	cin >> n;

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

		cin >> a[i];

	cout << magic(1);

	return 0;

}

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

using namespace std;



int main(){ 

    

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    

    int n, a[100001];

    cin >> n;

    vector<int> dp(n, INT_MAX);

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

        cin >> a[i];

    dp[0] = 0;

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

        if(i + 1 < n)

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

        if(i + 2 < n)

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

    }

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

    return 0;

}


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

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

using namespace std;

typedef long long ll;



int n;

vector<int> h(100000);

vector<int> cost(100000);



int ans(int n)

{

    if (cost.at(n) != -1)

        return cost.at(n);

    cost.at(n) = min(ans(n - 1) + abs(h.at(n) - h.at(n - 1)),

                     ans(n - 2) + abs(h.at(n) - h.at(n - 2)));

    return cost.at(n);

}



int main()

{

    cin >> n;

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

    {

        cin >> h.at(i);

        cost.at(i) = -1;

    }

    cost.at(0) = 0;

    cost.at(1) = abs(h.at(1) - h.at(0));

    cout << ans(n - 1) << endl;



    return 0;

}

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

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

using namespace std;

typedef long long ll;



int main()

{

    int n;

    cin >> n;

    vector<int> h(n);

    vector<int> dp(n);

    rep(i,n) {

        cin >> h[i];

        dp [i] = -1;

    }

    dp[0] = 0;

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



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

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

    }



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





    return 0;

}

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

using namespace std;



int dp[100001];



int recurse(auto& h, int i) {

	if(dp[i] != -1) {

    	return dp[i];

    } else if(i == 1) {

  		return dp[i] = 0;

    } else if(i == 2) {

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

    } else {

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

    }

}



int main() {

	int n; cin >> n;

  	vector<int> h(n + 1);

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

    	cin >> h[i];

    }

  	memset(dp, -1, sizeof dp);

  	cout << recurse(h, n);

}

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

using namespace std;



signed main() {

  	int n; cin >> n;

  	vector<int> h(n);

  	for(int& i: h) cin >> i;

  	int dp[n];

  	memset(dp, 0, sizeof dp);

  	dp[1] = abs(h[1] - h[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 - 1];

	return 0;

}

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

#define ll long long

#define ff first

#define ss second

#define mp make_pair

#define mod(d) d%1000000007

#define loop(i,s,e) for(ll i=s;i<e;i++)

#define vll vector<ll>

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

using namespace std;



int dp[1000000];



int MinimJumpCost(ll n,ll pos,int* A){

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

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

	int ans1=0;

	int ans2=0;

	int ans=0;

	if(pos<n-2){

    ans1+=abs(A[pos]-A[pos+1])+MinimJumpCost(n,pos+1,A);

    ans2+=abs(A[pos]-A[pos+2])+MinimJumpCost(n,pos+2,A); 

    ans=min(ans1,ans2);

    }

    else {

    	ans+=MinimJumpCost(n,pos+1,A)+abs(A[pos]-A[pos+1]);

    }

	return dp[pos] = ans;

}



int main(){

	

    ll n;

    cin>>n;



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



    int* A= new int[n];

    loop(i,0,n)cin>>A[i];



    cout<<MinimJumpCost(n,0,A)<<endl;



}




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

#include <ext/pb_ds/assoc_container.hpp> 

#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;

using namespace std;

 

#define ff                  first

#define ss                  second

#define endl                "\n"

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

#define int                 long long

#define vi                  vector<int> 

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

#define RS(v)               sort(v.rbegin(),v.rend())

#define R(v)                reverse(v.begin(),v.end())

#define mxpq(T)             priority_queue <T>

#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>

#define prv(v)              for(auto &x : v)cout << x << " ";

#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;

#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";

#define mp                  make_pair

#define pii                 pair<int,int>

#define mset(a,f)           memset(a , f , sizeof(a))

#define pb                  push_back

#define inf                 INT_MAX

#define INF                 LLONG_MAX

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;



const int N = 2e6 + 6;

int A[N];

int dp[N];

int n;





void solve()

{

    cin >> n;



    loop(i,0,n)cin >> A[i];



    loop(i,0,n+1)dp[i] = inf;



    dp[0] = 0;

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



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

    {

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

                dp[i-2] + abs(A[i] - A[i-2]));

    }



    cout << dp[n-1];

}

 

int32_t main()

{

 

cout<<fixed<<setprecision(16);



ios_base:: sync_with_stdio(false);

cin.tie(NULL); cout.tie(NULL);

     



     int t = 1;

     // cin >> t;

     while(t--)solve();

  

}

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



using namespace std;

int a[100005],dp[100003];

int n;

int mincost(int x)

{

	if(dp[x]!=-1)

		return dp[x];

	if(x==n)

	{

		dp[x]=0;

		return dp[x];

	}

	if(x==n-1)

	{

		if(dp[x]==-1)

			dp[x]= abs(a[n]-a[n-1]);

		return dp[x];

	}

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

	return dp[x];

}

int main()

{

	cin>>n;

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

	{

		cin>>a[i];

	}

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

	{

		dp[i]=-1;

	}

	

	cout<<mincost(1)<<'\n';

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

	// {

	// 	cout<<dp[i]<<' ';

	// }

	// cout<<'\n';



}

// Optimized solution to the same problem (faster):
//  Mayank Agarwal

//  IIIT Hyderabad







#include<bits/stdc++.h>

using namespace std;

const long long int M = 1000000007; 

#define ll long long int

#define ld double

#define pb push_back

#define mp make_pair

ll power(ll x, ll y,  ll p) 

{ 

    ll res = 1;      

    x = x % p;   

    while (y > 0) 

    { 

        if (y & 1) 

            res = (res*x) % p; 

        y = y>>1;x = (x*x) % p; 

    } return res%p; 

} 

ll modinver(ll a,ll b)

{

    return (power(a,1,M)*power(b,M-2,M))%M;

}

void SieveOfEratosthenes(int n) 

{   

    bool prime[10005]; 

    memset(prime, true, sizeof(prime)); 

  

    for (int p=2; p*p<=n; p++) 

    { 

        if (prime[p] == true) 

        { 

            for (int i=p*p; i<=n; i += p) 

                prime[i] = false; 

        } 

    } 

} 

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);cout.tie(0);

    ll n;

    cin>>n;

    ll a[100002];

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

    {

    	cin>>a[i];

    }

    ll dp[100002];

    dp[n]=0;

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

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

    {

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

    }

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

}


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

#include <algorithm>

#include <cstring>

#include <functional>

#include <bits/stdc++.h>

using namespace std;

int n,c,dp[100001];

vector<int> h;

int cost(int i)

{

    if(i==n-1)

        return 0;

    if(dp[i]!=-1)

        return dp[i];

    else

    {

        if(i+2<n)

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

        else

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

        return dp[i];

    }

}

int main()

{

    std::ios::sync_with_stdio(false);

    memset(dp,-1,sizeof dp);

    int x;

    cin>>n;

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

    {

        cin>>x;

        h.push_back(x);

    }

    cout<<cost(0)<<endl;

    return 0;

}


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

#include <algorithm>

#include <cstring>

#include <functional>

#include <bits/stdc++.h>

using namespace std;

int n;

vector<int> h;

int main()

{

    std::ios::sync_with_stdio(false);

    int x;

    cin>>n;

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

    {

        cin>>x;

        h.push_back(x);

    }

    int d[n];

    d[n-1]=0;

    d[n-2]=abs(h[n-1]-h[n-2]);

    for(int i=n-3;i>=0;i--)

    {

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

    }

    cout<<d[0];

    return 0;

}


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

#include <vector>

#include <cstdlib>

using namespace std;

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

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



const long long INF = 1LL << 60;



// 入力

int N;

long long h[100010];



// メモ用の DP テーブル

long long dp[100010];



long long rec(int i) {

    // DP の値が更新されていたらそのままリターン

    if (dp[i] < INF) return dp[i];

    

    // 足湯 0 のコストは 0

    if (i == 0) return 0;

    

    // i-1, i-2 それぞれ試す

    long long res = INF;

    chmin(res, rec(i-1) + abs(h[i] - h[i - 1])); // 足湯 i-1 から来た場合

    if (i > 1) chmin(res, rec(i-2) + abs(h[i] - h[i - 2])); // 足湯 i-2 から来た場合

    

    // 結果をメモしながら、返す

    return dp[i] = res;

}



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;

    

    // 答え

    cout << rec(N-1) << endl;

}

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

#include <vector>

using namespace std;



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

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}



const long long INF = 1LL << 60; // 十分大きい値とする



// 入力と，メモ用の DP テーブル

int N;

vector<long long> h;

vector<long long> dp;



long long rec(int i) {

    // DP の値が更新されていたらそのままリターン

    if (dp[i] < INF) return dp[i];



    // 足場 0 のコストは 0

    if (i == 0) return 0;



    // i-1, i-2 それぞれ試す

    long long res = INF;

    chmin(res, rec(i-1) + abs(h[i] - h[i - 1])); // 足場 i-1 から来た場合

    if (i > 1) chmin(res, rec(i-2) + abs(h[i] - h[i - 2])); // 足場 i-2 から来た場合



    // 結果をメモしながら、返す

    return dp[i] = res;

}



int main() {

    // 入力受け取り

    cin >> N;

    h.resize(N);

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



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

    dp.assign(N, INF);



    // 答え

    cout << rec(N-1) << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

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

#include <vector>

using namespace std;



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

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}



const long long INF = 1LL << 60; // 十分大きい値とする



// 入力と，メモ用の DP テーブル

int N;

vector<long long> h;

vector<long long> dp;



long long rec(int i) {

    // DP の値が更新されていたらそのままリターン

    if (dp[i] < INF) return dp[i];



    // 足場 0 のコストは 0

    if (i == 0) return 0;



    // i-1, i-2 それぞれ試す

    long long res = INF;

    chmin(res, rec(i-1) + abs(h[i] - h[i - 1])); // 足場 i-1 から来た場合

    if (i > 1) chmin(res, rec(i-2) + abs(h[i] - h[i - 2])); // 足場 i-2 から来た場合



    // 結果をメモしながら、返す

    return dp[i] = res;

}



int main() {

    // 入力受け取り

    cin >> N;

    h.resize(N);

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



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

    dp.assign(N, INF);



    // 答え

    cout << rec(N-1) << endl;

}


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

#include <vector>

using namespace std;

int n;

vector<int> h(100000);

vector<int> cost(100000);



int ans(int n)

{

    if (cost.at(n) != -1)

        return cost.at(n);

    cost.at(n) = min(ans(n - 1) + abs(h.at(n) - h.at(n - 1)), ans(n - 2) + abs(h.at(n) - h.at(n - 2)));

    return cost.at(n);

}



int main()

{

    cin >> n;

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

    {

        cin >> h.at(i);

        cost.at(i) = -1;

    }

    cost.at(0) = 0;

    cost.at(1) = abs(h.at(1) - h.at(0));

    cout << ans(n - 1) << endl;

}

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

using namespace std;

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

typedef long long int ll;

int main()

{

    int n;

    cin >> n;

    vector<int> h(n);

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

    rep(i, n)

    {

        cin >> h[i];

    }

    dp[0] = 0;

    rep(i, n)

    {

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

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

    }

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

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
// freopen("input.txt", "rt", stdin);

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

//#define _GLIBCXX_DEBUG//only for debugging

/*BISMILLAH UR RAHMAN*/ 

#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10);

#define endl "\n"

#define pb push_back

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

#define debug(x) std::cerr << #x << ": " << (x) << '\n';

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

#define INF INT_MAX;

using namespace std;

typedef long long int ll;

typedef pair<ll,ll> ii;

int arr[int(1e5+10)];

int cnt[int(1e5+10)];

int dp(int n)

{

  if(n<=0)return int(1e9+1);

  if(cnt[n]!=-1)return cnt[n];

  int ans=INF;

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

  return cnt[n]=ans;



}

int main()

{  

  fast

  int n;

  cin>>n;

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

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

  cnt[1]=0;

  cout<<dp(n);



  

  



}

// Optimized solution to the same problem (faster):
// freopen("input.txt", "rt", stdin);

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

//#define _GLIBCXX_DEBUG//only for debugging

/*BISMILLAH UR RAHMAN*/ 

#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10);

#define endl "\n"

#define pb push_back

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

#define debug(x) std::cerr << #x << ": " << (x) << '\n';

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

#define INF INT_MAX;

using namespace std;

typedef long long int ll;

typedef pair<ll,ll> ii;

int arr[int(1e5+10)];

int dp[int(1e5+10)];

int main()

{  

  fast

  int n;

  cin>>n;

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

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

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

  {

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



  }

 cout<<dp[n]<<endl;

  

  



}

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



using namespace std;





int main(){

    int n;

    cin >> n;

    int a[n + 1];

    int dp[n + 1];

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

    /*

    dp[0] = a[0];

    dp[1] = a[0] + a[1];

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

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

    }

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

    */

    dp[0] = 0;

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

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

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

    }

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

}

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

#include <stdio.h>

#include <stdlib.h>

#include <algorithm>

using namespace std;

//#define                     IO                                              ios_base::sync_with_stdio(0); cin.tie(0)



int main(){

    //IO;

    int n;

    //cin >> n;

    scanf("%d",&n);

    int a[n + 1];

    int dp[n + 1];

    for(int i = 0; i < n; i++) scanf("%d",&a[i]);//cin >> a[i];

    /*

    dp[0] = a[0];

    dp[1] = a[0] + a[1];

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

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

    }

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

    */

    dp[0] = 0;

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

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

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

    }

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

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

}

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



using namespace std;





int main(){

    int n;

    //cin >> n;

    scanf("%d",&n);

    int a[n + 1];

    int dp[n + 1];

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

    /*

    dp[0] = a[0];

    dp[1] = a[0] + a[1];

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

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

    }

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

    */

    dp[0] = 0;

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

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

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

    }

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

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

}

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

#include <stdio.h>

#include <stdlib.h>

#include <algorithm>

using namespace std;

//#define                     IO                                              ios_base::sync_with_stdio(0); cin.tie(0)



int main(){

    //IO;

    int n;

    //cin >> n;

    scanf("%d",&n);

    int a[n + 1];

    int dp[n + 1];

    for(int i = 0; i < n; i++) scanf("%d",&a[i]);//cin >> a[i];

    /*

    dp[0] = a[0];

    dp[1] = a[0] + a[1];

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

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

    }

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

    */

    dp[0] = 0;

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

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

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

    }

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

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

}

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



using namespace std;

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



int main(){

    IO;

    int n;

    cin >> n;

    //scanf("%d",&n);

    int a[n + 1];

    int dp[n + 1];

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

    /*

    dp[0] = a[0];

    dp[1] = a[0] + a[1];

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

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

    }

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

    */

    dp[0] = 0;

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

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

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

    }

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

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

}

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

#include <stdio.h>

#include <stdlib.h>

#include <algorithm>

using namespace std;

//#define                     IO                                              ios_base::sync_with_stdio(0); cin.tie(0)



int main(){

    //IO;

    int n;

    //cin >> n;

    scanf("%d",&n);

    int a[n + 1];

    int dp[n + 1];

    for(int i = 0; i < n; i++) scanf("%d",&a[i]);//cin >> a[i];

    /*

    dp[0] = a[0];

    dp[1] = a[0] + a[1];

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

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

    }

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

    */

    dp[0] = 0;

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

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

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

    }

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

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

}

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



using namespace std;

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



int main(){

    IO;

    int n;

    //cin >> n;

    scanf("%d",&n);

    int a[n + 1];

    int dp[n + 1];

    for(int i = 0; i < n; i++) scanf("%d",&a[i]);//cin >> a[i];

    /*

    dp[0] = a[0];

    dp[1] = a[0] + a[1];

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

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

    }

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

    */

    dp[0] = 0;

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

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

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

    }

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

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

}

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

#include <stdio.h>

#include <stdlib.h>

#include <algorithm>

using namespace std;

//#define                     IO                                              ios_base::sync_with_stdio(0); cin.tie(0)



int main(){

    //IO;

    int n;

    //cin >> n;

    scanf("%d",&n);

    int a[n + 1];

    int dp[n + 1];

    for(int i = 0; i < n; i++) scanf("%d",&a[i]);//cin >> a[i];

    /*

    dp[0] = a[0];

    dp[1] = a[0] + a[1];

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

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

    }

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

    */

    dp[0] = 0;

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

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

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

    }

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

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

}

// Fastest known solution for this problem: