stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

#define INF 1000000000;

using namespace std;

int n,h[100005],mem[100005],i;

int dp(int i){

  if(i==1){

    return 0;

  }

  if(i<1){

    return INF;

  }

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

    return mem[i];

  }

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

  int a2=dp(i-2)+abs(h[i-2]-h[i]);

  return mem[i]=min(a1,a2);

}

signed main(){

  cin>>n;

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

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

    cin>>h[i];

  }

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

  return(0);

}


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

using namespace std;

int main(){

  int n;

  cin>>n;

  vector<int> h(n+5);

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

    cin>>h[i+1];

  }

  vector<int> dp(n+5,100000);

  dp[1]=0;

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

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

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

  }

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

  return(0);

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

#define INF 1000000000;

using namespace std;

int n,h[100005],mem[100005],i;

int dp(int i){

  if(i==1){

    return 0;

  }

  if(i<1){

    return INF;

  }

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

    return mem[i];

  }

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

  int a2=dp(i-2)+abs(h[i-2]-h[i]);

  return mem[i]=min(a1,a2);

}

signed main(){

  cin>>n;

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

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

    cin>>h[i];

  }

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

  return(0);

}


// Faster C++ solution for the same problem (measured speedup: 1.3695719478838044x):
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>

using namespace std;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

typedef long long ll;

typedef vector<int> vint;

typedef pair<int, int> pint;

typedef vector<long long> vlong;

typedef vector<string> vstring;

#define vpush(a,x) a.push_back(x);

#define rep(i, n) REP(i, 0, n)

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

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

const int INF = 1 << 30;

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

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

#define stp(x)  setprecision(x)

const long double PI=3.14159265358979323846264338327950;

int main(){

  cin.tie(nullptr);

  ios::sync_with_stdio(false);

  int n;

  cin>>n;

  vint h(n);

  rep(i,n){

    cin>>h[i];

  }

  vint dp(n+5);

  dp[0]=0;

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

  REP(i,2,n){

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

  }

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

  return(0);

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

using namespace std;



const int MAX=100005;

vector<int> S(MAX),h(MAX);

int N;



void DP(int u){

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

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

    else if(i==3) S[3]=abs(h[3]-h[1]);

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

    }

    cout<<S[u]<<endl;

}



int main(){

    

    cin>>N;

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

        cin>>h[i+1];

    }

    DP(N);

    

}


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

using namespace std;



typedef long long ll;

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

const int mod=1000000007;



int main(){

    

    int N;cin>>N;

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

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

        cin>>S[i];

    }

    dp[0]=0;

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

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

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

    }

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

}
// Slower C++ solution:


// Problem : A - Frog 1

// Contest : AtCoder - Educational DP Contest

// URL : https://atcoder.jp/contests/dp/tasks/dp_a

// Memory Limit : 1024 MB

// Time Limit : 2000 ms

// Powered by CP Editor (https://github.com/cpeditor/cpeditor)



#pragma GCC optimize("O3")  

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define F first

#define pii pair<int,int>

#define S second

#define endl "\n"

#define gcd(a,b) __gcd(a,b)

#define lcm(a,b) (a*b)/gcd(a,b)

#define mem(z,i) memset(z,i,sizeof(z))

#define eps 1e-7

#define I (int)

#define mod 1000000007

#define pb push_back

const long long INF = 1000000000000000000LL;

//const int WASTE=∞

const int N=1e5+5;

int a[N],dp[N];

int f(int x){

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

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

	return dp[x];

}

signed main() {

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

  	// cout<<fixed;

  	// cout.precision(10);

   	int n;

   	cin>>n;

   	mem(dp,-1);

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

   	for(int x=1;x<=n;x++) cin>>a[x];

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

   	int ans=f(n);

   	cout<<ans<<endl;

   	//for(int x=1;x<=n;x++) cout<<dp[x]<<' ';

   	

   	

   	

   	

   	

   	

   	

   	

   	

   	

   	

  	return 0;

}




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


// Problem : A - Frog 1

// Contest : AtCoder - Educational DP Contest

// URL : https://atcoder.jp/contests/dp/tasks/dp_a

// Memory Limit : 1024 MB

// Time Limit : 2000 ms

// Powered by CP Editor (https://github.com/cpeditor/cpeditor)



#pragma GCC optimize("O3")  

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define F first

#define pii pair<int,int>

