stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
/*for better*/

#include<bits/stdc++.h>

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

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

#define fr(i,a,b) for(i=a;i>=b;i--)

#define endl '\n'

#define ll long long int

#define ff first

#define ss second

#define pb push_back

#define mod 1000000007

#define M 998244353

using namespace std;



ll n,h[100005],dp[100005][2];



ll fun(int i,int p)

{

	if(i==n-1)

		return 0;

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

		return dp[i][p];

	if(i>=n)

		return 1e9;

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

}



int main()

{

    fast; 

    int i;

    cin>>n;

    f(i,0,n)

    	cin>>h[i];

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

    cout<<min(fun(0,1),fun(0,2));

}


// Faster C++ solution for the same problem (measured speedup: 2.5143160383530896x):
/*for better*/

#include<bits/stdc++.h>

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

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

#define fr(i,a,b) for(i=a;i>=b;i--)

#define endl '\n'

#define ll long long int

#define ff first

#define ss second

#define pb push_back

#define mod 1000000007

#define M 998244353

using namespace std;



int main()

{

    fast; 

    ll n,h[100005],dp[100005],i;

    cin>>n;

    f(i,0,n)

    	cin>>h[i];

    dp[0]=0;

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

    f(i,2,n)

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

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

#include <stdlib.h>



int min(int val1, int val2)

{

    if (val1 > val2)

        return val2;

    return val1;

}



int main(void)

{

    using namespace std;

    

    int n;

    cin >> n;



    vector<int> vec(n + 1);

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

        cin >> vec.at(i);

    

    vector<int> dp(n + 1);

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

        dp.at(i) = 10000;



    dp.at(0) = 0;

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

    {

        int cost1 = dp.at(i - 1) + abs(vec.at(i - 1) - vec.at(i));

        int cost2 = 10000;

        if (i > 1)

            cost2 = dp.at(i - 2) + abs(vec.at(i - 2) - vec.at(i));

        

        dp.at(i) = min(cost1, cost2);

    }



    cout << dp.at(n - 1) << endl;

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

#include<climits>

using namespace std;



/*int memo[1000];

int compute(int a[],int n,int st){

	if(st==n-1)

		return 0;

	if(st>=n)

		return 0;



	int q1=10000,q2=10000;

	if(st-1<=n-1){

		q1=abs(a[st]-a[st+1])+compute(a,n,st+1);

		//cout<<q1<<" "<<st<<endl;

	}

	if(st-2<=n-1)

	{

		q2=abs(a[st]-a[st+2])+compute(a,n,st+2);

		//cout<<q2<<" "<<st<<endl;

	}

	return min(q1,q2);

}

int compute_memo(int a[],int n,int s){

	if(s==0)

	{

		memo[s]=0;

		return 0;

	}

	int q1=10000;

	int q2=10000;

	if(memo[s]!=-1)

		return memo[s];

	if(s-1>=0){

		q1=abs(a[s]-a[s-1])+compute_memo(a,n,s-1);

	}

	if(s-2>=0)

	{

		q1=abs(a[s]-a[s-2])+compute_memo(a,n,s-2);

	}

	cout<<s<<" "<<q1<<" "<<q2<<endl;

	memo[s]=min(q1,q2);

	return memo[s];

}*/

int dp_compute(int a[],int n){

	int dp[100009]={};

	dp[0]=0;

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

		int q1=INT_MAX,q2=INT_MAX;

		if(i-1>=0)

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

		if(i-2>=0)

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

		dp[i]=min(q1,q2);

	}

	return dp[n-1];

}



int main(){

	int n;

	cin>>n;

	int a[100009];

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

		cin>>a[i];

	}

	cout<<dp_compute(a,n)<<endl;

	return 0;

}






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

using namespace std;

#define ll  long long

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

#define endl '\n'

#define mod 1000000007



void inp()

{

    #ifndef ONLINE_JUDGE

    // for getting input from input.txt

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

    // for writing output to output.txt

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

    #endif

} 

ll min(ll a,ll b)

{

    if(a<b)

        return a;

    else

        return b;

}

 

ll max(ll a,ll b)

{

    if(a>b)

        return a;

    else

        return b;

}

