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

using namespace std;



int a[1000001];

int dp[1000001];

int it;



int fr(int p){

	if (p==it-1){

      return 0;

    }

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

      return dp[p];

    }

	int re=abs(a[p]-a[p+1])+fr(p+1);

	if(p!=it-2){

      re=min(re,abs(a[p]-a[p+2])+fr(p+2));

    }

	return dp[p]=re;

}

int main(){

	cin>>it;

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

    cin>>a[i];

    }



	memset(dp,-1,sizeof dp);

	cout<<fr(0)<<endl;

	return 0;

}


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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

}
// Slower C++ solution:


#include <iostream>

#include <bits/stdc++.h>





using namespace std;





int a[100005], p[100005],n, i;

int respuesta(int x)

{

    if(x==n) return 0;

    if(x>n) return 1e9;

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

    return p[x]=min(abs(a[x+1]-a[x])+respuesta(x+1), abs(a[x+2]-a[x])+respuesta(x+2));

}





int main()

{

    memset(p,-1,sizeof p);

    cin>>n;

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

    {

        cin>>a[i];

    }

    cout<<respuesta(1)<<endl;

    return 0;

}


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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

const int mod = 1e9+9;

//===========================================================//

const int nax = 1e5+3;

int n;

int dp[nax];

int a[nax];

int f(int i){

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

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

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

	if(i!=n-2) ans = min(ans, abs(a[i]-a[i+2])+f(i+2));

	return dp[i]=ans;

}

int main(){

	cin>>n;

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

	memset(dp, -1, sizeof dp);

	cout<<f(0)<<endl;

	return 0;

}

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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

const int mod = 1e9+9;

/*ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }

*ll lcm(ll x, ll y){return x*(y/gcd(x,y));}

*void exEuclid(int a, int b){

	if(b==0){x = 1; y=0; d=a; return ;}

	exEuclid(b, a%b);

	int x1=y;

	int y1=x-(a/b)*y;

	x=x1;

	y=y1;

} 

* */

//===========================================================//

const int nax = 1e5+3;

int n;

int dp[nax];

int a[nax];

int f(int i){

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

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

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

	if(i!=n-2) ans = min(ans, abs(a[i]-a[i+2])+f(i+2));

	return dp[i]=ans;

}

int main(){

	cin>>n;

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

	memset(dp, -1, sizeof dp);

	cout<<f(0)<<endl;

	return 0;

}

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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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

using namespace std;

typedef long long ll;

ll dp[100009];

int arr[100009];

ll sum = 0;

long long Frog1(int n){

 

    if(n==0) return 0;

    else if(n==1) return abs(arr[n] - arr[n-1]);

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

    else {

            ll x = Frog1(n-1);

            ll y = Frog1(n-2);

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

        //cout << n << " = " << dp[n] << endl;

         return dp[n];

    }

}

 

 

int main()

{

    int n;

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

    cin >> n;

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

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

}

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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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

using namespace std;

#define ll long long

#define ld long double

#define sf scanf

#define pf printf

#define pb push_back

#define llu unsigned long long

#define U unsigned int

#define SIZE 1000002

#define pie 3.14159265358979323

#define minuss 1e-6

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

 

#define BIG 100000000

 

ll  lcm(ll a,ll b)

{

    ll GCD=__gcd(a,b);

    ll lcm=(a*b)/GCD;

    return lcm;

}

ll dp[100005];

ll weight[1000005],value[1000005];

ll total,val;

ll call(ll n)

{

    if(n>=total)

        return 0;

 

    if(dp[n]!=-1)

        return dp[n];

 

    ll res1=BIG,res2=BIG;

 

   // if(weight[n]+c<=val)

    res1=abs(weight[n]-weight[n+1]) + call(n+1);

    if(n+2<=total) res2=abs(weight[n]-weight[n+2]) + call(n+2);

    //cout<<n<<" "<<res1<<" "<<res2<<endl;

    dp[n]=min(res1,res2);

    return dp[n];

 

}

int main()

{

    cin>>total;

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

        cin>>weight[i];

 

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

    ll ret=call(1);

    cout<<ret<<endl;

    return 0;

}

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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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

using namespace std;



int num[100001], memo[100001];



int dp(int n){

    if(n==0) return 0;

    if(n==1) return abs(num[0]-num[1]);

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

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

}



int main(){

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

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

    ios_base::sync_with_stdio(0);

    cin.tie(0);

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

    int n;

    cin>>n;

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

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

    return 0;

}


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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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



using namespace std;

int v[100010];

int memo[100010];

int c;