#define S second

#define endl "\n"

#define gcd(a,b) __gcd(a,b)

#define lcm(a,b) (a*b)/gcd(a,b)

#define mem(z,i) memset(z,i,sizeof(z))

#define eps 1e-7

#define I (int)

#define mod 1000000007

#define pb push_back

const long long INF = 1000000000000000000LL;

//const int WASTE=∞

const int N=1e5+5;

signed main() {

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

  	// cout<<fixed;

  	// cout.precision(10);

   	int n;

   	cin>>n;

   	int a[n];

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

   	int dp[n];

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

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

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

   	}

   	cout<<dp[n-1];

   	

   	

   	

   	

   	

   	

   	

   	

   	

   	

  	return 0;

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

using namespace std;



using ll=long long;



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 ll INF = 1LL << 60;



int N;

ll h[100010];

ll 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=0;i<N;i++){

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

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

  }

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

  

}

// Faster C++ solution for the same problem (measured speedup: 1.279081164686403x):
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

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

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

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

typedef long long ll;

typedef pair<ll,ll> l_l;

typedef pair<int,int> i_i;

const ll MOD=1e9+7;

const int INF=1<<30;



int dp[100100];



int main(){

  int N; cin >> N;

  vector<int> h(N);

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

  rep(i,100100){

    dp[i]=INF;

  }

  dp[0]=0;

  rep(i,N){

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

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

  }

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

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

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



using ll=long long;

const int Nmax=100010;

int N; 

ll dp[Nmax];

int h[Nmax];

const ll INF=1LL<<60;





int main(){

  cin >> N;

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

    cin >> h[i];

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

    dp[i]=INF;

  dp[0]=0;

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

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

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

  }

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

  

}

// Faster C++ solution for the same problem (measured speedup: 1.277067894200459x):
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

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

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

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

typedef long long ll;

typedef pair<ll,ll> l_l;

typedef pair<int,int> i_i;

const ll MOD=1e9+7;

const int INF=1<<30;



int dp[100100];



int main(){

  int N; cin >> N;

  vector<int> h(N);

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

  rep(i,100100){

    dp[i]=INF;

  }

  dp[0]=0;

  rep(i,N){

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

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

  }

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

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

using namespace std;

typedef unsigned long long int ull;

typedef long long int ll;

typedef long double ld;

#define mod 1000000007

#define pub(a) push_back(a)

#define mp(a,b) make_pair(a,b)



const ll N = 100004;

vector<ll>dp(N,-1);



ll call(ll h[],ll n){

    if(n==1){

        dp[1]= 0;

        return dp[1];

    }else if(n==2){

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

        return dp[2];

    }else{

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

            return dp[n];

        }

    }

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



}





int main(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    ll n;

    cin>>n;

    ll h[n+1];

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

        cin>>h[i];

    }

    cout<<call(h,n);

    



    return 0;

}


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

using namespace std;

typedef unsigned long long int ull;

typedef long long int ll;

typedef long double ld;

#define mod 1000000007

#define pub(a) push_back(a)

#define mp(a,b) make_pair(a,b)

#define getl(s) getline(cin,s);







int main(){

  ios::sync_with_stdio(0);

  cin.tie(0);

  ll n;

  cin>>n;

  ll dp[n+1];

  ll h[n+1];

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

    cin>>h[i];

  }

  dp[1]=dp[0] =0;

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

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



  return 0;

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



using namespace std;

int n , a[100000],dp[100000];

int f(int i = 0)

{

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

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

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

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

}

int main()

{

    memset(dp,-1,sizeof dp);

    cin >> n;

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

        cin >> a[i];

    cout << f();

    return 0;

}

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

using namespace std;

#define ll long long

int main()