int main() {

    //inp();

    fio;

    ll n;

    cin>>n;



    vector<int> nums(n);

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

    {

    	cin>>nums[i];

    }



    vector<int> dp(n,INT_MAX);

    dp[0]=0;

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

    {

    	if(i-1>=0)

    	{

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

    	}

    	if(i-2>=0)

    	{

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

    	}

    }

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



    return 0;

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

#include <cmath>

#include <cstring>

#include <string>



using namespace std;



#define MAXN 100005



int h[MAXN], dp[MAXN];



int solve(int n) {

	if(n == 1) return 0;

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

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

	if(n > 2) {

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

	}

	return dp[n];

}



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0);

	

	int n;

	cin >> n;

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

		cin >> h[i];

	}

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

	cout << solve(n) << '\n';

	

	return 0;

}

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

#include <cmath>

#include <cstring>

#include <string>



using namespace std;



#define MAXN 100005



int h[MAXN], dp[MAXN];



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0);

	

	int n;

	cin >> n;

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

		cin >> h[i];

	}

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

	

	return 0;

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

using namespace std;

int n;

int a[100009];

int res[100009];

/*lets try to understand how to write recursive eqn for the current problem

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

                  ,0 if i>=n}         

 */

int mincost(int i)

{

   if(res[i]>=0)

	   return res[i];

  		if(i>=n)

		 return 0;

	

	

  if(i<n-1)

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

  else

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

 return res[i]; 

}

int main()

{  

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

    res[i]=-1;

	cin>>n;

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

		cin>>a[i];

	 cout<<mincost(1);

}


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

using namespace std;

int main()

