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

using namespace std;

int n;

int dp[100005],num[100005];

int main() {

	cin.tie(),cout.tie();

	memset(dp,23333,sizeof(dp));

	cin>>n;

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

	dp[0]=0;

	dp[1]=0;

	dp[2]=fabs(num[2]-num[1]);

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

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

			int add=fabs(num[i]-num[j]);

			dp[i]=min(dp[i],dp[j]+add);

		}

//		cout<<i<<':'<<dp[i]<<endl;

	}

	cout<<dp[n]<<endl;

	return 0;

} 

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

using namespace std;

int n,num[200005],dp[200005];

int main() {

	cin>>n;

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

	dp[1]=0;

	dp[2]=dp[1]+fabs(num[1]-num[2]);

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

		dp[i]=min(dp[i-1]+fabs(num[i-1]-num[i]),

		dp[i-2]+fabs(num[i-2]-num[i]));

	cout<<dp[n]<<endl;

	return 0;

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



using namespace std;



typedef long long int ll;

ll n,cost=0;

vector<ll> height(100005, INT_MAX);

ll memo[100005];

ll dp(int pos)

{

	if(pos>n-1)

		return INT_MAX;

	if(pos==n-1)

		return 0;

	if(memo[pos]!=-1)

		return memo[pos];

	ll ans = INT_MAX;

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

		ans = min(ans, dp(pos+i)+abs(height[pos]-height[pos+i]));

	return memo[pos] = ans;

}

int main()

{

	cin>>n;

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

		cin>>height[i];

	memset(memo, -1, sizeof memo);

	cout<<dp(0)<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.606957491030084x):
/*"You can do anything you set your mind to,man" - Eminem*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define llpow(a,b) (ll)(pow(a,b)+0.5)

#define l_b(a,val) min((int)a.size()-1, (int)(lower_bound(a.begin(),a.end(),val)-a.begin()))

#define f first

#define s second

#define INF 9223372036854775807

const  int mod = 1000000007;

void add(ll& a, ll b){a+=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}

void mul(ll& a, ll b){a*=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}

ll binexpomodulo(ll x, ll y){ll res =1;x%=mod;if(!x)return 0;while(y){if(y&1){mul(res, x);}mul(x,x);y>>=1;}return res;}

ll nCrInOr(ll n, ll r){ll res = 1;if(r>n-r)r = n-r;ll rin = 1;for(ll i = 1; i <=r ; i++)rin = (rin*i)%mod;rin = binexpomodulo(rin,mod-2);for(ll i = 1; i <= r; i++)res = (res*(n-i+1))%mod;res = (res*rin)%mod;return res;}

int msb(ll n){int ans;for(int i = 0 ; i < 64;  i++)if(n&(1LL<<i))ans = i+1;return ans;}

void strrev(string& s){int n = (s.size());for(int i = 0 ; i < n/2; i++)swap(s[i],s[n-1-i]);}

int main()

{

	int n; cin>>n;

	ll a[n];

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

		cin>>a[i];

	}

	ll dp[n] = {INF};

	dp[0] = 0;

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

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

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

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

  	return 0;

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



using namespace std;



int h[100002];

int dp[100002];

int n;



int solve(int i) {

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

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



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

	if(i+2 < n) 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("%d", &h[i]);



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



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



	return 0;

}

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



using namespace std;



int main() {

	int n; scanf("%d", &n);

	int h[n];

	int dp[n];



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

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



	dp[0] = 0;

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



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

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

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

	}



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



	return 0;

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

#include <vector>

using namespace std;



vector<int> h(100000), dp(100000, -1);



int cost(int n) {

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

  return dp[n] = min(cost(n - 1) + abs(h[n] - h[n - 1])

                      , cost(n - 2) + abs(h[n] - h[n - 2]));

}



int main() {

  int N;

  cin >> N;



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



  dp[0] = 0;

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

  cout << cost(N - 1);

  return 0;

}

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

using namespace std;

using ll = long long;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);



  ll N; cin >> N;

  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];

  vector<ll> dp(N + 5, 1e15);

  dp[0] = 0;

  for (ll i = 0; i < N; 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]));

  }

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

  return 0;

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

  #define endl "\n"

  #define ll long long int

  #define vi vector<int>

  #define vll vector<ll>

  #define vvi vector < vi >

  #define pii pair<int,int>

  #define pll pair<long long, long long>

  #define mod 1000000007

  #define inf 1000000000000000001;

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

  #define mp(x,y) make_pair(x,y)

  #define mem(a,val) memset(a,val,sizeof(a))

  #define pb push_back

  #define f first

  #define se second

  

  using namespace std;

  ll arr[1000000]={0};

  ll arr2[1000000]={0};



  ll func(ll n,ll cur){

    if(cur==n)

      return 0;

    if(cur>n)

      return inf;

    if(arr2[cur]!=-1)

      return arr2[cur];



    ll sum=0;



    sum=min(func(n,cur+1)+abs(arr[cur]-arr[cur+1]),  func(n,cur+2)+abs(arr[cur]-arr[cur+2]));



    // cout<<"cur is: "<<cur<<" and sum is: "<<sum<<endl;

    arr2[cur]=sum;

    return sum;

  }





  int main()

  {

    std::ios::sync_with_stdio(false);

    ll n=0,m=0,k=0,x=0,t1=0,t2=0,t3=0,f=0,sum=0,count=0;

    mem(arr2,-1);



    cin>>n;



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

      cin>>arr[i];

    }



    cout<<func(n-1,0);



    return 0;

  }

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

  #define endl "\n"

  #define ll long long int

  #define vi vector<int>

  #define vll vector<ll>

  #define vvi vector < vi >

  #define pii pair<int,int>

  #define pll pair<long long, long long>

  #define mod 1000000007

  #define inf 1000000000000000001;

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

  #define mp(x,y) make_pair(x,y)

  #define mem(a,val) memset(a,val,sizeof(a))

  #define pb push_back

  #define f first

  #define se second

  

  using namespace std;

  int main()

  {

    std::ios::sync_with_stdio(false);

    ll n=0,m=0,k=0,x=0,t1=0,t2=0,t3=0,f=0,sum=0,count=0;



    cin>>n;

    ll arr[n+1],dp[n+1];

    arr[0]=inf; dp[0]=0;



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

      cin>>arr[i];

    }

    dp[1]=0;



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



    return 0;

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

  #define endl "\n"

  #define ll long long int

  #define vi vector<int>

  #define vll vector<ll>

  #define vvi vector < vi >

  #define pii pair<int,int>

  #define pll pair<long long, long long>

  #define mod 1000000007

  #define inf 1000000000000000001;

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

  #define mp(x,y) make_pair(x,y)

  #define mem(a,val) memset(a,val,sizeof(a))

  #define pb push_back

  #define f first

  #define se second

  

  using namespace std;

  ll arr[1000000]={0};

  ll arr2[1000000]={0};



  ll func(ll n,ll cur){

    if(cur==n)

      return 0;

    if(cur>n)

      return inf;

    if(arr2[cur]!=-1)

      return arr2[cur];



    ll sum=0;



    sum=min(func(n,cur+1)+abs(arr[cur]-arr[cur+1]),  func(n,cur+2)+abs(arr[cur]-arr[cur+2]));



    // cout<<"cur is: "<<cur<<" and sum is: "<<sum<<endl;

    arr2[cur]=sum;

    return sum;

  }





  int main()

  {

    std::ios::sync_with_stdio(false);

    ll n=0,m=0,k=0,x=0,t1=0,t2=0,t3=0,f=0,sum=0,count=0;

    mem(arr2,-1);



    cin>>n;



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

      cin>>arr[i];

    }



    cout<<func(n-1,0);



    return 0;

  }

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

  #define endl "\n"

  #define ll long long int

  #define vi vector<int>

  #define vll vector<ll>

  #define vvi vector < vi >

  #define pii pair<int,int>

  #define pll pair<long long, long long>

  #define mod 1000000007

  #define inf 1000000000000000001;

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

  #define mp(x,y) make_pair(x,y)

  #define mem(a,val) memset(a,val,sizeof(a))

  #define pb push_back

  #define f first

  #define se second

  

  using namespace std;

  int main()

  {

    std::ios::sync_with_stdio(false);

    ll n=0,m=0,k=0,x=0,t1=0,t2=0,t3=0,f=0,sum=0,count=0;



    cin>>n;

    ll arr[n+1],dp[n+1];

    arr[0]=0; dp[0]=inf;



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

      cin>>arr[i];

    }

    dp[1]=0;



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



    return 0;

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

  #define endl "\n"

  #define ll long long int

  #define vi vector<int>

  #define vll vector<ll>

  #define vvi vector < vi >

  #define pii pair<int,int>

  #define pll pair<long long, long long>

  #define mod 1000000007

  #define inf 1000000000000000001;

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

  #define mp(x,y) make_pair(x,y)

  #define mem(a,val) memset(a,val,sizeof(a))

  #define pb push_back

  #define f first

  #define se second

  

  using namespace std;

  ll arr[1000000]={0};

  ll arr2[1000000]={0};



  ll func(ll n,ll cur){

    if(cur==n)

      return 0;

    if(cur>n)

      return inf;

    if(arr2[cur]!=-1)

      return arr2[cur];



    ll sum=0;



    sum=min(func(n,cur+1)+abs(arr[cur]-arr[cur+1]),  func(n,cur+2)+abs(arr[cur]-arr[cur+2]));



    // cout<<"cur is: "<<cur<<" and sum is: "<<sum<<endl;

    arr2[cur]=sum;

    return sum;

  }





  int main()

  {

    std::ios::sync_with_stdio(false);

    ll n=0,m=0,k=0,x=0,t1=0,t2=0,t3=0,f=0,sum=0,count=0;

    mem(arr2,-1);



    cin>>n;



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

      cin>>arr[i];

    }



    cout<<func(n-1,0);



    return 0;

  }

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

  #define endl "\n"

  #define ll long long int

  #define vi vector<int>

  #define vll vector<ll>

  #define vvi vector < vi >

  #define pii pair<int,int>

  #define pll pair<long long, long long>

  #define mod 1000000007

  #define inf 1000000000000000001;

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

  #define mp(x,y) make_pair(x,y)

  #define mem(a,val) memset(a,val,sizeof(a))

  #define pb push_back

  #define f first

  #define se second

  

  using namespace std;

  int main()

  {

    std::ios::sync_with_stdio(false);

    ll n=0,m=0,k=0,x=0,t1=0,t2=0,t3=0,f=0,sum=0,count=0;



    cin>>n;

    ll arr[n+1],dp[n+1];

    arr[0]=inf; dp[0]=inf;



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

      cin>>arr[i];

    }

    dp[1]=0;



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



    return 0;

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

using ll = long long;

using namespace std;



int n;

ll dp[100100];

int h[100100];

bool vis[100100];



ll func( int pos ) {

    if (pos == n) return 0;

    if ( vis[pos] ) return dp[pos];

    vis[pos] = 1;



    ll p = 2e9, q = 2e9;

    if ( pos + 1 <= n ) p = abs(h[pos] - h[pos + 1]) + func(pos + 1);

    if ( pos + 2 <= n ) q = abs(h[pos] - h[pos + 2]) + func(pos + 2);



    return dp[pos] = min(p, q);

}





int main() {

    cin >> n;

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

    cout << func(1) << endl;

    return 0;

}


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

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

int a[100005],d[100005];

int main()

{

	int n,i;

	memset(a,0,sizeof(a));

	scanf("%d",&n);

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

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

	d[n] = 0;

	d[n - 1] = abs(a[n] - a[n - 1]);

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

	{

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

	}

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

	return 0;

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

using namespace std;

const int N =1e6;



int dp[N], h[N];



int main(){

    int n;

    cin >> n;

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

        cin >> h[i];

    }

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

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

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

    }

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



}


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

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

int a[100005],d[100005];

int main()

{

	int n,i;

	memset(a,0,sizeof(a));

	scanf("%d",&n);

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

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

	d[n] = 0;

	d[n - 1] = abs(a[n] - a[n - 1]);

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

	{

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

	}

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

	return 0;

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



using namespace std;



int main(){

    int n, i;

    scanf("%d",&n);

    int height[n+5];

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

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

    }

    int ans = 1e9;

    int dp[n+5];

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

        dp[i] = 1e9;

    }

    dp[1] = 0;

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

        if(i > 1) dp[i] = min(dp[i], dp[i-1] + abs(height[i] - height[i-1]));

        if(i > 2) dp[i] = min(dp[i], dp[i-2] + abs(height[i] - height[i-2]));

    }

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

    return 0;

}


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

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

int a[100005],d[100005];

int main()

{

	int n,i;

	memset(a,0,sizeof(a));

	scanf("%d",&n);

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

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

	d[n] = 0;

	d[n - 1] = abs(a[n] - a[n - 1]);

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

	{

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

	}

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

	return 0;

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

using namespace std;



const int MAXN = 1e5 + 1;



int n, k, h[MAXN];



int main(){



    cin >> n;

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

    int dp[n + 5];

    for(int i = 1; i <= n; i++) dp[i] = 1e9;

    dp[1] = 0;

    for(int i = 2; i <= n; i++) for(int j = 1; j <= 2 && j < i; j++) if(i > j) dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));

    cout << dp[n] << endl;



    return 0;

}


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

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

int a[100005],d[100005];

int main()

{

	int n,i;

	memset(a,0,sizeof(a));

	scanf("%d",&n);

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

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

	d[n] = 0;

	d[n - 1] = abs(a[n] - a[n - 1]);

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

	{

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

	}

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

	return 0;

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



using namespace std;

typedef long long int ll;

ll dp[100010];

ll arr[100010];



int main(){

    ll n;

    scanf("%lld",&n);



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

        scanf("%lld",arr+i);

    }



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

        dp[i] = 10000000000000;

        if(i-1 >= 1){

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

        }

        if(i-2 >= 1){

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

        }

    }

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

}


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

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

int a[100005],d[100005];

int main()

{

	int n,i;

	memset(a,0,sizeof(a));

	scanf("%d",&n);

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

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

	d[n] = 0;

	d[n - 1] = abs(a[n] - a[n - 1]);

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

	{

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

	}

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

	return 0;

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

using namespace std;



int arr[100010];

int dp[100010];



int main (){

	int n;

	cin >> n;

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

		cin >> arr[i];

	}

	dp[1] = 0;

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

	

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

}

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

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

int a[100005],d[100005];

int main()

{

	int n,i;

	memset(a,0,sizeof(a));

	scanf("%d",&n);

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

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

	d[n] = 0;

	d[n - 1] = abs(a[n] - a[n - 1]);

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

	{

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

	}

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

	return 0;

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

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

#include <queue>

#include <stack>

#include <map>

#include <set>

#include <vector>

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

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

#define pii pair<int,int>

#define pll pair<long long ,long long>

#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MSC0(X) memset((X), '\0', sizeof((X)))

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define gg(x) getInt(&x)

using namespace std;

typedef long long ll;

inline void getInt(int* p);

const int maxn=1000010;

const int inf=0x3f3f3f3f;



ll n;

ll dp[maxn];

ll a[maxn];

int main()

{

    gbtb;

    cin>>n;

    repd(i,1,n)

    {

        cin>>a[i];

    }

    dp[1]=0;

    dp[0]=0;

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

    repd(i,3,n)

    {

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



    }

    cout<<dp[n];

    return 0;

}



inline void getInt(int* p) {

    char ch;

    do {

        ch = getchar();

    } while (ch == ' ' || ch == '\n');

    if (ch == '-') {

        *p = -(getchar() - '0');

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 - ch + '0';

        }

    }

    else {

        *p = ch - '0';

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 + ch - '0';

        }

    }

}

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

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

int a[100005],d[100005];

int main()

{

	int n,i;

	memset(a,0,sizeof(a));

	scanf("%d",&n);

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

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

	d[n] = 0;

	d[n - 1] = abs(a[n] - a[n - 1]);

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

	{

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

	}

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

	return 0;

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

using namespace std;

const int mx = 100005;

int dp[mx];

int A[mx];

void memo(int i,int n)

{

	if(i>n) return;

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

	memo(i+1,n);

}

int main()

{

     int n;cin>>n;

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

     	cin>>A[i];

     memset(dp,0,sizeof(dp));

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

     memo(3,n);

     cout<<dp[n]<<endl;

     return 0;

}

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

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

int a[100005],d[100005];

int main()

{

	int n,i;

	memset(a,0,sizeof(a));

	scanf("%d",&n);

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

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

	d[n] = 0;

	d[n - 1] = abs(a[n] - a[n - 1]);

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

	{

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

	}

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

	return 0;

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

using namespace std;



#define INF 1e18;

#define MAX_N 100005

long long N, h[MAX_N], memo[MAX_N];



long long dp(int pos) {

  if (pos < 1) {

  	return INF;

  }

  if (pos == 1) {

  	return 0;

  }

  if (pos == 2) {

  	return abs(h[2] - h[1]);

  }

  if (memo[pos] != -1) {

  	return memo[pos];

  }

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

}



int main() {

  cin >> N;

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

  	cin >> h[i];

  }

  /*

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

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

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

  }

  */

  /*

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

  	cout << i << ' ' << memo[i] << '\n';

  }

  */

  // cout << memo[N] << '\n';

  memset(memo, -1, sizeof memo);

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

}

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

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

