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

using namespace std;



const int N = 1e5 + 5 , INF = 2e9;



int n;

int h[N];

int mem[N];



int dp(int i){

    if(i == n)return 0;



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

    int ans = INF;



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

    if(i <= n-2){

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

    }



    return mem[i] = ans;

}



main(){

    scanf("%d" , &n);



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

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

    }

    n --;

    memset(mem , -1 , sizeof mem);

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

}


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

using namespace std;



const int N = 1e5 + 5 , INF = 2e9;



int dp[N];

int h[N];



main(){

    int n;



    scanf("%d" , &n);

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

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

    }



    dp[1] = 0;

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

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

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

using namespace std;



const int N = 1e5 + 5 , INF = 2e9;



int n;

int h[N];

int mem[N];



int dp(int i){

    if(i == n)return 0;



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

    int ans = INF;



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

    if(i <= n-2){

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

    }



    return mem[i] = ans;

}



main(){

    scanf("%d" , &n);



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

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

    }

    n --;

    memset(mem , -1 , sizeof mem);

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

}


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


#include<bits/stdc++.h>





using namespace std;



using ll   = long long;

using ii   = pair   < int , int >;

using i3   = pair   < int , ii  >;

using li   = pair   < ll  , int >;

using lii  = pair   < ll  , ii  >;

using pll  = pair   < ll  , ll  >;

using vi   = vector < int       >;

using vl   = vector < ll        >;

using vii  = vector < ii        >;

using vli  = vector < li        >;

using vpll = vector < pll       >;

using vi3  = vector < i3        >;

using vlii = vector < lii       >;





const int N = 2e5 + 5;

const ll INF = 1e17 + 7;

const double eps = 1e-9 , PI = acos(-1);







int n , m;

ll  a[N];

ll dp[N];



void solve(int testCase){



    scanf("%d" , &n);



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

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

            dp[i] = INF;

    }



    dp[0] = 0;

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

            if(i > 0)

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

            if(i > 1)

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

    }



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



}



main(){



    int t = 1;

    // scanf("%d" , &t);



    for(int testCase = 1 ; testCase <= t ; testCase ++){

            solve(testCase);

    }



    return 0;

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

using namespace std;



const int N = 1e5 + 5 , INF = 2e9;



int n;

int h[N];

int mem[N];



int dp(int i){

    if(i == n)return 0;



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

    int ans = INF;



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

    if(i <= n-2){

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

    }



    return mem[i] = ans;

}



main(){

    scanf("%d" , &n);



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

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

    }

    n --;

    memset(mem , -1 , sizeof mem);

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

}


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


#include<bits/stdc++.h>





using namespace std;



using ll   = long long;

using ii   = pair   < int , int >;

using i3   = pair   < int , ii  >;

using li   = pair   < ll  , int >;

using lii  = pair   < ll  , ii  >;

using pll  = pair   < ll  , ll  >;

using vi   = vector < int       >;

using vl   = vector < ll        >;

using vii  = vector < ii        >;

using vli  = vector < li        >;

using vpll = vector < pll       >;

using vi3  = vector < i3        >;

using vlii = vector < lii       >;





const int N = 2e5 + 5;

const ll INF = 1e17 + 7;

const double eps = 1e-9 , PI = acos(-1);







int n , m;

int  a[N];

int dp[N];



void solve(int testCase){



    scanf("%d" , &n);



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

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

            dp[i] = 2e9;

    }



    dp[0] = 0;

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

            if(i > 0)

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

            if(i > 1)

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

    }



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



}



main(){



    int t = 1;

    // scanf("%d" , &t);



    for(int testCase = 1 ; testCase <= t ; testCase ++){

            solve(testCase);

    }



    return 0;

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

using namespace std;



const int N = 1e5 + 5 , INF = 2e9;



int n;

int h[N];

int mem[N];



int dp(int i){

    if(i == n)return 0;



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

    int ans = INF;



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

    if(i <= n-2){

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

    }



    return mem[i] = ans;

}



main(){

    scanf("%d" , &n);



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

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

    }

    n --;

    memset(mem , -1 , sizeof mem);

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

}


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


#include <bits/stdc++.h>



using namespace std;



const int N   = 1e5 + 5;

const int INF = 2e9;



int jump[N];

int h[N];

int n;





main(){



    scanf("%d" , &n);

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

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

    }



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

            jump[i] = INF;

    }



    jump[0] = 0;

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



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



            if(i + 2 < n) {

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

            }

    }



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



    return 0;

}
// Slower C++ solution:


