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

using namespace std;

#define    sz    100110

#define    ll    long long int

ll n,c=0,p,q;

ll num[sz];

ll vis[sz];

ll dp[sz];



ll tani(int pos)

{



  if(pos>=n)return 0;

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

  vis[pos]=1;



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



}



int main()

{

    ll t,i;



    for(i=1;i<sz;i++)num[i]=1000000;



    cin>>n;

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

    {

        cin>>num[i];

    }

    t=tani(1);

    cout<<t<<endl;

    return 0;

}


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

using namespace std;

#define ff first

#define ss second

#define ll long long int

#define pii pair<int,int>

#define pll pair<ll,ll>

#define mem(x) memset(x, 0, sizeof x)

#define mem1(x) memset(x, -1, sizeof x)

#define MX 100005

ll arr[MX], dp[MX],n;

//ll rec(ll i, ll score)

//{

//    if(i==n-1) return score;

//    else if(i>=n) return 1e9;

//    else if(dp[i]<score && dp[i]!=-1) return dp[i];

//    else if(!i || dp[i]==-1 || score<dp[i])

//    {

//        ll ret1=1e9, ret2=1e9;

//        if(i+1<=n-1) ret1= rec(i+1, score+llabs(arr[i+1]-arr[i]));

//        if(i+2<=n-1) ret2= rec(i+2, score+llabs(arr[i+2]-arr[i]));

//        return dp[i]=min(ret1,ret2);

//    }

//}

int main()

