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

using namespace std;

const int maxn = 1e5 + 5;

int main(){

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

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

	scanf("%d",&n);

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

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

	dp[1] = 0;

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

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

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

	}

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

	return 0;

}

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



using namespace std;

long long dp[1000005],num[1000005];

int main()

{

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

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

    ios_base::sync_with_stdio(0);

    cin.tie(NULL);

    long long a,b=2;

    cin>>a;

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

    {

        cin>>num[i];

        long long mi;

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

        {

            if(i-j<0)

                break;

            if(j==1)

                mi=dp[i-j]+abs(num[i]-num[i-j]);

            if(dp[i-j]+abs(num[i]-num[i-j])<mi)

            {

                mi=dp[i-j]+abs(num[i]-num[i-j]);

            }

            dp[i]=mi;

        }

    }

    cout<<dp[a-1];

    return 0;

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



using namespace std;



const int N = 1e5 + 9;



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



int sol(int i, int prev){

    if(i >= n)  return 1e9;

    if(i == n - 1)  return abs(h[i] - h[i - 1 - (prev == 1)]);



    int &ret = dp[i][prev];

    if(~ret)    return ret;



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

}



int main(){

    cin >> n;

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

        cin >> h[i];



    memset(dp, -1, sizeof dp);



    cout << min(sol(1, 0), sol(2, 1));



    return 0;

}

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



using namespace std;

long long dp[1000005],num[1000005];

int main()

{

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

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

    ios_base::sync_with_stdio(0);

    cin.tie(NULL);

    long long a,b=2;

    cin>>a;

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

    {

        cin>>num[i];

        long long mi;

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

        {

            if(i-j<0)

                break;

            if(j==1)

                mi=dp[i-j]+abs(num[i]-num[i-j]);

            if(dp[i-j]+abs(num[i]-num[i-j])<mi)

            {

                mi=dp[i-j]+abs(num[i]-num[i-j]);

            }

            dp[i]=mi;

        }

    }

    cout<<dp[a-1];

    return 0;

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



using namespace std;



int n, h[100002], dp[100002][3];



int sol(int i, int choice){

    if(i==0) return 0;

    if(i<0) return 1E9;



    int &ret = dp[i][choice];

    if(~ret) return ret;



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

}



int main()

{

    cin >> n;

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

        cin >> h[i];



    memset(dp, -1, sizeof dp);

    cout << min(sol(n-1, 1), sol(n-1, 2));

}


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



using namespace std;

long long dp[1000005],num[1000005];

int main()

{

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

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

    ios_base::sync_with_stdio(0);

    cin.tie(NULL);

    long long a,b=2;

    cin>>a;

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

    {

        cin>>num[i];

        long long mi;

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

        {

            if(i-j<0)

                break;

            if(j==1)

                mi=dp[i-j]+abs(num[i]-num[i-j]);

            if(dp[i-j]+abs(num[i]-num[i-j])<mi)

            {

                mi=dp[i-j]+abs(num[i]-num[i-j]);

            }

            dp[i]=mi;

        }

    }

    cout<<dp[a-1];

    return 0;

}
// Slower C++ solution:


#include <bits/stdc++.h>

using namespace  std;



int N;

const int SIZE = 100005;

long h [SIZE];

int mem [SIZE];



int dp (int i) {

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

  

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



  long ret = LLONG_MAX;



  if (i+1 < N) 

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

  if (i+2 < N)

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



  return  mem[i] = ret;

}



int main (){ 



  cin  >> N;

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

    cin >> h[i];

  }



  memset(mem, -1, sizeof mem);



  cout << dp(0);



}

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



using namespace std;

long long dp[1000005],num[1000005];

int main()

{

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

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

    ios_base::sync_with_stdio(0);

    cin.tie(NULL);

    long long a,b=2;

    cin>>a;

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

    {

        cin>>num[i];

        long long mi;

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

        {

            if(i-j<0)

                break;

            if(j==1)

                mi=dp[i-j]+abs(num[i]-num[i-j]);

            if(dp[i-j]+abs(num[i]-num[i-j])<mi)

            {

                mi=dp[i-j]+abs(num[i]-num[i-j]);

            }

            dp[i]=mi;

        }

    }

    cout<<dp[a-1];

    return 0;

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

#define maxn 100005

using namespace std;



int main(){

    int n;

    cin >> n;

    int h[maxn];

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

        cin >> h[i];

    }

    int dp[maxn];

    fill(dp, dp+maxn, 0x7fffffff);

    dp[0] = 0;

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

        int temp = 0;

        if(i+1 < n){

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

            if(temp < dp[i+1])

                dp[i+1] = temp;

        }

        if(i+2 < n){

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

            if(temp < dp[i+2])

                dp[i+2] = temp;

        }

    }

    cout << dp[n-1];

    return 0;

}


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



