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

using namespace std;



int dp[101010];



int main() {

	int n;

	cin >> n;

	vector< int > h(n);

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



	fill_n(dp, 101010, 1e9+1);

	dp[0] = 0;

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

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

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

	}



	int ans = dp[n-1];

	cout << ans << endl;

	

  return 0;

}


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

using namespace std;







int main() {

	int n; cin >> n;

	vector< int > h(n);

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



	vector< int > dp(n+1, 1e9+1);



	dp[0] = 0;

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

		if (i>0) 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;

	

  return 0;

}


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

#include<climits>



using namespace std;

#define ll long long int

#define Max 110000



int main() {

	int n;

	cin>>n;

	int arr[n];

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

	{

		cin>>arr[i];

	}

	ll dp[Max+1];

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

	{

		dp[i]=INT_MAX;

	}

	dp[0]=0;

	//cout<<dp[1];

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

	{

		if(i+1<n)

		{

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

		}

		if(i+2<n)

		{

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

		}

	}

	cout<<dp[n-1];

	return 0;

}

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

#define ll long long int

using namespace std;

ll solve(int cost[],int n)

{

	ll dp[n];

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

		dp[i]=INT_MAX;

	dp[0]=0;

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

	{

		if(i+1<n)

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

		if(i+2<n)

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

	}

	return dp[n-1];

}

int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	int n;

	cin>>n;

	int cost[n];

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

		cin>>cost[i];

	long long int ans=solve(cost,n);

	cout<<ans;

	return 0;

}

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

using namespace std;

int v[100010];

int dp[100010];

int f(int i){

    if(i == 1) return 0;

    if(i == 2) return abs(v[1]-v[2]);

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

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

    return dp[i];

}

int main(){

    memset(dp,-1,sizeof dp);

    memset(v,0,sizeof v);

    int n;

    cin>>n;

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

    cout<<f(n)<<"\n";

    return 0;

}


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

using namespace std;

#define PB push_back

#define MP make_pair

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

typedef long long ll;

typedef int i;

typedef vector<i>vi;

typedef pair<i,i>pi;

int v[100010];

int dp[100010];

int f(int i){

	if(i < 0) return 1e8;

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

	int &r = dp[i];

	r = min(f(i-1)+abs(v[i]-v[i-1]) , f(i-2)+abs(v[i]-v[i-2]));

	return r;



}



int main(){

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

	ios::sync_with_stdio(0);

	cin.tie(0);

	int n;cin>>n;

	fora(i,0,n){

		cin>>v[i];

	}

	memset(dp, -1,sizeof dp);

	dp[0] = 0;

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

	cout<<f(n-1)<<"\n";

	

	return 0;

}

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

using namespace std;

int dp[100005];

int n,arr[100005];

int func(int i)

{

    int ans1=0,ans2=0;

    if(i>=n) return 0;

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

    ans1 = abs(arr[i]-arr[i+1])+func(i+1);

    if(i<=n-2) ans2=abs(arr[i]-arr[i+2])+func(i+2);

    else ans2=123456;

    return dp[i]=min(ans1,ans2);

}

int main()

{

    int i;

    cin>>n;



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

    memset(dp,-1,sizeof dp);

    int ans = func(1);

    cout<<ans;

}


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

using namespace std;

int dp[100005];

int main()

{

    int n,i;

    cin>>n;

    int arr[n+2];

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



    dp[1]=0;

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



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

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

    }

    cout<<dp[n]<<endl;

}


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



#define fast1 ios_base::sync_with_stdio(false)

#define fast2 cin.tie(NULL)

#define ll long long



using namespace std;



int main(){



    int n;

    cin >> n;



    int a[n];

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

        cin >> a[i];

    }



    int dp[100008];

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

        dp[i]=INT_MAX;

    }





    dp[0]=0;



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

        if(i==n-2){

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

        }else{

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

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

        }

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

    }



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





    return 0;

}


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

using namespace std;



int main(){



	int n;

	cin >> n;



	vector<int> a(n);

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

		cin >> a[i];

	}



	vector<int> dp(n,INT_MAX);

	dp[n-1]=0;





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

		if(i+1<n){

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

		}

		if(i+2<n){

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

		}

	}



	cout << dp[0] << "\n";





	return 0;

}

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

#include <vector>

#include <map>

using namespace std;



int N;

int h[111111];

int dp[111111];

int main(){

    cin >> N;

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

        cin >> h[i];



    fill_n(dp, 111111, 1<<30);

    dp[0] = 0;

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

        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;

    return 0;

}

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