{

    ll i,j,k,l, m;

    scanf("%lld",&n);

    for(i=0; i<n; i++) scanf("%lld",&arr[i]);

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

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

    {

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

        if(i+2<=n-1) dp[i+2]=min(dp[i+2], dp[i]+llabs(arr[i]-arr[i+2]));

    }

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

    return 0;

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

using namespace std;



#define fr(i,n) _back

#define pb	push_back

#define eb	emplace_back

#define mk	make_pair

#define fi	first

#define se	second

#define endl	'\n'



typedef long long ll;

typedef pair<int,int> ii;

typedef vector<ii> vii;

const int INF = 0x3f3f3f3f;

const double PI = acos(-1.0);

const int N = 1e5 + 3;

int h[N];

int dp[N];



int main() {

    ios_base::sync_with_stdio(false);

    memset(dp, INF, sizeof dp);

    int n; cin >> n;

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



    dp[0] = 0;

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

        for(int j = max(0,i-2); j < i; j++)

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



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

    return 0;

}


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

using namespace std;

#define ff first

#define ss second

#define ll long long int

#define pii pair<int,int>

#define pll pair<ll,ll>

#define mem(x) memset(x, 0, sizeof x)

#define mem1(x) memset(x, -1, sizeof x)

#define MX 100005

ll arr[MX], dp[MX],n;

//ll rec(ll i, ll score)

//{

//    if(i==n-1) return score;

//    else if(i>=n) return 1e9;

//    else if(dp[i]<score && dp[i]!=-1) return dp[i];

//    else if(!i || dp[i]==-1 || score<dp[i])

//    {

//        ll ret1=1e9, ret2=1e9;

//        if(i+1<=n-1) ret1= rec(i+1, score+llabs(arr[i+1]-arr[i]));

//        if(i+2<=n-1) ret2= rec(i+2, score+llabs(arr[i+2]-arr[i]));

//        return dp[i]=min(ret1,ret2);

//    }

//}

int main()

{

    ll i,j,k,l, m;

    scanf("%lld",&n);

    for(i=0; i<n; i++) scanf("%lld",&arr[i]);

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

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

    {

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

        if(i+2<=n-1) dp[i+2]=min(dp[i+2], dp[i]+llabs(arr[i]-arr[i+2]));

    }

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

    return 0;

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

using namespace std;



int N, a[100100], dp[100100];



int f(int n) {

	if (n==1) return 0;

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

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

	dp[n] = min(

				f(n-1) + abs(a[n] - a[n-1]),

				f(n-2) + abs(a[n] - a[n-2])

				);

	return dp[n];

}



int main() {

	cin >> N;

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

		cin >> a[i];

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

	cout << f(N) << endl;

	return 0;

}

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

using namespace std;

#define ff first

#define ss second

#define ll long long int

#define pii pair<int,int>

#define pll pair<ll,ll>

#define mem(x) memset(x, 0, sizeof x)

#define mem1(x) memset(x, -1, sizeof x)

#define MX 100005

ll arr[MX], dp[MX],n;

//ll rec(ll i, ll score)

//{

//    if(i==n-1) return score;

//    else if(i>=n) return 1e9;

//    else if(dp[i]<score && dp[i]!=-1) return dp[i];

//    else if(!i || dp[i]==-1 || score<dp[i])

//    {

//        ll ret1=1e9, ret2=1e9;

//        if(i+1<=n-1) ret1= rec(i+1, score+llabs(arr[i+1]-arr[i]));

//        if(i+2<=n-1) ret2= rec(i+2, score+llabs(arr[i+2]-arr[i]));

//        return dp[i]=min(ret1,ret2);

//    }

//}

int main()

{

    ll i,j,k,l, m;

    scanf("%lld",&n);

    for(i=0; i<n; i++) scanf("%lld",&arr[i]);

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

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

    {

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

        if(i+2<=n-1) dp[i+2]=min(dp[i+2], dp[i]+llabs(arr[i]-arr[i+2]));

    }

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

    return 0;

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

using namespace std;

typedef long long LL;



int arr[100007];

int dp[100007];



int Solve(int idx, int n){

//	cout<<cost<<" "<<idx<<endl;

	if(idx >= n)return 1e9;

	if(idx == n - 1){

		return 0;	

	}

	

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

	

	

	return dp[idx] = min(abs(arr[idx] - arr[idx+1]) + Solve(idx+1, n), abs(arr[idx] - arr[idx+2]) + Solve(idx+2,n));

}



int main(){

	int n; cin>>n;

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

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

		

	cout<<Solve(0,n)<<endl;

	return 0;

}

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

using namespace std;

#define ff first

#define ss second

#define ll long long int

#define pii pair<int,int>

#define pll pair<ll,ll>

#define mem(x) memset(x, 0, sizeof x)

#define mem1(x) memset(x, -1, sizeof x)

#define MX 100005

ll arr[MX], dp[MX],n;

//ll rec(ll i, ll score)

//{

//    if(i==n-1) return score;

//    else if(i>=n) return 1e9;

//    else if(dp[i]<score && dp[i]!=-1) return dp[i];

//    else if(!i || dp[i]==-1 || score<dp[i])

//    {

//        ll ret1=1e9, ret2=1e9;

//        if(i+1<=n-1) ret1= rec(i+1, score+llabs(arr[i+1]-arr[i]));

//        if(i+2<=n-1) ret2= rec(i+2, score+llabs(arr[i+2]-arr[i]));

//        return dp[i]=min(ret1,ret2);

//    }

//}

int main()

{

    ll i,j,k,l, m;

    scanf("%lld",&n);

    for(i=0; i<n; i++) scanf("%lld",&arr[i]);

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

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

    {

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

        if(i+2<=n-1) dp[i+2]=min(dp[i+2], dp[i]+llabs(arr[i]-arr[i+2]));

    }

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

    return 0;

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

using namespace std;

int dp[100005];

int H[100005];

void memo(int i,int n)

{

	if(i==n) return;

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

	memo(i+1,n);

}

int main()

{

	int N;cin>>N;

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

	{

        cin>>H[i];

	}

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

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

	memo(2,N);

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

	return 0;

}

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

using namespace std;

#define ff first

#define ss second

#define ll long long int

#define pii pair<int,int>

#define pll pair<ll,ll>

#define mem(x) memset(x, 0, sizeof x)

#define mem1(x) memset(x, -1, sizeof x)

#define MX 100005

ll arr[MX], dp[MX],n;

//ll rec(ll i, ll score)

//{

//    if(i==n-1) return score;

//    else if(i>=n) return 1e9;

//    else if(dp[i]<score && dp[i]!=-1) return dp[i];

//    else if(!i || dp[i]==-1 || score<dp[i])

//    {

//        ll ret1=1e9, ret2=1e9;

//        if(i+1<=n-1) ret1= rec(i+1, score+llabs(arr[i+1]-arr[i]));

//        if(i+2<=n-1) ret2= rec(i+2, score+llabs(arr[i+2]-arr[i]));

//        return dp[i]=min(ret1,ret2);

//    }

//}

int main()

{

    ll i,j,k,l, m;

    scanf("%lld",&n);

    for(i=0; i<n; i++) scanf("%lld",&arr[i]);

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

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

    {

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

        if(i+2<=n-1) dp[i+2]=min(dp[i+2], dp[i]+llabs(arr[i]-arr[i+2]));

    }

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

    return 0;

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

using namespace std;

#define    sz    100110

#define    ll    long long int

ll n,c=0,p,q;

ll num[sz];

ll vis[sz];

ll dp[sz];



ll tani(int pos)

{



  if(pos>=n)return 0;

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

  vis[pos]=1;



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



}



int main()

{

    ll t,i;



    for(i=1;i<sz;i++)num[i]=1000000;



    cin>>n;

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

    {

        cin>>num[i];

    }

    t=tani(1);

    cout<<t<<endl;

    return 0;

}


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

using namespace std;



int a[110000];

int m[110000];

int n;



int dp(){

	m[0] = 0;

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

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

		m[i] = min(

			(m[i-1] + abs(a[i] - a[i-1])),

			(m[i-2] + abs(a[i] - a[i-2]))

		);	

	}

	return m[n-1];

}



int main(){

	cin>>n;

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

		cin>>a[i];

	}

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

	return 0;

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

using namespace std;



#define fr(i,n) _back

#define pb	push_back

#define eb	emplace_back

#define mk	make_pair

#define fi	first

#define se	second

#define endl	'\n'



typedef long long ll;

typedef pair<int,int> ii;

typedef vector<ii> vii;

const int INF = 0x3f3f3f3f;

const double PI = acos(-1.0);

const int N = 1e5 + 3;

int h[N];

int dp[N];



int main() {

    ios_base::sync_with_stdio(false);

    memset(dp, INF, sizeof dp);

    int n; cin >> n;

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



    dp[0] = 0;

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

        for(int j = max(0,i-2); j < i; j++)

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



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

    return 0;

}


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

using namespace std;



int a[110000];

int m[110000];

int n;



int dp(){

	m[0] = 0;

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

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

		m[i] = min(

			(m[i-1] + abs(a[i] - a[i-1])),

			(m[i-2] + abs(a[i] - a[i-2]))

		);	

	}

	return m[n-1];

}



int main(){

	cin>>n;

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

		cin>>a[i];

	}

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

	return 0;

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

using namespace std;



int N, a[100100], dp[100100];



int f(int n) {

	if (n==1) return 0;

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

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

	dp[n] = min(

				f(n-1) + abs(a[n] - a[n-1]),

				f(n-2) + abs(a[n] - a[n-2])

				);

	return dp[n];

}



int main() {

	cin >> N;

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

		cin >> a[i];

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

	cout << f(N) << endl;

	return 0;

}

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

using namespace std;



int a[110000];

int m[110000];

int n;



int dp(){

	m[0] = 0;

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

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

		m[i] = min(

			(m[i-1] + abs(a[i] - a[i-1])),

			(m[i-2] + abs(a[i] - a[i-2]))

		);	

	}

	return m[n-1];

}



int main(){

	cin>>n;

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

		cin>>a[i];

	}

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

	return 0;

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

using namespace std;

typedef long long LL;



int arr[100007];

int dp[100007];



int Solve(int idx, int n){

//	cout<<cost<<" "<<idx<<endl;

	if(idx >= n)return 1e9;

	if(idx == n - 1){

		return 0;	

	}

	

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

	

	

	return dp[idx] = min(abs(arr[idx] - arr[idx+1]) + Solve(idx+1, n), abs(arr[idx] - arr[idx+2]) + Solve(idx+2,n));

}



int main(){

	int n; cin>>n;

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

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

		

	cout<<Solve(0,n)<<endl;

	return 0;

}

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

using namespace std;



int a[110000];

int m[110000];

int n;



int dp(){

	m[0] = 0;

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

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

		m[i] = min(

			(m[i-1] + abs(a[i] - a[i-1])),

			(m[i-2] + abs(a[i] - a[i-2]))

		);	

	}

	return m[n-1];

}



int main(){

	cin>>n;

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

		cin>>a[i];

	}

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

	return 0;

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

using namespace std;

int dp[100005];

int H[100005];

void memo(int i,int n)

{

	if(i==n) return;

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

	memo(i+1,n);

}

int main()

{

	int N;cin>>N;

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

	{

        cin>>H[i];

	}

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

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

	memo(2,N);

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

	return 0;

}

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

using namespace std;



int a[110000];

int m[110000];

int n;



int dp(){

	m[0] = 0;

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

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

		m[i] = min(

			(m[i-1] + abs(a[i] - a[i-1])),

			(m[i-2] + abs(a[i] - a[i-2]))

		);	

	}

	return m[n-1];

}