#include <bits/stdc++.h>



using namespace std;





const int N = 1e5 + 5;



int n;

int h[N];

int mem[N];



int jump(int i){

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



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



    int x = abs(h[i] - h[i + 1]) + jump(i + 1);

    int y = x;



    if(i + 2 < n) y = abs(h[i] - h[i + 2]) + jump(i + 2);



    mem[i] = min(x , y);

    return mem[i];

}



main(){

    scanf("%d" , &n);



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

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

    }



    memset(mem , -1 , sizeof mem);

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



    return 0;

}


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


#include <bits/stdc++.h>



using namespace std;



const int N   = 1e5 + 5;

const int INF = 2e9;



int jump[N];

int h[N];

int n;





main(){



    scanf("%d" , &n);

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

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

    }



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

            jump[i] = INF;

    }



    jump[0] = 0;

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



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



            if(i + 2 < n) {

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

            }

    }



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



    return 0;

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

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0)

#define endl "\n"

#define int long long

typedef vector<int> vi;

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

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

#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

#define pii              pair <int,int>

#define DEBUG(x) cerr << '>' << #x << ':' << x << endl;

typedef long long ll;

//#pragma comment(linker, "/STACK:667772160")

#define in_range(x, y, r, c) ((x >= 0 && x < r && y >= 0 && y < c))



const double eps=1e-9;

const int MOD=1e9+7;

const int N=1e5+30;

const int inf = 1e17+995;



template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }

template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

template <typename T> T exp(T b, T p){T x = 1;while(p){if(p&1)x=(x*b);b=(b*b);p=p>>1;}return x;}

inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

void boostIO() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}

int mem[N],n ,tall[N];

int dp(int idx){

 if(idx==n-1)

     return 0;

 if(idx>n-1)

     return inf;

    int &ret=mem[idx];

    if(ret!=-1)

   return ret;

    ret=min(abs(tall[idx]-tall[idx+1])+dp(idx+1),abs(tall[idx]-tall[idx+2])+dp(idx+2));



    return ret;

}

int32_t main() {

boostIO();

cin>>n;

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

        cin>>tall[i];

    }

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

    int ans=dp(0);

    cout<<ans<<endl;

}

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

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0)

#define endl "\n"

#define int long long

typedef vector<int> vi;

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

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

#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

#define pii              pair <int,int>

#define DEBUG(x) cerr << '>' << #x << ':' << x << endl;

typedef long long ll;

//#pragma comment(linker, "/STACK:667772160")

#define in_range(x, y, r, c) ((x >= 0 && x < r && y >= 0 && y < c))



const double eps=1e-9;

const int MOD=1e9+7;

const int N=1e5+30;

const int inf = 1e17+995;



template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }

template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

template <typename T> T exp(T b, T p){T x = 1;while(p){if(p&1)x=(x*b);b=(b*b);p=p>>1;}return x;}

inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

void boostIO() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}



int32_t main() {

boostIO();

int n;

cin>>n;

vi h(n);

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

        cin>>h[i];

    }

    vi dp(n,inf);

    dp[0]=0;

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

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

            if(j<n){

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

            }

        }

    }

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

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

#define ll long long int

using namespace std;



ll n;

ll dp[1000005];



int solve(ll a[], int i)

{

	if (i == n - 1)

	{

		return 0;

	}

	if (i > n - 1)

	{

		return INT_MAX;

	}



	if (dp[i] != -1)

	{

		return dp[i];

	}



	int value;

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



	return dp[i] = value;

}



int main()

{

	cin >> n;

	ll a[n];

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

	{

		cin >> a[i];

	}

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

	cout << solve(a, 0) << endl;;

	return 0;

}

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

#define ll long long int

using namespace std;



int n;

int dp[1000005];

/*

int solve(ll a[], int i)

{

	if (i == n - 1)

	{

		return 0;

	}

	if (i > n - 1)

	{

		return INT_MAX;

	}



	if (dp[i] != -1)

	{

		return dp[i];

	}



	int value;

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



	return dp[i] = value;

}

*/



int main()