{

  int n,i,sum=0;

  cin>>n;

  int a[n+1],dp[n+1];

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

      cin>>a[i];

  dp[1]=0;

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

  for(i=3;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]<<endl;

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



typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

ll mod = 998244353;

#define EPS 1e-1

#define PI 3.14159265



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

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

using namespace std;



ll fastpow(ll base, ll pow)

{

    if (!base)

        return 0;

    if (!pow)

        return 1;

    if (pow == 1)

        return base;

    ll x = fastpow(base, pow / 2) % mod;

    x *= x;

    x %= mod;

    if (pow % 2)

        x *= base;

    return x % mod;

}



ll inverse(ll x)

{

    return fastpow(x, mod - 2) % mod;

}



ll fact[(int)1e6 + 5], inv[(int)1e6 + 5];

void init()

{

    fact[0] = inv[0] = 1;

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

    {

        fact[i] = (i * fact[i - 1]) % mod;

        inv[i] = inverse(fact[i]);

    }

}



void factorize(ll x, map<int, int> &ss)

{

    while (x % 2 == 0)

        ss[2]++, x /= 2;

    for (int i = 3; i <= sqrt(x); i += 2)

        while (x % i == 0)

            ss[i]++, x/= i;

    if (x > 2)

        ss[x]++;

}



ll ncr(ll n, ll r)

{

    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;

}



ll npr(ll n, ll r)

{

    return (fact[n] * inv[n - r]) % mod;

}



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

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



int n;

ll arr[(int)1e5 + 5];

ll dp[(int)1e5 + 5];



ll solve(int idx)

{

    if (idx == n)

        return 0;

    if (dp[idx] != -1)

        return dp[idx];

    ll res = 1e9;

    if (idx + 1 < n)

        res = min(res, abs(arr[idx] - arr[idx + 1]) + solve(idx + 1));

    else if (idx + 1 == n)

        res = min(res, solve(idx + 1));

    if (idx + 2 < n)

        res = min(res, abs(arr[idx] - arr[idx + 2]) + solve(idx + 2));

    else if (idx == n)

        res = min(res, solve(idx + 2));

    return dp[idx] = res;

}



int main()

{

    fastio

    cin >> n;

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

        cin >> arr[i];

    memset(dp, -1, sizeof dp);

    cout << solve(0);

    return 0;

}


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

using namespace std;

typedef long long ll;



const int N = 1e5 + 5;

const int steps = 2;

ll dp[N];

ll h[N];

int n;



int main() {

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

    cin >> n;

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

        cin >> h[i];

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

        ll start = max(0, i - steps), mn = 1e9;

        for (int j = start; j < i; j++)

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

        dp[i] = mn;

    }

    cout << dp[n - 1];

    return 0;

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



typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

ll mod = 1e9 + 7;

#define EPS 1e-1

#define PI 3.14159265



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

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

using namespace std;



ll fastpow(ll base, ll pow)

{

    if (!base)

        return 0;

    if (!pow)

        return 1;

    if (pow == 1)

        return base;

    ll x = fastpow(base, pow / 2) % mod;

    x *= x;

    x %= mod;

    if (pow % 2)

        x *= base;

    return x % mod;

}



ll inverse(ll x)

{

    return fastpow(x, mod - 2) % mod;

}



ll fact[(int)1e6 + 5], inv[(int)1e6 + 5];

void init()

{

    fact[0] = inv[0] = 1;

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

    {

        fact[i] = (i * fact[i - 1]) % mod;

        inv[i] = inverse(fact[i]);

    }

}



void factorize(ll x, map<int, int> &ss)

{

    while (x % 2 == 0)

        ss[2]++, x /= 2;

    for (int i = 3; i <= sqrt(x); i += 2)

        while (x % i == 0)

            ss[i]++, x/= i;

    if (x > 2)

        ss[x]++;

}



ll ncr(ll n, ll r)

{

    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;

}



ll npr(ll n, ll r)

{

    return (fact[n] * inv[n - r]) % mod;

}



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

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



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

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

    int n;



ll solve(int idx)

{

    if (idx >= n - 1)

        return 0;

    if (dp[idx] != -1)

        return dp[idx];

    int c1 = 1e9;

    if (idx + 1 < n)

    {

        c1 = 0;

        c1 = abs(arr[idx] - arr[idx + 1]) + solve(idx + 1);

    }

    int c2 = 1e9;

    if (idx + 2 < n)

    {

        c2 = 0;

        c2 = abs(arr[idx] - arr[idx + 2]) + solve(idx + 2);

    }

    return dp[idx] = min(c1, c2);

}



int main()

{

    fastio

    memset(dp, -1, sizeof dp);

    cin >> n;

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

        cin >> arr[i];

    cout << solve(0);

    return 0;

}


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

using namespace std;

typedef long long ll;



const int N = 1e5 + 5;

const int steps = 2;

ll dp[N];

ll h[N];

int n;



int main() {

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

    cin >> n;

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

        cin >> h[i];

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

        ll start = max(0, i - steps), mn = 1e9;

        for (int j = start; j < i; j++)

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

        dp[i] = mn;

    }

    cout << dp[n - 1];

    return 0;

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

#define debug(x) cout << #x << " = " << x << '\n'



using ll = long long;

using namespace std;



const int N = 1e5 + 1;

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



int solve(int index)

{

	if (dp[index] != -1)

		return dp[index];

	

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

}



int main()

{

	ios_base::sync_with_stdio(false);

	cin.tie(nullptr);

	cout << setprecision(10) << fixed;



#ifdef LOCAL_DEFINE

	freopen("in.txt", "r", stdin);

#endif



	int n;

	cin >> n;

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

		cin >> h[i];



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

	dp[0] = 0;

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



	cout << solve(n - 1);



	

	return 0;

}

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



using namespace std;



const int INF = 1e9;



int main() {

  ios_base::sync_with_stdio(0);

  cin.tie(0);

  int n;

  cin >> n;

  vector<int> a(n);

  for (auto &x : a)

    cin >> x;

  vector<int> dp(n, INF);

  dp[0] = 0;

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

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

    for (auto j : {i - 1, i - 2})

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

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

  return 0;

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

#define ll long long int

#define INF INT_MAX

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

using namespace std;

ll dp[100006];

ll a[100006];

ll n;

ll rec(ll idx)

{

	

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

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

	ll ans=0;

	if(idx<n-2)

	{

		ans=min(abs(a[idx]-a[idx+1])+rec(idx+1),abs(a[idx]-a[idx+2])+rec(idx+2));

	}

	else ans=abs(a[idx]-a[idx+1])+rec(idx+1);

	return dp[idx]=ans;

}

int main()

{

	chutiyaap;

	cin>>n;

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

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

	cout<<rec(0);

}


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

#define pb push_back

#define mp make_pair

#define ll long long int

#define INF INT_MAX

#define mod

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

using namespace std;



int main()

{

	chutiyaap;

	ll n;cin>>n;

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

	ll dp[n+1];

	dp[0]=0;

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

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

	{

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

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

using namespace std;

int main()

{

	long long int i,j,k,n,m,x,y,z,a[100000],b[100000]={0};

	cin>>n;

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

	cin>>a[i];

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

	{

		if(i==1)

		{

			x=a[i]-a[i-1];

			if(x<0)

			x=x*(-1);

			b[i]=x;

		}

		else

		{

			x=a[i]-a[i-1];

			y=a[i]-a[i-2];

			if(x<0)

			x=x*(-1);

			if(y<0)

			y=y*(-1);

			x=x+b[i-1];

			y=y+b[i-2];

			b[i]=min(x,y);

		}

	}

	cout<<b[n-1];

}

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

using namespace std;

#define max1 1000005

#define siz 100000

#define mod 998244353

#define inf 1e18+5

#define ll long long int

#define debug(x) cout<<#x<<" "<<x<<endl

#define jam(x) cout<<"Case #"<<x<<": "

typedef pair<ll,ll> pr;

int main()

{

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);

  cout.tie(NULL);

  /*#ifndef ONLINE_JUDGE

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

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

  #endif*/

  ll n;

  cin>>n;

  vector<ll> a(n);

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

  {

    cin>>a[i];

  }

  vector<ll> dp(n,0);

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

  {

    if(i==1)

    {

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

    }

    else

    {

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

    }

  }

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

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

using namespace         std;

#define                 int long long

#define                 pb push_back

#define                 mp make_pair

#define st(arr,a)       memset(arr,a,sizeof arr)

#define                 nl cout<<endl

#define                 real signed

#define                 endl '\n'              

#define bitcount(x)     __builtin_popcountll(x)

const int MOD = 1000000007ll;

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

#define rfor(i,a,b)     for(int i=a;i>=b;i--)



int arr[100000+50000],n;



int dp[150000];



int ans(int ind)

{

    if(ind==n)return 0;

    if(ind>n)return MOD*MOD;



    if(dp[ind]>-1)return dp[ind];



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

    return dp[ind];

}



signed main() 

{

	ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cin>>n;

    st(dp,-1);

    forn(i,1,n)cin>>arr[i];



    cout<<ans(1);



    



     

     









     return 0;



}



//       g++ -g c2.cpp ; ./a.exe

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

using namespace         std;

#define                 int long long

#define                 pb push_back

#define                 mp make_pair

#define st(arr,a)       memset(arr,a,sizeof arr)

#define                 nl cout<<endl

#define                 real signed

#define                 endl '\n'              

#define bitcount(x)     __builtin_popcountll(x)

const int MOD = 1000000007ll;

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

#define rfor(i,a,b)     for(int i=a;i>=b;i--)

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

#define pi pair<int,int>

#define X first

#define Y second

#define N 1014159

#define  vi vector<int>

#define  v  vector





int n,h[N];

int dp[N];



void solve()

{

    cin>>n;

    forn(i,1,n)cin>>h[i];

    dp[1] = 0;

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

    forn(i,3,n)

    {

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

    }

    cout<<dp[n];

    

}





signed main() 

{

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

    int t = 1;

    //cin>>t;

    while(t--)

    {

        solve();

    }







    return 0;



}



//       g++ -g c.cpp ; ./a.exe
// Slower C++ solution:
#include <bits/stdc++.h>



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



const long long INF = 1LL << 60;



using namespace std;



int main() {



    long int n; cin >> n;

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



    long long dp[100010]; rep(i,100010) dp[i] = INF;



    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;

}

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



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



const int INF = 1001001001;



using namespace std;



int main() {



    int n; cin >> n;

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



    vector<int> dp(n,INF);



    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;

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



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



const long long INF = 1LL << 60;



using namespace std;



int main() {



    long int n; cin >> n;

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



    long long dp[100010]; rep(i,100010) dp[i] = INF;



    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;

}

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



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



const int INF = 1001001001;



using namespace std;



signed main() {



    int n; cin >> n;

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



    vector<int> dp(n,INF);



    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;

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



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



const long long INF = 1LL << 60;



using namespace std;



int main() {



    long int n; cin >> n;

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



    long long dp[100010]; rep(i,100010) dp[i] = INF;



    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;

}

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



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



const int INF = 1001001001;



using namespace std;



signed main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    int n; cin >> n;

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



    vector<int> dp(n,INF);



    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;

}