int main(){

	cin>>n;

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

		cin>>a[i];

	}

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

	return 0;

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

using namespace std;

#define    sz    100110

#define    ll    long long int

ll n,c=0,p,q;

ll num[sz];

ll vis[sz];

ll dp[sz];



ll tani(int pos)

{



  if(pos>=n)return 0;

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

  vis[pos]=1;



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



}



int main()

{

    ll t,i;



    for(i=1;i<sz;i++)num[i]=1000000;



    cin>>n;

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

    {

        cin>>num[i];

    }

    t=tani(1);

    cout<<t<<endl;

    return 0;

}


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

#include<iostream>

#include<algorithm>

#include<cstring>

#include<queue>

#include<cmath>

using namespace std;

const int maxn = 1e5 + 5;

int main()

{

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

	scanf("%d",&n);

	for(int i = 1;i <= n;i++)scanf("%d",&a[i]);

	dp[1] = 0,dp[2] = fabs(a[1] - a[2]),dp[3] = fabs(a[1] - a[3]);

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

		if(dp[i + 1] + fabs(a[i+2] - a[i + 1]) > dp[i] + fabs(a[i]-a[i + 2]))dp[i + 2] = dp[i] + fabs(a[i] - a[i + 2]);

		else dp[i + 2] = dp[i + 1] + fabs(a[i + 2] - a[i +1]);

	}

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

	return 0;

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