{

	cin >> n;

	int a[n];

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

	{

		cin >> a[i];

	}

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

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

	{

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

	}

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

	return 0;

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



using namespace std;

int n;

int ar[100005];

long long mem[100005];



long long solve(int ind){

    if(ind==n-1){

        return 0;

    }

    if(ind>n-1){

        return 1e11;

    }

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

        return mem[ind];

    }

    long long ch1=0,ch2=0;

    ch1=solve(ind+1)+abs(ar[ind+1]-ar[ind]);

    ch2=solve(ind+2)+abs(ar[ind+2]-ar[ind]);

    return mem[ind]=min(ch1,ch2);

}



int main() {

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

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

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    memset(mem,-1,sizeof mem);

    cin>>n;

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

        cin>>ar[i];

    }

    cout<<solve(0)<<endl;

    return 0;

}

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



using namespace std;

int n;

int h[100005];

int dp[100005];



int main() {

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

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

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    memset(dp,-1,sizeof dp);

    cin>>n;

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

        cin>>h[i];

    }

    reverse(h,h+n);

    dp[0]=0;

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

        if(i-2>=0){

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

        }

        else{

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

        }

    }

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

    return 0;

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



using namespace std;

int n;

int ar[100005];

long long mem[100005];



long long solve(int ind){

    if(ind==n-1){

        return 0;

    }

    if(ind>n-1){

        return 1e11;

    }

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

        return mem[ind];

    }

    long long ch1=0,ch2=0;

    ch1=solve(ind+1)+abs(ar[ind+1]-ar[ind]);

    ch2=solve(ind+2)+abs(ar[ind+2]-ar[ind]);

    return mem[ind]=min(ch1,ch2);

}



int main() {

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

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

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    memset(mem,-1,sizeof mem);

    cin>>n;

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

        cin>>ar[i];

    }

    cout<<solve(0)<<endl;

    return 0;

}

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



using namespace std;

#define ll long long

const int N=100005;

int n;

int ar[N];

int mem[N];



int solve(int ind){

    if(ind==n-1){

        return 0;

    }

    if(ind>=n){

        return 1e9;

    }

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

        return mem[ind];

    }

    int ch1=solve(ind+1)+abs(ar[ind]-ar[ind+1]);

    int ch2=solve(ind+2)+abs(ar[ind]-ar[ind+2]);

    return mem[ind]=min(ch1,ch2);

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    memset(mem,-1,sizeof mem);

    cin>>n;

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

        cin>>ar[i];

    }

    cout<<solve(0)<<endl;

    return 0;

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



using namespace std;

int n;

int ar[100005];

long long mem[100005];



long long solve(int ind){

    if(ind==n-1){

        return 0;

    }

    if(ind>n-1){

        return 1e11;

    }

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

        return mem[ind];

    }

    long long ch1=0,ch2=0;

    ch1=solve(ind+1)+abs(ar[ind+1]-ar[ind]);

    ch2=solve(ind+2)+abs(ar[ind+2]-ar[ind]);

    return mem[ind]=min(ch1,ch2);

}



int main() {

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

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

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    memset(mem,-1,sizeof mem);

    cin>>n;

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

        cin>>ar[i];

    }

    cout<<solve(0)<<endl;

    return 0;

}

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



using namespace std;

#define ll long long



const int INF = 1e9+5;



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int n;

    cin>>n;

    int ar[n];

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

        cin>>ar[i];

    }

    vector<int> dp(n,INF);

    dp[0]=0;

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

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

            if(j<n){

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

            }

        }

    }

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



    return 0;

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



using namespace std;

int n;

int h[100005];

int dp[100005];



int main() {

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

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

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    memset(dp,-1,sizeof dp);

    cin>>n;

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

        cin>>h[i];

    }

    reverse(h,h+n);

    dp[0]=0;

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

        if(i-2>=0){

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

        }

        else{

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

        }

    }

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

    return 0;

}

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



using namespace std;

#define ll long long



const int INF = 1e9+5;



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int n;

    cin>>n;

    int ar[n];

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

        cin>>ar[i];

    }

    vector<int> dp(n,INF);

    dp[0]=0;

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

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

            if(j<n){

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

            }

        }

    }

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



    return 0;

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



using namespace std;

#define ll long long

const int N=100005;

int n;

int ar[N];

int mem[N];



int solve(int ind){

    if(ind==n-1){

        return 0;

    }

    if(ind>=n){

        return 1e9;

    }

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

        return mem[ind];

    }

    int ch1=solve(ind+1)+abs(ar[ind]-ar[ind+1]);

    int ch2=solve(ind+2)+abs(ar[ind]-ar[ind+2]);

    return mem[ind]=min(ch1,ch2);

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    memset(mem,-1,sizeof mem);

    cin>>n;

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

        cin>>ar[i];

    }

    cout<<solve(0)<<endl;

    return 0;

}

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