int f(int i)

{



    if(memo[i]!=-1)

        return memo[i];



    if(i == 0)

        return memo[0] = 0;



    if(i == 1)

        return memo[1] = abs(v[0] - v[1]);



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

}



int main()

{



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

    cin>>c;



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

    {

        cin>>v[i];

    }



    cout<<f(c-1)<<endl;



    return 0;

}

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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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



using namespace std;



const int N = 1e5 + 9;



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



int solve(int i){

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

    if(i == n)   return 1e9;



    int &ret = dp[i];

    if(~ret)    return ret;



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

}



int main(){



    cin >> n;

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

        cin >> h[i];



    memset(dp, -1, sizeof dp);



    cout << solve(0);

}


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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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

using namespace std;

int n;

long long h[100005];

long long dp[100005];



long long solve(int i){

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

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



	dp[i] = 1e17;

	if(i+1 <= n-1)

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

	if(i+2 <= n-1)

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



	return dp[i];

}



int main(){

	scanf("%d", &n);

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

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

	memset(dp, -1, sizeof dp);

	cout<<solve(0)<<endl;

	return 0;

}

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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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

using namespace std;

#define ll long long

#define pb push_back

#define mp make_pair

#define ull  unsigned long long

#define vll  vector <long long>

#define pll pair <long long,long long>

#define f first

#define s second

#define up upper_bound

#define lp lower_bound

#define pq priority_queue

#define inf 1e10

#define minf -1e10

#define pi 3.14159265

#define mod 300000000000000000

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

int main()

{

    ll n;

    cin>>n;

    vll vec;

    ll ara[100001];

    memset(ara,0,sizeof(ara));

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

    {

        ll num;

        cin>>num;

        vec.pb(num);

    }

    ll ans=0;

    ara[n-2]=abs(vec[n-2]-vec[n-1]);

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

    {

        ara[i]=min(abs(vec[i]-vec[i+1])+ara[i+1],abs(vec[i]-vec[i+2])+ara[i+2]);

    }

    cout<<ara[0]<<endl;

}


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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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

using namespace std;

#define ll long long



int ara[100000];

int dp[100000];



int f(int i, int n)

{

    if(i == n) return 0;

    if(dp[i] != -1)

        return dp[i];

    int cost = f(i+1,n) + abs(ara[i] - ara[i+1]);

    if(i+2<=n)

        cost = min(cost, f(i+2,n)+abs(ara[i] - ara[i+2]));

    dp[i] = cost;



    return cost;

}



int main()

{

   int n;

   cin>>n;



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

   {

       cin>>ara[i];

   }



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

   cout<<f(1,n)<<endl;



   return 0;

}






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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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



#define TR 100000



int l[TR];

using namespace std;

vector<int> h;





int solve(int p) {

	if(p == 0)

		return 0;

	if(p < 0)

		return 10000000;

	if(l[p] != -1)

		return l[p];

	l[p] = min(abs(h[p] - h[p - 1]) + solve(p - 1), abs(h[p] - h[p - 2]) + solve(p - 2));

	return l[p];



}



int main() {

	int n;

	cin >> n;

	memset(l, -1, TR * sizeof(int));

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

		cin >> tmp;

		h.push_back(tmp);

	}

	solve(n - 1);

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

}

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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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



using namespace std;

#define tam 100001

int dp[tam],A[tam],n,pr=0;

int solver(int index)

{

    if(dp[index] != -1)

        return dp[index];

    if(index <= 1)

        return dp[index] = abs(A[0]-A[index]);

    return dp[index] = min(solver(index-1) + abs(A[index]-A[index-1]),

    solver(index-2) + abs(A[index]-A[index-2]));

}

int main()

{

    cin>>n;

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

        cin>>A[i];

    memset(dp,-1,sizeof dp);

    dp[0] = 0; 

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

    return 0;

}


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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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

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

#define ii          pair<int,int>

#define F           first

#define S           second

#define pb          push_back

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

#define rall(x)     (x).rbegin(),(x).rend()

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

#define forr(i,a)   for(int i = a; i >= 0; i--)

#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 

#define w(t)        while(t--)

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

#define cls(a,car)  memset(a,car,sizeof (a))

#define db(x)       cerr << #x << " is " << x << '\n'

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

#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

#define angle(x)    double(x * acos(-1) / 180.0)

using namespace std;

typedef long long   ll;

typedef vector<int> vi;

typedef vector<ii>  vii;

const int N = 1 * 1e5 + 5;

const ll mod = 1e9 + 7;

const double E = 1e-9;