using namespace std;



#define fr(i,n) _back

#define pb	push_back

#define eb	emplace_back

#define mk	make_pair

#define fi	first

#define se	second

#define endl	'\n'



typedef long long ll;

typedef pair<int,int> ii;

typedef vector<ii> vii;

const int INF = 0x3f3f3f3f;

const double PI = acos(-1.0);

const int N = 1e5 + 3;

int h[N];

int dp[N];



int main() {

    ios_base::sync_with_stdio(false);

    memset(dp, INF, sizeof dp);

    int n; cin >> n;

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



    dp[0] = 0;

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

        for(int j = max(0,i-2); j < i; j++)

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



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

    return 0;

}


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

#include<iostream>

#include<algorithm>

#include<cstring>

#include<queue>

#include<cmath>

using namespace std;

const int maxn = 1e5 + 5;

int main()

{

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

	scanf("%d",&n);

	for(int i = 1;i <= n;i++)scanf("%d",&a[i]);

	dp[1] = 0,dp[2] = fabs(a[1] - a[2]),dp[3] = fabs(a[1] - a[3]);

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

		if(dp[i + 1] + fabs(a[i+2] - a[i + 1]) > dp[i] + fabs(a[i]-a[i + 2]))dp[i + 2] = dp[i] + fabs(a[i] - a[i + 2]);

		else dp[i + 2] = dp[i + 1] + fabs(a[i + 2] - a[i +1]);

	}

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

	return 0;

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

using namespace std;



int N, a[100100], dp[100100];



int f(int n) {

	if (n==1) return 0;

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

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

	dp[n] = min(

				f(n-1) + abs(a[n] - a[n-1]),

				f(n-2) + abs(a[n] - a[n-2])

				);

	return dp[n];

}



int main() {

	cin >> N;

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

		cin >> a[i];

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

	cout << f(N) << endl;

	return 0;

}

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

#include<iostream>

#include<algorithm>

#include<cstring>

#include<queue>

#include<cmath>

using namespace std;

const int maxn = 1e5 + 5;

int main()

{

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

	scanf("%d",&n);

	for(int i = 1;i <= n;i++)scanf("%d",&a[i]);

	dp[1] = 0,dp[2] = fabs(a[1] - a[2]),dp[3] = fabs(a[1] - a[3]);

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

		if(dp[i + 1] + fabs(a[i+2] - a[i + 1]) > dp[i] + fabs(a[i]-a[i + 2]))dp[i + 2] = dp[i] + fabs(a[i] - a[i + 2]);

		else dp[i + 2] = dp[i + 1] + fabs(a[i + 2] - a[i +1]);

	}

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

	return 0;

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

using namespace std;

typedef long long LL;



int arr[100007];

int dp[100007];



int Solve(int idx, int n){

//	cout<<cost<<" "<<idx<<endl;

	if(idx >= n)return 1e9;

	if(idx == n - 1){

		return 0;	

	}

	

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

	

	

	return dp[idx] = min(abs(arr[idx] - arr[idx+1]) + Solve(idx+1, n), abs(arr[idx] - arr[idx+2]) + Solve(idx+2,n));

}



int main(){

	int n; cin>>n;

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

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

		

	cout<<Solve(0,n)<<endl;

	return 0;

}

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

#include<iostream>

#include<algorithm>

#include<cstring>

#include<queue>

#include<cmath>

using namespace std;

const int maxn = 1e5 + 5;

int main()