{

    int n, a[100000], dp[100000];

    scanf("%d", &n);

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

        scanf("%d", a+i);

    dp[n-1] = 0;

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

    for(int i=n-3; 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[0];

    return 0;

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

using namespace std;

#define ll long long

int n, a[100000], dp[100000];

int f(int i)

{

    if( i == n-1 )

        return 0;

    if( dp[i] != -1 )

        return dp[i];

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

    if( i < n-2 )

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

    return dp[i];

}

int main()

{

    scanf("%d", &n);

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

        scanf("%d", a+i);

    memset(dp, -1, sizeof dp);

    cout << f(0);

    return 0;

}

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

using namespace std;

#define ll long long

int main()

{

    int n, a[100000], dp[100000];

    scanf("%d", &n);

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

        scanf("%d", a+i);

    dp[n-1] = 0;

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

    for(int i=n-3; 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[0];

    return 0;

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

using namespace std;

const long long INF = 1LL << 60;



int main() {

  int n;

  vector<int> h(100010);

  vector<long long> dp(100010);

  cin >> n;

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

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

  dp[0] = 0;



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

}

// Faster C++ solution for the same problem (measured speedup: 2.1789867135998033x):
#pragma gcc optimize("Ofast")

#include <bits/stdc++.h>



using namespace std;

using ll = long long;



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

#define REP(i, n) FOR(i, 0, n)

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

#define SORT(V) sort(ALL(V)) //小さい方からソート

#define REV(V) reverse(ALL(V)) //リバース

#define RSORT(V) SORT(V);REV(V) //大きい方からソート

#define NPN(V) next_permutation(ALL(V)) //順列

#define pb(n) push_back(n)

#define endl '\n'

#define Endl '\n'

#define DUMP(x)  cout << #x << " = " << (x) << endl

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl

#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl

#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl

#define RAPID cin.tie(0);ios::sync_with_stdio(false)

#define VSUM(V) accumulate(ALL(V), 0)

#define MID(a,b,c) (a) < (b) && (b) < (c)

#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)

#define IN(n) cin >> n

#define IN2(a,b) cin >> a >> b

#define IN3(a,b,c) cin >> a >> b >> c 

#define IN4(a,b,c,d) cin >> a >> b >> c >> d

#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}

#define OUT(n) cout << n << endl

#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}

#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;



// 型マクロ定義

#define int long long

#define P pair<ll,ll>

#define Vi vector<ll>

#define VVi vector<vector<ll>>

#define Vd vector<double>

#define Vb vector<bool>

#define Vs vector<string>

#define Vc vector<char>

#define M map<ll,ll>

#define S set<ll>

#define PQ priority_queue<ll>

#define PQG priority_queue<ll,V,greater<ll>

//



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 int MOD = 1000000007;

const int INF = 1061109567;

const double EPS = 1e-10;

const double PI  = acos(-1.0);



int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数

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

string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}

string gCh(string str, int key){return str.substr(key,1);}



signed main() {

  RAPID;

  // デフォルト変数定義

  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;

  string s="",t="";

  //



  // ここから

  IN(n);

  Vi h(n);

  VIN(h)

  int dp[n+10];

  REP(i,n+10) dp[i] = INF;

  dp[0] = 0;

  FOR(i,1,n){

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

  }

  OUT(dp[n-1]);

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

using namespace std;

typedef long long       ll;

typedef pair<int,int>   ii;

typedef vector<int>     vi;

typedef vector<ii>      vii;

typedef set<int>        si;

typedef set<ii>         sii;



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

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

#define clr(x,v) memset(x,v,sizeof x)

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

#define re return



template<typename T> T sgn (T x)      {re x<0? -1:(x>0? 1:0); }

template<typename T> T gcd (T a, T b) {re a ? gcd (b % a, a) : b; }

template<typename T> T abs (T x)      {re x < 0 ? -x : x; }

template<typename T> T sqr (T x)      {re x*x;}



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

#define popcount __builtin_popcount

#define mp make_pair

#define pb push_back

#define ins insert

#define sc second

#define fr first

#define endl "\n"

#define MOD ((int)1e9+7)

#define N ((int)2e5+123)



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

int f(int i){

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

    if(i>=n)return MOD;

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

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



}

void solve(){

    cin >> n;

    clr(dp,-1);

    forn(i,0,n)cin >> v[i];

    cout << f(0) << endl;

}

int main(){_

    solve();

     /*

    int t; cin >> t;

    while(t--){

        solve();

    }

   */

}


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

using namespace std;

typedef long long       ll;

typedef pair<int,int>   ii;

typedef vector<int>     vi;

typedef vector<ii>      vii;

typedef set<int>        si;

typedef set<ii>         sii;



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

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

#define clr(x,v) memset(x,v,sizeof x)

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

#define re return



template<typename T> T sgn (T x)      {re x<0? -1:(x>0? 1:0); }

template<typename T> T gcd (T a, T b) {re a ? gcd (b % a, a) : b; }

template<typename T> T abs (T x)      {re x < 0 ? -x : x; }

template<typename T> T sqr (T x)      {re x*x;}



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

#define popcount __builtin_popcount

#define mp make_pair

#define pb push_back

#define ins insert

#define sc second

#define fr first

#define endl "\n"

#define MOD ((int)1e9+7)

#define N ((int)2e5+123)



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



void solve(){

    cin >> n;

    forn(i,0,n)cin >> v[i];

    dp[n-1]=0;dp[n]=MOD;

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

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

    }

    cout << dp[0] << endl;

}

int main(){_

    solve();

    /*

    int t; cin >> t;

    while(t--){

        solve();

    }

    */

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

using namespace std;

typedef long long ll; 



const int mxN = 1e5 + 10;

int dp[mxN];



int rec(vector<int>& v, int i, int n) {

	if(i == (n-1)) {

		return dp[n-1] = 0;

	}

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

	int ans = INT_MAX;

	if(i + 1 <= n-1)

		ans = min(ans, abs(v[i] - v[i+1]) + rec(v, i+1, n));

	if(i + 2 <= n-1)

		ans = min(ans, abs(v[i] - v[i+2]) + rec(v, i+2, n));

		

	return dp[i] = ans;

}



int main() {

	int n;

	cin >> n;

	vector<int> v(n);

	

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

		cin >> v[i];

	}

	

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

	cout << rec(v, 0, n) << "\n";

}


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

using namespace std;

typedef long long ll; 



int main() {

	int n;

	cin >> n;

	vector<int> v(n);

	

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

		cin >> v[i];

	}

	

	vector<int> dp(n, INT_MAX);

	dp[0] = 0;

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

	

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

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

	}

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

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

#define F first

#define S second

#define pb push_back

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

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

#define fill(x,v) memset(x, v, sizeof(x))

#define PI (ld)acos(-1)

#define endl '\n'

#define dbg(x) cout<<#x<<"="<<(x)<<endl;

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

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

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

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

typedef pair<int,int> pi;

typedef pair<ll,ll> pl;

const ld eps=(ld)1e-9;

const ll inf=(ll)1e18;

const ll mod=(ll)1e9+7;

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

int f(int i){

	if(i==n-1){

		return 0;

	}

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

		return dp[i];

	}

	int ans=INT_MAX;

	if(i+2<n){

		ans=abs(h[i+2]-h[i])+f(i+2);

	}

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

}





void solve(){

	cin>>n;

	fill(dp,-1);

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

	{

		cin>>h[i];

	}

	cout<<f(0);

}



int main(){fio;

int test=1;

// cin>>test;

while(test--){

	solve();

	cout<<endl;

}

return 0;

}

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

#define F first

#define S second

#define pb push_back

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

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

#define fill(x,v) memset(x, v, sizeof(x))

#define PI (ld)acos(-1)

#define endl '\n'

#define dbg(x) cout<<#x<<"="<<(x)<<endl;

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

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

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

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

typedef pair<int,int> pi;

typedef pair<ll,ll> pl;

const ld eps=(ld)1e-9;

const ll inf=(ll)1e9;

const ll mod=(ll)1e9+7;





void solve(){

	int n;

	cin>>n;

	int h[n];

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

	{

		cin>>h[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[j]-h[i]));

			}

		}

	}

	cout<<dp[n-1];

}



int main(){fio;

int test=1;

// cin>>test;

while(test--){

	solve();

	cout<<endl;

}

return 0;

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

using namespace std;

using namespace std::chrono;

int arr[100005];

int n;

int dp[100005];

long long go(int i){

    if(i == n-1)

        return 0;

  	if(i >= n)

      return 1000000;

  int &ans = dp[i];

  if(ans!=-1)

    return ans;



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

  return ans;

}



int main(){

    //auto start = high_resolution_clock::now();

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

        dp[i] = -1;

    }

	cin >> n;

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



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







  	//auto stop = high_resolution_clock::now();



  	//auto duration = duration_cast<milliseconds>(stop - start);

  	//cout<<duration.count();

}


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

using namespace std;

using namespace std::chrono;

int arr[100005];

int n;

long long dp[100005];



int main(){

    //auto start = high_resolution_clock::now();

	cin >> n;

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

  	dp[0] = 100000;

  	dp[1] = 0;

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

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

    }

    cout<<dp[n];

}