using namespace std;

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

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(int i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }

template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }



int main(){

    int N;

    cin >> N;

    vector<int> h(N);

    REP(i, N) cin >> h[i];

    vector<int> dp(N, 1<<30);

    dp[0] = 0;

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

        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;

}

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

using namespace std;

typedef long long int lli;

typedef vector <int> vi;

typedef vector <vi> vvi;

typedef pair <int,int> pr;

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

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

#define pb push_back

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

#define tr(c, i) for (typeof ((c).begin() i = (c).begin(); i != (c).end(); i++)

#define present(c, x)((c).find(x) != (c).end())

#define cpresent(c, x)(find(all(c), x) != (c).end())

// for mod power a^b%m use power<lli> (a,b,m)

template < class mytype >

mytype power(mytype a, mytype b, mytype m){if (b == 1) return a % m;if (b == 0) return 1;

lli root = power < lli > (a, b / 2, m);lli ans = (root * root) % m;if (b % 2) ans = (ans * a) % m;

return ans;

}

// for gcd use gcd<int> (a,b)

template < class type >type gcd(type a, type b){if (a == 0) return b;else return gcd(b % a, a);}

template < class type >type mod_inv(type a, type p) {return power(a, p - 2, p);}



// use from here bitches

int n;

vector<int> height(100002) , values(100002 , -1);

int dp(int x){

if(values[x] != -1) return values[x];

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

if(x >= n-2) return values[x] = abs(height[x+1] - height[x]);

else return values[x] = min(abs(height[x+1] - height[x]) + dp(x+1) , abs(height[x+2] - height[x]) + dp(x+2));

}





int main()

{    

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cin >> n;

	fr(i , n){

		cin >> height[i];

	}

	cout << dp(0);

		



	





    return 0;

	

}


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

using namespace std;

typedef long long int lli;

typedef vector <int> vi;

typedef vector <vi> vvi;

typedef pair <int,int> pr;

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

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

#define pb push_back

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

#define tr(c, i) for (typeof ((c).begin() i = (c).begin(); i != (c).end(); i++)

#define present(c, x)((c).find(x) != (c).end())

#define cpresent(c, x)(find(all(c), x) != (c).end())

// for mod power a^b%m use power<lli> (a,b,m)

template < class mytype >

mytype power(mytype a, mytype b, mytype m){if (b == 1) return a % m;if (b == 0) return 1;

mytype root = power < lli > (a, b / 2, m);mytype ans = (root * root) % m;if (b % 2) ans = (ans * a) % m;

return ans;

}

// for gcd use gcd<int> (a,b)

template < class type >type gcd(type a, type b){if (a == 0) return b;else return gcd(b % a, a);}

template < class type >type mod_inv(type a, type p) {return power(a, p - 2, p);}





int main()

{

    int n;

    cin >> n;

    vector<int> h(n) , cost(n , 1e9+7);

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

    cost[0] = 0;

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

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

            if(j < n) cost[j] = min(cost[j] , cost[i] + abs(h[i] - h[j]));

        }

    }

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

    return 0;

}


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

using namespace std;

typedef long long int lli;

typedef vector <int> vi;

typedef vector <vi> vvi;

typedef pair <int,int> pr;

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

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

#define pb push_back

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

#define tr(c, i) for (typeof ((c).begin() i = (c).begin(); i != (c).end(); i++)

#define present(c, x)((c).find(x) != (c).end())

#define cpresent(c, x)(find(all(c), x) != (c).end())

// for mod power a^b%m use power<lli> (a,b,m)

template < class mytype >

mytype power(mytype a, mytype b, mytype m){if (b == 1) return a % m;if (b == 0) return 1;

mytype root = power < lli > (a, b / 2, m);mytype ans = (root * root) % m;if (b % 2) ans = (ans * a) % m;

return ans;

}

// for gcd use gcd<int> (a,b)

template < class type >type gcd(type a, type b){if (a == 0) return b;else return gcd(b % a, a);}

template < class type >type mod_inv(type a, type p) {return power(a, p - 2, p);}

int n;

vector<int> h(100001);

vector<int> cost(100001 , -1);



int dp(int index){

    if(cost[index] != -1) return cost[index];

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

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

    return cost[index];

    }

int main()

{

    cin >> n;cost[0] = 0;

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

        cin >> h[i];

    }

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







    return 0;

}


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

using namespace std;

typedef long long int lli;

typedef vector <int> vi;

typedef vector <vi> vvi;

typedef pair <int,int> pr;

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

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

#define pb push_back

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

