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

  Vivek Rathi

  CSE 2nd Year

  MNNIT

*/

#include<bits/stdc++.h>

using namespace std;

#define M 1000000007

#define ll long long int

#define pb push_back

#define pf push_front

#define pob pop_back

#define pof pop_front

#define debug1(x) cout<<#x<<" "<<x<<endl;

#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;

#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;

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

#define null NULL

#define mp make_pair

#define fi first

#define se second

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

#define inf 1e17

#include <ext/pb_ds/assoc_container.hpp> 

#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

ll n,h[100001];

ll dp[100001];

ll solve(ll i)

{

	if(i==n-1)

	{

		return 0;

	}

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

	ll ans1=inf,ans2=inf;

	if(i+2<n)ans1 = abs(h[i]-h[i+2])+solve(i+2);

	if(i+1<n)ans2 = abs(h[i+1]-h[i])+solve(i+1);

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

}

int main()

{

	boost

	cin>>n;

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

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

	cout<<solve(0)<<endl;

	return 0;

}

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

  Vivek Rathi

  CSE 2nd Year

  MNNIT

*/

#include<bits/stdc++.h>

using namespace std;

#define M 1000000007

#define ll long long int

#define pb push_back

#define pf push_front

#define pob pop_back

#define pof pop_front

#define debug1(x) cout<<#x<<" "<<x<<endl;

#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;

#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;

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

#define null NULL

#define mp make_pair

#define fi first

#define se second

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

#define inf 1e17

#include <ext/pb_ds/assoc_container.hpp> 

#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

int main()

{

	boost

	ll n;

	cin>>n;

	ll h[n];

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

	if(n<3)

	{

		if(n==1)

		{

			cout<<0<<endl;

		}

		else if(n==2)

		{

			cout<<abs(h[0]-h[1])<<endl;

		}

		return 0;

	}

	ll dp[n];

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

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

	for(ll i=n-4;i>=0;i--)

	{

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

	}

	cout<<dp[0]<<endl;

	return 0;

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

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

using namespace std;



int n;

vector<int>h(100000);

vector<int>cost(100000);



int Ans(int n){

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

    cost[n] = min((Ans(n-1) + abs(h[n-1] - h[n])),

                  (Ans(n-2) + abs(h[n-2] - h[n])));

    return cost[n];

}



int main(){

    cin>>n;

    rep(i,n){

        cin>>h[i];

        cost[i] = -1;

    }

    cost[0] = 0;

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

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

}

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

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

using namespace std;



int solve(int n, vector<int>h){

	vector<int>cost(n, 0);

    cost[0] = 0;

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

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

        cost[i] = min(

            (cost[i-1] + abs(h[i] - h[i-1])),

            (cost[i-2] + abs(h[i] - h[i-2])));

    }

    return cost[n-1];

}



int main(){

    int n; cin>>n;

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

    cout << solve(n,h);

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

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

using namespace std;



int n;

vector<int>h(100000);

vector<int>cost(100000);



int Ans(int n){

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

    cost[n] = min((Ans(n-1) + abs(h[n-1] - h[n])),

                  (Ans(n-2) + abs(h[n-2] - h[n])));

    return cost[n];

}



int main(){

    cin>>n;

    rep(i,n){

        cin>>h[i];

        cost[i] = -1;

    }

    cost[0] = 0;

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

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

}

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

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

using namespace std;



void solve(int m, vector<int>h){

  	vector<int>cost(m);

    cost[0] = 0;

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

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

        cost[i] = min(

            (cost[i-1] + abs(h[i]-h[i-1])),

            (cost[i-2] + abs(h[i]-h[i-2]))

        );

    }

    cout << cost[m-1];

}