using namespace std;

long long dp[1000005],num[1000005];

int main()

{

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

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

    ios_base::sync_with_stdio(0);

    cin.tie(NULL);

    long long a,b=2;

    cin>>a;

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

    {

        cin>>num[i];

        long long mi;

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

        {

            if(i-j<0)

                break;

            if(j==1)

                mi=dp[i-j]+abs(num[i]-num[i-j]);

            if(dp[i-j]+abs(num[i]-num[i-j])<mi)

            {

                mi=dp[i-j]+abs(num[i]-num[i-j]);

            }

            dp[i]=mi;

        }

    }

    cout<<dp[a-1];

    return 0;

}
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

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

#define per(i,a,n) for (int i=n-1;i>=a;i--)

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

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

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

#define fi first

#define se second

#define pp push_back

#define pb pop_back

#define pi 3.141592654

#define MOD 1000000007 

#define cons1 1e12

#define cons2 1e6

using namespace std;

typedef long long ll;

typedef vector<int> vi;

typedef pair<int, int> pa;

typedef unsigned long long int ull;

typedef double long dl;

const int N = 1e5+9;

int n;

int v[N], ans[N];

int sol(int i) {

	if (ans[i] == -1) {

		if (i == n - 1)

			ans[i] = 0;

		else if (i == n - 2)

			ans[i] = abs(v[i] - v[i + 1]);

		else 

			ans[i] = min(abs(v[i] - v[i + 1])+sol(i + 1)

				, abs(v[i] - v[i + 2]) + sol(i + 2));

		

	}

	return ans[i];

	

}

void solve() {

	clr(ans, -1);

	cin >> n;

	rep(i, 0, n)

		cin >> v[i];

	cout << sol(0) << endl;

}

int main() {

	ios::sync_with_stdio(0);

	cin.tie(NULL);

	cout.tie(NULL);

	int t = 1;

	//cin >> t;

	while (t--)

		solve();



#ifndef ONLINE_JUDGE

	- system("pause");

#endif



}

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



using namespace std;

long long dp[1000005],num[1000005];

int main()

{

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

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

    ios_base::sync_with_stdio(0);

    cin.tie(NULL);

    long long a,b=2;

    cin>>a;

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

    {

        cin>>num[i];

        long long mi;

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

        {

            if(i-j<0)

                break;

            if(j==1)

                mi=dp[i-j]+abs(num[i]-num[i-j]);

            if(dp[i-j]+abs(num[i]-num[i-j])<mi)

            {

                mi=dp[i-j]+abs(num[i]-num[i-j]);

            }

            dp[i]=mi;

        }

    }

    cout<<dp[a-1];

    return 0;

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

using namespace std;

int dif(int a, int b)

{

    int ans=a-b;

    if(ans<0) ans*=-1;

    return ans;

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int N, h[100005],i,j;

    int f1,f2;

    cin>>N;

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

        cin>>h[i];

    int M[100005]={0};

    M[N-2]=dif(h[N-1],h[N-2]);

    for(i=N-3;i>=0;i--)

    {

        f1=dif(h[i+1],h[i])+M[i+1];

        f2=dif(h[i+2],h[i])+M[i+2];

        M[i]=min(f1,f2);

    }

    cout<<M[0]<<endl;

    return 0;

}


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

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

#define debug(x) cout << #x << " " << x << endl;

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

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

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

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

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

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

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

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

      std::cout << DP[n-1] << '\n';

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



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

using namespace std;

int n;

int h[1000005], memo[1000005];

int f(int n) {

    if(n == 1) {                        // bisa juga base case nya n = 0, f(0) harus tinggi, misal 1e9;

        return 0;

    }

    if(n == 2) {

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

    } 

    else if(memo[n] != -1) {

        return memo[n];

    }

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

    return memo[n];

}



int main() {

    scanf("%d", &n);

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

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

    }

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

    f(n);

    printf("%d\n", f(n));

}

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

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