int a[100005],d[100005];

int main()

{

	int n,i;

	memset(a,0,sizeof(a));

	scanf("%d",&n);

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

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

	d[n] = 0;

	d[n - 1] = abs(a[n] - a[n - 1]);

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

	{

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

	}

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

	return 0;

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

using namespace std;

const int mx = 100005;

int dp[mx];

int A[mx];

void memo(int i,int n)

{

	if(i>n) return;

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

	memo(i+1,n);

}

int main()

{

     int n;cin>>n;

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

     	cin>>A[i];

     memset(dp,0,sizeof(dp));

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

     memo(3,n);

     cout<<dp[n]<<endl;

     return 0;

}

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



using namespace std;

int main(){

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

	scanf("%lld", &n);

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

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

	}

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

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

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

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

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

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

using namespace std;



#define INF 1e18;

#define MAX_N 100005

long long N, h[MAX_N], memo[MAX_N];



long long dp(int pos) {

  if (pos < 1) {

  	return INF;

  }

  if (pos == 1) {

  	return 0;

  }

  if (pos == 2) {

  	return abs(h[2] - h[1]);

  }

  if (memo[pos] != -1) {

  	return memo[pos];

  }

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

}



int main() {

  cin >> N;

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

  	cin >> h[i];

  }

  /*

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

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

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

  }

  */

  /*

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

  	cout << i << ' ' << memo[i] << '\n';

  }

  */

  // cout << memo[N] << '\n';

  memset(memo, -1, sizeof memo);

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

}

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



using namespace std;

int main(){

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

	scanf("%lld", &n);

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

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

	}

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

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

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

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

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

}