//int dx[] = {1, 0}, dy[] = {0, 1};

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

//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};

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

// fflush(stdout)

// cout << flush

// a + b = a ^ b + 2 * (a & b)

int v[N];

int dp[N];

int n, k = 2;

int f(int i){

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

    int &ans = dp[i];

    if(ans == -1){

        ans = 1e9;

        for(int j = 1; j <= k; j++)

            if(i + j < n)

                ans = min(ans, f(i + j) + abs(v[i] - v[i + j]));

            else

                break;

    }

    return ans;

}

int main(){

    //FL;

    FIN;

    cin >> n;

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

    cls(dp, -1);

    cout << f(0) << '\n';

    

    EjecuteTime;

    return 0;

}       

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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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

#define INF 0x3f3f3f3f

using namespace std;

const int maxn = 1e6+10;

int a[maxn];

int dp[maxn];

int main()

{

    int n;

    memset(dp,INF,sizeof dp);

    scanf("%d",&n);

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

    {

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

    }

    dp[1]=0;

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

    {

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

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

    }

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

    return 0;

}


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

using namespace std;



#define ll long long int



int piedras[100005];

ll memo[100005];

char visitado[100005];

int N;



ll costo(int n){

	if(!n) return 0;

	if(n == 1) return memo[1] = abs(piedras[0]-piedras[1]);

	if(visitado[n]) return memo[n];

	visitado[n] = 1;

	return memo[n] = min(costo(n-1)+abs(piedras[n]-piedras[n-1]),

						 costo(n-2)+abs(piedras[n]-piedras[n-2]));

}





int main() {

	cin>>N;

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

		cin>>piedras[i];

	cout<<costo(N-1)<<"\n";

	return 0;

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

using namespace std;

#define N (int)2e5

int n,memo[N],c[N];



int dp(int curr) {

    if (curr == n) return 0;

    if (curr > n) return 1e9;

    int &sol = memo[curr];

    if (sol != -1) return sol;

    sol = min(

        dp(curr + 1) + abs(c[curr] - c[curr + 1]) ,

        dp(curr + 2) + abs(c[curr] - c[curr + 2])

    );

    return sol;

}



int main() {

    scanf("%d" , &n);

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

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

    memset (memo , -1 , sizeof memo);

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

}


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

using namespace std;



const int mx=1e5+1;

int n,k;

int h[mx],dp[mx];

int solve(int s) //s->no of stone

{

    if(s==n) return 0;

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

    int ret=INT_MAX;

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

        if((i+s)<=n) ret=min(ret,abs(h[s+i]-h[s])+solve(s+i));

    }

    return dp[s]=ret;

}

int main()

{

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

    //freopen("input.txt","r",stdin);    return 0;



    cin>>n;

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

    memset(dp,-1,sizeof dp);

    cout<<solve(1);



    return 0;

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

using namespace std;

#define ll long long int

#define dbl double

#define pi acos(-1)

#define sc1(a) scanf("%lld",&a)

#define sc2(a,b) scanf("%lld%lld",&a,&b)

#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)

#define pb push_back



ll ara[1000005];



map<ll,ll>vis;

map<ll,ll>vis1;

map<ll,ll>pos;

map<ll,ll>high;

map<ll,ll>low;

map<string,ll>mp;

vector<ll>vec;

vector<ll>v;

stack<ll>q;

string str1[100];

string str2[100];

priority_queue<ll>pq;

ll dp[1000005],t;

ll mn=1000000;

ll call(ll id)

{

    if(id==t )return 0;

    if(dp[id]!=-1)

        return dp[id];

    ll p=call(id+1)+abs(ara[id+1]-ara[id]);

    ll q=100000000;

    if(id+2!=t+1)

        q=call(id+2)+abs(ara[id+2]-ara[id]);

    dp[id]=min(p,q);

    return dp[id];



}

int main()

{



    // ll t;

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

    sc1(t);

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

    {

        sc1(ara[i]);

    }

    cout<<call(1)<<endl;

    return 0;

}


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

using namespace std;



const int mx=1e5+1;

int n,k;

int h[mx],dp[mx];

int solve(int s) //s->no of stone

{

    if(s==n) return 0;

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

    int ret=INT_MAX;

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

        if((i+s)<=n) ret=min(ret,abs(h[s+i]-h[s])+solve(s+i));

    }

    return dp[s]=ret;

}

int main()

{

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

    //freopen("input.txt","r",stdin);    return 0;



    cin>>n;

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

    memset(dp,-1,sizeof dp);

    cout<<solve(1);



    return 0;

}