{

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

	scanf("%d",&n);

	for(int i = 1;i <= n;i++)scanf("%d",&a[i]);

	dp[1] = 0,dp[2] = fabs(a[1] - a[2]),dp[3] = fabs(a[1] - a[3]);

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

		if(dp[i + 1] + fabs(a[i+2] - a[i + 1]) > dp[i] + fabs(a[i]-a[i + 2]))dp[i + 2] = dp[i] + fabs(a[i] - a[i + 2]);

		else dp[i + 2] = dp[i + 1] + fabs(a[i + 2] - a[i +1]);

	}

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

	return 0;

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

using namespace std;

int dp[100005];

int H[100005];

void memo(int i,int n)

{

	if(i==n) return;

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

	memo(i+1,n);

}

int main()

{

	int N;cin>>N;

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

	{

        cin>>H[i];

	}

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

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

	memo(2,N);

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

	return 0;

}

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

#include<iostream>

#include<algorithm>

#include<cstring>

#include<queue>

#include<cmath>

using namespace std;

const int maxn = 1e5 + 5;

int main()

{

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

	scanf("%d",&n);

	for(int i = 1;i <= n;i++)scanf("%d",&a[i]);

	dp[1] = 0,dp[2] = fabs(a[1] - a[2]),dp[3] = fabs(a[1] - a[3]);

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

		if(dp[i + 1] + fabs(a[i+2] - a[i + 1]) > dp[i] + fabs(a[i]-a[i + 2]))dp[i + 2] = dp[i] + fabs(a[i] - a[i + 2]);

		else dp[i + 2] = dp[i + 1] + fabs(a[i + 2] - a[i +1]);

	}

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

	return 0;

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

#include<algorithm>



using namespace std;



int h[1000000];

int dp[1000000];



int main()

{

    int n;

    cin>>n;



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

        cin>>h[i];

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

}

// Faster C++ solution for the same problem (measured speedup: 5.224923670396924x):
//动态规划青蛙跳

#include <stdio.h>

#include <math.h>

#include <algorithm>



using namespace std;



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



int main()

{

	scanf("%d",&n);

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

	{

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

	}

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

	{

		if(i == 1)

		{

			dp[i] = 0;

		}

		else if(i == 2)

		{

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

		}

		else

		{

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

		}

	}

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

	return 0;

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

#include <algorithm>

#include <list>

#include <map>

#include <queue>

#include <stack>

#include <string>

#include <vector>



using namespace std;



int main() {

    vector<int> stones;

    vector<int> energyReq;

    int n;

    cin >> n;

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

        int h;

        cin >> h;

        stones.push_back(h);

    }

    energyReq.push_back(0);

    energyReq.push_back(abs(stones[1] - stones[0]));

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

        energyReq.push_back(min(energyReq[i - 2] + abs(stones[i] - stones[i - 2]), energyReq[i - 1] + abs(stones[i] - stones[i - 1])));

    }

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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.2895769789765295x):
//动态规划青蛙跳

#include <stdio.h>

#include <math.h>

#include <algorithm>



using namespace std;



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



int main()

{

	scanf("%d",&n);

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

	{

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

	}

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

	{

		if(i == 1)

		{

			dp[i] = 0;

		}

		else if(i == 2)

		{

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

		}

		else

		{

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

		}

	}

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

	return 0;

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

using namespace std;

long long n,x;

long long h[100005],f[100005];

int main(){

	cin>>n;

	h[0]=0;

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

		cin>>h[i];

	}

	f[1]=0;

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

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

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

	}

	cout<<f[n];

}


// Faster C++ solution for the same problem (measured speedup: 5.180374298121784x):
//动态规划青蛙跳

#include <stdio.h>

#include <math.h>

#include <algorithm>



using namespace std;



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



int main()

{

	scanf("%d",&n);

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

	{

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

	}

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

	{

		if(i == 1)

		{

			dp[i] = 0;

		}

		else if(i == 2)

		{

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

		}

		else

		{

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

		}

	}

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

	return 0;

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

using namespace std;

int n,a[100010],f[100010]; 

int main()

{

	cin>>n;

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

		cin>>a[i];

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

	{

		if(i==1)

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

		else

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

	}

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

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.232597526709703x):
//动态规划青蛙跳

#include <stdio.h>

#include <math.h>

#include <algorithm>



using namespace std;



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



int main()

{

	scanf("%d",&n);

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

	{

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

	}

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

	{

		if(i == 1)

		{

			dp[i] = 0;

		}

		else if(i == 2)

		{

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

		}

		else

		{

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

		}

	}

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

	return 0;

}