int main(){

  	int n; cin>>n;

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

  	solve(n, h);

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

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

using namespace std;



int n;

vector<int>h(100000);

vector<int>cost(100000);



int Ans(int n){

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

    cost[n] = min((Ans(n-1) + abs(h[n-1] - h[n])),

                  (Ans(n-2) + abs(h[n-2] - h[n])));

    return cost[n];

}



int main(){

    cin>>n;

    rep(i,n){

        cin>>h[i];

        cost[i] = -1;

    }

    cost[0] = 0;

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

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

}

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

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

using namespace std;



void solve(int m, vector<int>h){

    vector<int>cost(m);

    cost[0] = 0;

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

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

        cost[i] = min(

            ( cost[i-1] + abs( h[i] - h[i-1] ) ),

            ( cost[i-2] + abs( h[i] - h[i-2 ]) )

        );

    }

    cout << cost[m-1];

}



int main(){

    int n; cin>>n;

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

    solve(n,h);

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

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

using namespace std;



int n;

vector<int>h(100000);

vector<int>cost(100000);



int Ans(int n){

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

    cost[n] = min((Ans(n-1) + abs(h[n-1] - h[n])),

                  (Ans(n-2) + abs(h[n-2] - h[n])));

    return cost[n];

}



int main(){

    cin>>n;

    rep(i,n){

        cin>>h[i];

        cost[i] = -1;

    }

    cost[0] = 0;

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

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

}

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

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

using namespace std;



void solve(int n, vector<int>h){

  vector<int>dp(n);

  dp[0] = 0;

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

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

    dp[i] = min(

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

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

    );

  }

  cout << dp[n-1];

}



int main(){

  int n; cin>>n;

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

  solve(n,h);

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

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

using namespace std;



int n;

vector<int>h(100000);

vector<int>cost(100000);



int Ans(int n){

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

    cost[n] = min((Ans(n-1) + abs(h[n-1] - h[n])),

                  (Ans(n-2) + abs(h[n-2] - h[n])));

    return cost[n];

}



int main(){

    cin>>n;

    rep(i,n){

        cin>>h[i];

        cost[i] = -1;

    }

    cost[0] = 0;

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

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

}

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

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

using namespace std;

using ll = long long;

const ll INF = 10e9;

const ll mod = 10e9+7;



int solve(int n, vector<int>h){

  vector<int>dp(n);

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

    );

  }

  return dp[n-1];

}



int main(){

  int n; cin>>n;

  vector<int>h(n);

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

  cout << solve(n,h) << endl;

  return 0;

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

#include <cstdlib>

using namespace std;



const long long INF = 1LL << 60;



int N;

long long h[100010];

long long dp[100010];



int main() {

  cin >> N;

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



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



  dp[0] = 0;



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

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

    if (i > 1) dp[i] = min(dp[i], dp[i - 2] + llabs(h[i] - h[i - 2]));

  }



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



  return 0;

}

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

#include <vector>

#include <cmath>

using namespace std;



int dp[100010];



int main() {

  int n;

  cin >> n;

  vector<int> h(n);

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

    cin >> h[i];

  }

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

    dp[i] = 1100000000;

  }

  dp[0] = 0;

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

  return 0;

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

#include <vector>

#include <cmath>

using namespace std;



long long dp[100010];



int main() {

  int n;

  cin >> n;

  vector<long long> h(n);

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

    cin >> h[i];

  }

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

    dp[i] = 1LL << 60;

  }

  dp[0] = 0;

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

  return 0;

}

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

#include <vector>

#include <cmath>

using namespace std;



int dp[100010];



int main() {

  int n;

  cin >> n;

  vector<int> h(n);

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

    cin >> h[i];

  }

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

    dp[i] = 1100000000;

  }

  dp[0] = 0;

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

  return 0;

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

#include <cstdlib>

using namespace std;



const long long INF = 1LL << 60;



int N;

long long h[100010];

long long dp[100010];



int main() {

  cin >> N;

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



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



  dp[0] = 0;



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

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

    if (i > 1) dp[i] = min(dp[i], dp[i - 2] + llabs(h[i] - h[i - 2]));

  }



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



  return 0;

}

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

#include <vector>

#include <cmath>

using namespace std;



int dp[100010];