#define debug(x) cout << #x << " " << x << endl;

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

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

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

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

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

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

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

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

      std::cout << DP[n-1] << '\n';

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



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

using namespace std;



typedef signed long long ll;

const int MX = 1e5 + 5;

const int INF = 1e9 + 5;

int n, A[MX], dp[MX];



int solve(int pos) {

    if(pos > n) return INF;

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

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

    int ans = INF;

    if(pos + 1 < n) ans = min(ans, abs(A[pos] - A[pos + 1]) + solve(pos + 1));

    if(pos + 2 < n) ans = min(ans, abs(A[pos] - A[pos + 2]) + solve(pos + 2));

    return dp[pos] = ans;

}



int main() {

    scanf("%d", &n);



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

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

    }

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

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

    return 0;

}

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

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

#define debug(x) cout << #x << " " << x << endl;

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

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

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

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

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

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

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

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

      std::cout << DP[n-1] << '\n';

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



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

#include<cmath>

#include<algorithm>

#include<cstring>

using namespace std;



int h[100055],dp[100055];

const int inf = 0x3f3f3f;

int main()

{

	int n;

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

	cin>>n;

	h[1]=inf;

	h[0]=inf;

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

		cin>>h[i];

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

	return 0;

} 

//max(h[i],h[i-2])-min(h[i],h[i-2])

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

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

#define debug(x) cout << #x << " " << x << endl;

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

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

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

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

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

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

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

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

      std::cout << DP[n-1] << '\n';

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



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

using namespace std;

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

typedef long long ll;

const int maxn = 1e6 + 5;

const int inf = 0x3f3f3f3f;

ll a[maxn];

ll dp[maxn];



int main()

{

    IO;

    int n, k=2;

    cin >> n ;

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

        cin >> a[i];

    memset(dp, inf, sizeof(dp));

    dp[1] = 0;

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

    {

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

        {

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

        }

    }

    cout << dp[n] << endl;

}


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

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

#define debug(x) cout << #x << " " << x << endl;

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

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

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

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

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

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

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

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

      std::cout << DP[n-1] << '\n';

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



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

using namespace std;

const int nax = 1e5+3;

int number;

int dyn[nax];

int a[nax];

int op1(int i){

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

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

	int res = abs(a[i]-a[i+1])+op1(i+1);

	if(i!=number-2) res = min(res, abs(a[i]-a[i+2])+op1(i+2));

	return dyn[i]=res;

}

int main(){

	cin>>number;

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

	memset(dyn, -1, sizeof dyn);

	cout<<op1(0)<<endl;

	return 0;

}


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

using namespace  std ;

typedef long long  ll;

typedef pair<ll, ll> Pll;

#define F first

#define S second

#define MP make_pair

#define PB push_back

#define rad(X) cout << (X) << endl

#define ASH(X) cout << (X) << " "

#define debug(x) cout << #x << " " << x << endl;

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

#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)

#define cir(I,B,A) for(ll I = (A); I >=(B); I--)

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

#define MS1(X) memset((X), -1, sizeof((X)))

#define SORT(c) (sort(c.begin(),c.end()))

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())

#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)

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

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};

ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};

//vector<ll>a,b,c;

map<ll,ll>m1,m2,m3;

ll DP[100005];



/************************************************/



void Execute()

{

      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;

      std::cin >> n;

      ll ar[n];

      FOR(i,0,n-1) cin >> ar[i];



      DP[0] = 0;

      DP[1] = abs(ar[1] - ar[0]);



      FOR(i,2,n-1)

      {

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

            b = abs(ar[i] - ar[i-2]) + DP[i-2];

        DP[i] = min(a,b);

      }

      std::cout << DP[n-1] << '\n';

}



int32_t main()

{

    //#ifndef ONLINE_JUDGE

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

    //#endif



    FAST();

    //CASES



        Execute();



}