#define tr(c, i) for (typeof ((c).begin() i = (c).begin(); i != (c).end(); i++)

#define present(c, x)((c).find(x) != (c).end())

#define cpresent(c, x)(find(all(c), x) != (c).end())

// for mod power a^b%m use power<lli> (a,b,m)

template < class mytype >

mytype power(mytype a, mytype b, mytype m){if (b == 1) return a % m;if (b == 0) return 1;

mytype root = power < lli > (a, b / 2, m);mytype ans = (root * root) % m;if (b % 2) ans = (ans * a) % m;

return ans;

}

// for gcd use gcd<int> (a,b)

template < class type >type gcd(type a, type b){if (a == 0) return b;else return gcd(b % a, a);}

template < class type >type mod_inv(type a, type p) {return power(a, p - 2, p);}





int main()

{

    int n;

    cin >> n;

    vector<int> h(n) , cost(n , 1e9+7);

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

    cost[0] = 0;

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

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

            if(j < n) cost[j] = min(cost[j] , cost[i] + abs(h[i] - h[j]));

        }

    }

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

    return 0;

}


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

using namespace std;



#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )

template <typename Arg1>

void __f( const char* name , Arg1&& arg1 ) {

        cerr << name << " : " << arg1 << "\n";

}

template <typename Arg1, typename... Args>

void __f( const char* na , Arg1&& arg1 , Args&&... args ) {

        const char* c = strchr( na + 1 , ',' );

        cerr.write( na , c - na ) << " : " << arg1 << " , ";

        __f( c + 1 , args... );

}

#define endl "\n"

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

#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())

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

typedef long long int LL;

typedef pair <int,int> pii;

const int MOD = 1e9 + 7;

const int inf = 1e9;

const double EPS = 1e-9;

const double PI = acos(-1.0);

const long long INF = 1e18;

const int N = 1e5 + 5;



int n;

int h[ N ];

int dp[ N ];



int solve( int idx ) {

        if( idx == n ) return 0;

        if( idx > n ) return inf;

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

        int ret = inf;

        ret = min( ret , solve( idx + 1 ) + abs( h[idx+1] - h[idx] ) );

        ret = min( ret , solve( idx + 2 ) + abs( h[idx+2] - h[idx] ) );

        return dp[idx] = ret;

}

int main( ) {

        IO;

        #ifdef LOCAL

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

        #endif // LOCAL

        cin >> n;

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

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

        cout << solve( 1 ) << endl;

        return 0;

}










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

using namespace std;



#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void __f(const char* name, Arg1&& arg1) {

  cerr << name << " : " << arg1 << "\n";

}

template <typename Arg1, typename... Args>

void __f(const char* na, Arg1&& arg1, Args&&... args) {

  const char* c = strchr(na + 1, ',');

  cerr.write(na, c - na) << " : " << arg1 << " , ";

  __f(c + 1, args...);

}

#define endl "\n"

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

#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())

typedef long long LL;

typedef pair <int,int> pii;

const double pi = acos(-1.0);

const double eps = 1e-8;

const int mod = 1e9 + 7;

const int inf = 1e9;

const LL INF = 1e18;

const int N = 1e5 + 5;



int main() {

  ios_base::sync_with_stdio(false);

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

  #ifdef LOCAL

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

  #endif // LOCAL

  int n;

  cin >> n;

  vector <LL> h (n + 1);

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

  vector <LL> dp (n + 1, INF);

  dp[1] = 0;

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

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

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

  }

  cout << dp[n] << endl;

  return 0;

}


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

using namespace std;



#define ll long long



int dp[100001];

int n, arr[100001];

int pound(int pos)

{

    if (dp[pos] != -1)

        return dp[pos];

    

    return dp[pos] = min(abs(arr[pos] - arr[pos - 1]) + pound(pos - 1), abs(arr[pos] - arr[pos - 2]) + pound(pos - 2));

    

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    cin >> n;



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

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

        cin >> arr[i];



    dp[0] = 0;

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

    

    cout << pound(n - 1);



    return 0;

}


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

using namespace std;



#define ll long long



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

  

    int n;

    cin >> n;



    int arr[n], dp[n];



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

        cin >> arr[i];



    dp[0] = 0;

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

    

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

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



    cout << dp[n - 1];



    return 0;

}


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



using namespace std;



typedef long long ll;



const int mx = 100050;

int arr[mx];

int dp[mx];

int n;



int func(int idx)