int main() {

  int n;

  cin >> n;

  vector<int> h(n + 1, 0);

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

    cin >> h[i];

  }

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

    dp[i] = 1000000000;

  }

  dp[0] = 0;

  dp[1] = 0;

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

  return 0;

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

#include <vector>

#include <cmath>

using namespace std;



long long dp[100010];



int main() {

  int n;

  cin >> n;

  vector<long long> h(n);

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

    cin >> h[i];

  }

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

    dp[i] = 1LL << 60;

  }

  dp[0] = 0;

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

  return 0;

}

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

#include <vector>

#include <cmath>

using namespace std;



int dp[100010];



int main() {

  int n;

  cin >> n;

  vector<int> h(n + 1, 0);

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

    cin >> h[i];

  }

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

    dp[i] = 1000000000;

  }

  dp[0] = 0;

  dp[1] = 0;

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

  return 0;

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

using namespace std;

#define ll long long 



#define F first

#define S second



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

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

const double EPS= 1e-8 ;

const double PI  = acos(-1.0);

#define inf INT_MAX

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }



int n ; 

int a[100005] ; 

ll dp[100005]; 



ll solve ( int ind )

{

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

	

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

	

	ll & res = dp[ind]; 

	ll res1=1e10 , res2 =1e10 ; 

	if ( ind +1 <n ) 

	res1 = solve ( ind + 1)+ abs ( a[ind] - a[ind+1])  ; 

	if ( ind + 2 <n ) 

	res2 = solve ( ind+2 ) +abs ( a[ind] - a[ind+2]); 

	res = min ( res1 , res2 ); 

	return res ; 

	

}







int main()

 {

 

 cin>>n ; 

  

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

 {

	 cin>>a[i] ; 

	 

 }

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

 ll ans = solve ( 0 ) ; 

 

  

cout<< ans << endl; 





 return 0 ;

}













 

 

 

 

 

 



 


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

using namespace std;

#define ll long long 



#define F first

#define S second



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

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

const double EPS= 1e-8 ;

const double PI  = acos(-1.0);

#define inf INT_MAX

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }











int main()

 {

 int n ; 

 cin>>n ; 

 int a[n] ; 

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

 vector < int > dp ( n , inf) ; 

 dp[0]=0; 

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

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

  

 {

	 

	 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 <iostream>

#include <assert.h>

#include <stdlib.h>

#include <time.h>

#include <stdio.h>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <string>

#include <string.h>

#include <cmath>

#include <algorithm>

#include <iomanip>

using namespace std;



const int N = 1e5 + 2;



int n, h[N];

long long dp[N];



long long calc(int i)

{

    if (i == n - 1)

    {

        return 0;

    }

    long long &ret = dp[i];

    if (ret != -1)

    {

        return ret;

    }

    ret = 1e9;

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

    if (i + 2 < n)

    {

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

    }

    return ret;

}



int main()

{

    memset(dp, -1, sizeof dp);

    cin >> n;

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

    {

        cin >> h[i];

    }

    cout << calc(0) << endl;

    return 0;

}

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

#include <assert.h>

#include <stdlib.h>

#include <time.h>

#include <stdio.h>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <string>

#include <string.h>

#include <cmath>

#include <algorithm>

#include <iomanip>

#define ll long long

using namespace std;



const int N = 1e5 + 7;

const long long oo = 1e18L + 5;



int n;



int main() {

    cin >> n;

    vector<int> h(n + 1);

    vector<ll> dp(n + 2, oo);

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

        cin >> h[i];

    }

    dp[0] = 0;

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

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

        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 <iostream>

#include <assert.h>

#include <stdlib.h>

#include <time.h>

#include <stdio.h>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <string>

#include <string.h>

#include <cmath>

#include <algorithm>

#include <iomanip>

#define ll long long

using namespace std;



const int N = 1e5 + 7;

const long long oo = 1e18L + 5;



int n, h[N];

ll dp[N];



ll go(int i) {

    if (i == n) {

        return 0;

    }

    if (i > n) {

        return oo;

    }

    ll &ret = dp[i];

    if (ret != -1) {

        return ret;

    }

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

    return ret;

}



int main() {

    memset(dp, -1, sizeof dp);

    cin >> n;

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

        cin >> h[i];

    }

    cout << go(1) << endl;

    return 0;

}

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

#include <assert.h>

#include <stdlib.h>

#include <time.h>

#include <stdio.h>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <string>

#include <string.h>

#include <cmath>

#include <algorithm>

#include <iomanip>

#define ll long long

using namespace std;



const int N = 1e5 + 7;

const long long oo = 1e18L + 5;



int n;



int main() {

    cin >> n;

    vector<int> h(n + 1);

    vector<ll> dp(n + 2, oo);

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

        cin >> h[i];

    }

    dp[0] = 0;

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

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

        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 <iostream>

#include <cmath>

using namespace std;



const long long  INF = 1LL << 60;



int N;

int H[100010];



int main() {

    cin >> N;

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



    long long dp[100010];

    for (int i = 0; i < 100010; ++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 >= 2) dp[i] = min(dp[i], 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.2895998638064698x):
#include <iostream>

#include <cmath>

using namespace std;



const int INF = 1 << 29;



int N;

int H[100010];



int main() {

    cin >> N;

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



    int dp[100010];

    for (int i = 0; i < 100010; ++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 >= 2) dp[i] = min(dp[i], 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<(int)(n); i++)

using namespace std;

using ll = long long;

using Graph = vector<vector<int>>;



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



int main() {

  int n; cin >>n;

  vector<ll> h(n);

  rep (i,n) cin >>h.at(i);

  const ll INF = 1LL << 60;

  vector<ll> dp(100010);

  rep (i,100010) dp.at(i) = INF;

  dp.at(0) = 0;

  for (int i=0; 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-1] <<endl;



}


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

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

using namespace std;

using ll = long long;

using Graph = vector<vector<int>>;

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



void chmin(int &a, int &b){if (a>b){a = b; return;}return;}

void chmax(int &a, int &b){if (a<b){a = b; return;}return;}





const ll MOD = 1000000007;

const ll INF = 9999999999;



int main() {

  int n; cin >>n;

  vector<int> h(n);

  for (int i=0; i<n; i++) cin >>h.at(i);

  vector<int> dp(n+2, 1500000000);

  dp.at(0) = 0;

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

    chmin(dp.at(i+1), dp.at(i) + abs(h.at(i) - h.at(i+1)));

    if (i==n-2) break;

    chmin(dp.at(i+2), dp.at(i) + abs(h.at(i) - h.at(i+2)));

  }

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

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

using namespace std;

const int mxn=1e5;

int  dp[mxn+2];

int h[mxn+2];

int func(int n)

{

    int k;

    if(n==1)return dp[1]=0;

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

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

if(n>2){

k=func(n-2)+abs(h[n]-h[n-2]);

dp[n]=min(k,dp[n]);}

return dp[n];





}





int main()

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

    int n;

    cin>>n;



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

    cout<<func(n)<<endl;





}

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

using namespace std;

const int inf=1e9;

int main()

{

    int n;

    scanf("%d",&n);

    vector<int> h(n);

    for(int& i:h)

       {



        scanf("%d",&i);}

        vector<int> dp(n,inf);

        dp[0]=0;

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





        {



                for(int j :{i+1,i+2})

        {if(j<n)

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



        }



        }



        }

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





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



using namespace std;



int n,arr[100005],mem[100005];



int dp(int pos){

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

    if(pos>=n)return 100000;

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

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

}



int main(){

    ios_base::sync_with_stdio(0);

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

    cin>>n;

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

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

    cout<<dp(0);

}

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



using namespace std;



int n,arr[100005],dp[100005];



int main(){

    ios_base::sync_with_stdio(0);

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

    cin>>n;

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

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

    for(int i=2;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-1];

}