using namespace std;

#define ll long long



const int INF = 1e9+5;



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int n;

    cin>>n;

    int ar[n];

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

        cin>>ar[i];

    }

    vector<int> dp(n,INF);

    dp[0]=0;

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

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

            if(j<n){

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

            }

        }

    }

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



    return 0;

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

using namespace std;

#define ll long long

#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

#define dcm(a) setprecision(a)<<fixed

#define MOD 1000000007

#define clr(memo, a) memset(memo,a,sizeof(memo))

int const N=1e5+5;

int a[N];

int n;

int memo[N];

int dp(int i){

    if(i>n)

        return +N;

    if(i==n-1)

        return 0;

    int &ret=memo[i];

    if(ret!=-1)

        return ret;

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

}

int main()

{cin>>n;

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

    cin>>a[i];

clr(memo,-1);

cout<<dp(0)<<endl;





}


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

#include <bitset>

using namespace std;

#define ll long long

#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

#define dcm(a) setprecision(a)<<fixed

#define MOD 1000000007

#define clr(memo, a) memset(memo,a,sizeof(memo))

#define PI acos(-1)



int const N=1e5+5;

int const inf=1e9+5;

void solve(){

int n;

cin>>n;

vector<int> dp(n,inf);

vector<int> v(n);

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

    cin>>v[i];

dp[0]=0;

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

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

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

}

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

}

int main(){

    fast;



solve();



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

using namespace std;

typedef long long ll;

const int N=1e6;

const ll inf=1e6;

int n,a[N];

ll dp[N];

ll f(int i)

{

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

    if(i==n) return 0;

    ll p1=inf,p2=inf;

    if(i<=(n-1)) p1=abs(a[i]-a[i+1])+f(i+1);

    if(i<=(n-2)) p2=abs(a[i]-a[i+2])+f(i+2);

    dp[i]=min(p1,p2);

    return dp[i];

}

int main()

{

    scanf("%d",&n);

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

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

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

    printf("%lld",f(1));

    //while(1);

    return 0;

}

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

using namespace std;

const int INF=1e9+5;

int main()

{

    int n;

    scanf("%d", &n);

    vector<int> h(n);

    vector<int> dp(n, INF);

    for(int& x : h)

        scanf("%d", &x);

    dp[0]=0;

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

    {

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

        {

            if(j<n)

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

        }

    }

    cout << dp[n-1];

    //while(1);

    return 0;

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

using namespace std;

typedef long long ll;

const int N=1e6;

const ll inf=1e6;

int n,a[N];

ll dp[N];

ll f(int i)

{

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

    if(i==n) return 0;

    ll p1=inf,p2=inf;

    if(i<=(n-1)) p1=abs(a[i]-a[i+1])+f(i+1);

    if(i<=(n-2)) p2=abs(a[i]-a[i+2])+f(i+2);

    dp[i]=min(p1,p2);

    return dp[i];

}

int main()

{

    scanf("%d",&n);

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

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

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

    printf("%lld",f(1));

    //while(1);

    return 0;

}

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

using namespace std;

const int N=1e5+1;

vector<int> h(N);

const int INF=1e9+5;

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

int n;

int f(int i){

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

    if(i>n) return INF;

    if(i==n) return 0;

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

}

int main(){

    scanf("%d",&n);

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

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

    }

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

    //while(1);

    return 0;

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

using namespace std;

typedef long long ll;

const int N=1e6;

const ll inf=1e6;

int n,a[N];

ll dp[N];

ll f(int i)

{

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

    if(i==n) return 0;

    ll p1=inf,p2=inf;

    if(i<=(n-1)) p1=abs(a[i]-a[i+1])+f(i+1);

    if(i<=(n-2)) p2=abs(a[i]-a[i+2])+f(i+2);

    dp[i]=min(p1,p2);

    return dp[i];

}

int main()

{

    scanf("%d",&n);

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

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

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

    printf("%lld",f(1));

    //while(1);

    return 0;

}

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

using namespace std;

const int N=1e5+1;

vector<int> h(N);

const int INF=1e9+5;

vector<int> dp(N,INF);

int n;

int main(){

    scanf("%d",&n);

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

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

    }

    dp[1]=0;

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

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

            if(j<=n){

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

            }

        }

    }

    cout<<dp[n];

    // while(1);

    return 0;

}