{

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

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



    int nxt = idx+1;

    int ans  , ret;

    ans = 1e9;

    ans += 100;

    if(nxt < n)

    {

        ret = abs(arr[nxt]-arr[idx]) + func(nxt);

        ans = min(ans,ret);

    }

    nxt = idx+2;

    if(nxt < n)

    {

        ret = abs(arr[nxt]-arr[idx]) + func(nxt);

        ans = min(ans,ret);

    }



    return dp[idx] = ans;

}



int main()

{

    scanf("%d",&n);



    int i, j , k , p , q;



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

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

    int ans = func(0);



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



    return 0;

}


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



using namespace std;



typedef long long ll;



const int mx = 100050;

int arr[mx];

int dp[mx];

int n;





int main()

{

    scanf("%d",&n);



    int i, j , k , p , q;



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



    dp[0] = 0;



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

    {

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

        if(i > 1)

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

    }



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



    return 0;

}


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

using namespace std;



const int N = 1e5 + 5 , INF = 2e9;



int n;

int h[N];

int mem[N];



int dp(int i){

    if(i == n)return 0;



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

    int ans = INF;



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

    if(i <= n-2){

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

    }



    return mem[i] = ans;

}



main(){

    scanf("%d" , &n);



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

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

    }

    n --;

    memset(mem , -1 , sizeof mem);

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

}


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


#include <bits/stdc++.h>



using namespace std;



const int N   = 1e5 + 5;

const int INF = 2e9;



int jump[N];

int h[N];

int n;





main(){



    scanf("%d" , &n);

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

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

    }



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

            jump[i] = INF;

    }



    jump[0] = 0;

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



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



            if(i + 2 < n) {

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

            }

    }



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



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):


#include <bits/stdc++.h>



using namespace std;





const int N = 1e5 + 5;



int n;

int h[N];

int mem[N];



int jump(int i){

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



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



    int x = abs(h[i] - h[i + 1]) + jump(i + 1);

    int y = x;



    if(i + 2 < n) y = abs(h[i] - h[i + 2]) + jump(i + 2);



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

    return mem[i];

}



main(){

    scanf("%d" , &n);



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

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

    }



    memset(mem , -1 , sizeof mem);

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



    return 0;

}


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


#include <bits/stdc++.h>



using namespace std;



const int N   = 1e5 + 5;

const int INF = 2e9;



int jump[N];

int h[N];

int n;





main(){



    scanf("%d" , &n);

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

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

    }



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

            jump[i] = INF;

    }



    jump[0] = 0;

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



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



            if(i + 2 < n) {

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

            }

    }



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



    return 0;

}


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

#define ll long long int

using namespace std;



ll n;

ll dp[1000005];



int solve(ll a[], int i)

{

	if (i == n - 1)

	{

		return 0;

	}

	if (i > n - 1)

	{

		return INT_MAX;

	}



	if (dp[i] != -1)

	{

		return dp[i];

	}



	int value;

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



	return dp[i] = value;

}



int main()

{

	cin >> n;

	ll a[n];

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

	{

		cin >> a[i];

	}

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

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

	return 0;

}

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

#define ll long long int

using namespace std;



int n;

int dp[1000005];

/*

int solve(ll a[], int i)

{

	if (i == n - 1)

	{

		return 0;

	}

	if (i > n - 1)

	{

		return INT_MAX;

	}



	if (dp[i] != -1)

	{

		return dp[i];

	}



	int value;

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



	return dp[i] = value;

}

*/



int main()

{

	cin >> n;

	int a[n];

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

	{

		cin >> a[i];

	}

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

	return 0;

}


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



using namespace std;

int n;

int ar[100005];

long long mem[100005];



long long solve(int ind){

    if(ind==n-1){

        return 0;

    }

    if(ind>n-1){

        return 1e11;

    }

    if(mem[ind]!=-1){

        return mem[ind];

    }

    long long ch1=0,ch2=0;

    ch1=solve(ind+1)+abs(ar[ind+1]-ar[ind]);

    ch2=solve(ind+2)+abs(ar[ind+2]-ar[ind]);

    return mem[ind]=min(ch1,ch2);

}



int main() {

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

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

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    memset(mem,-1,sizeof mem);

    cin>>n;

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

        cin>>ar[i];

    }

    cout<<solve(0)<<endl;

    return 0;

}

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



using namespace std;

#define ll long long



const int INF = 1e9+5;



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int n;

    cin>>n;

    int ar[n];

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

        cin>>ar[i];

    }

    vector<int> dp(n,INF);

    dp[0]=0;

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

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

            if(j<n){

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

            }

        }

    }

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



    return 0;

}

// Fastest known solution for this problem: