stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



const int mx=1e5+1;

int n,k;

int h[mx],dp[mx];

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

{

    if(s==n) return 0;

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

    int ret=INT_MAX;

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

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

    }

    return dp[s]=ret;

}

int main()

{

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

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



    cin>>n;

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

    memset(dp,-1,sizeof dp);

    cout<<solve(1);



    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

const int INF = 0x3f3f3f3f;

const int maxn = 2e5 + 9;

inline int read()

{

    int data = 0, f = 1;

    char ch = getchar();

    while (!isdigit(ch))

    {

        if (ch == '-')

            f = -1;

        ch = getchar();

    }

    while (isdigit(ch))

    {

        data = (data << 3) + (data << 1) + ch - '0';

        ch = getchar();

    }

    return f * data;

}

int h[maxn], ans[maxn];

int main()

{

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

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

    //std::ios::sync_with_stdio(false);

    //std::cin.tie(0);

    int n = read();

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

        h[i] = read();

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

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

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

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

    //fclose(stdin);

    //fclose(stdout);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

const int maxn=100000+10;

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

int main()

{

	cin>>n;

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

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

	dp[1]=0;

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

	{

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

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

	}

	cout<<dp[n]<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5+5;

int a[maxn];

int dp[maxn];

int main()

{

	int n;

	scanf("%d",&n);

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

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

	for(int 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("%d\n",dp[n]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define N 100007

#define inf 999999999

using namespace std;



long long mem[N];

long long ara[N];

int n;



long long dp(int i, int j)

{

    if(i >= n)

        return inf;

    if(i == j)

        return 0;

    if(mem[i] != -1)

        return mem[i];

    long long ans = min(abs(ara[i + 1] - ara[i]) + dp(i + 1, j), abs(ara[i + 2] - ara[i]) + dp(i + 2, j));

    mem[i] = ans;

    return ans;

}

int main()

{

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

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

    cin >> n;

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

        cin >> ara[i];

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

    cout << dp(0, n - 1) << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5+5;

int a[maxn];

int dp[maxn];

int main()

{

	int n;

	scanf("%d",&n);

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

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

	for(int 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("%d\n",dp[n]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using ii = pair<int, int>;

using iii = pair<ii, int>;

#define vt vector

#define pq priority_queue

#define pb push_back

#define pf push_front

#define mp make_pair

#define fi first

#define se second

#define __lcm(a, b) a * b / __gcd(a, b)

const int MOD = 1e9 + 7;

const int INF = 2e9;

const int N = 1e5 + 5;



int n;

int a[N], dp[N];



int f(int idx) {

    if(idx > n) return INF;

    if(idx == n) return 0;

    int &sol = dp[idx];

    if(sol != -1) return sol;

    return sol = min(f(idx + 1) + abs(a[idx] - a[idx + 1]), 

                     f(idx + 2) + abs(a[idx] - a[idx + 2]));

}



void solve() {

    cin >> n;

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

        cin >> a[i];

    }

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

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

}



int main() {

 

    ios_base::sync_with_stdio(0);

    cin.tie(0); cout.tie(0);

    

    solve();

    

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5+5;

int a[maxn];

int dp[maxn];

int main()

{

	int n;

	scanf("%d",&n);

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

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

	for(int 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("%d\n",dp[n]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;



#define ll long long



const int N = 1e5+4;

const ll inf = 1e16;

int h[N], n;

ll dp[3][N];



ll f(int j, int t)

{

    if(j > n)

        return inf;



    if(dp[t][j] != -1)

        return dp[t][j];



    ll x = f(j + 1, 1), y = f(j + 2, 2);



    if(x == inf and y == inf)

        x = y = 0;



    return dp[t][j] = abs(h[j] - h[j - t]) + min(x, y);

}



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    cin >> n;



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

        cin >> h[i];



    memset(dp, -1, sizeof dp);



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



    return 0;

}


// Optimized solution to the same problem (faster):
 #include<bits/stdc++.h>

using namespace std;

#define ll long long

#define mod 10000007



int main()

{

    ll n;

    cin>>n;

    ll cost[n+1];

    ll dp[n+1];

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

    {

        cin>>cost[i];



    }

    dp[n]=0;

    dp[n-1]=abs(cost[n]-cost[n-1]);



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

    {

        //if(i!=(n-1))

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

    }

    //

    cout<<dp[1]<<endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
// A - Frog 1



// 問題文

// N個の足場があります。 足場には 1,2,…,N と番号が振られています。 各 i (1≤i≤N) について、

// 足場 iの高さはhiです。最初、足場1にカエルがいます。 カエルは次の行動を何回か繰り返し、足場 N

// まで辿り着こうとしています。足場iにいるとき、足場 i+1 または i+2へジャンプする。

 // このとき、ジャンプ先の足場を jとすると、コスト |hi−hj|を支払う。カエルが足場 Nに辿り着くまでに支払うコストの

 // 総和の最小値を求めてください。



// 制約

// 入力はすべて整数である。

// 2≤N≤10の５乗

// 1≤hi≤10の4乗

// 入力

// 入力は以下の形式で標準入力から与えられる。

// N

// h1 h2 …hN

// 出力

// カエルが支払うコストの総和の最小値を出力せよ。

// 入力例 1 

// Copy

// 4

// 10 30 40 20

//  出力例 1 

// Copy

// 30

// 足場 

// 1→ 2→ 4

 // と移動すると、コストの総和は |10−30|+|30−20|=30となります。

// 入力例 2 

// Copy

// 2

// 10 10

// 出力例 2 

// Copy

// 0

// 足場 

// 1→ 2と移動すると、コストの総和は |10−10|=0となります。



// 入力例 3 

// Copy

// 6

// 30 10 60 10 60 50

// 出力例 3 

// Copy

// 40

// 足場 

// 1→ 3→ 5→ 6と移動すると、コストの総和は |30−60|+|60−60|+|60−50|=40となります。

//miss

#include<cstdio>

#include<algorithm>

#include<iostream>

#include<cmath>

using namespace std;

int main(void){

	long long N,h[100100]={0};

	long long dp[100100]={0};

	long long inf=1e9;

	cin>>N;

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

		cin>>h[i];

	}

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

		dp[i]=inf;

	}

	dp[0]=0;

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

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

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

	}

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

	return 0;

}

// Optimized solution to the same problem (faster):
#include<algorithm>

#include<iostream>

#include<cstdio>

#include<cmath>

using namespace std;

int N=0;

long long dp[100100],Hi[100100];

int main(void){

	cin>>N;

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

		cin>>Hi[i];

	}

	dp[0]=0;

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

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

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

	}

	cout<<dp[N-1];

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;



#define pb push_back

#define mp make_pair

#define fi first

#define se second



const int N = 1e5 + 5;

ll dp[N][2], h[N];

int n;



ll solve(int n, int f) {

    if (n == 1) return 0;

  	if (n == 0) return 1e18;

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

    dp[n][f - 1] = 1e18;

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

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    

    cin >> n;

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

        cin >> h[i];

    }

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

    ll ans = min(solve(n, 1), solve(n, 2));

    cout << ans;

    

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;



#define pb push_back

#define mp make_pair

#define fi first

#define se second



const int N = 1e5 + 5;

const ll inf = 1e18;

ll dp[N], h[N];

int n;



ll solve(int n) {

    if (n == 1) return 0;

    if (n == 0) return inf;

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

    dp[n] = inf;

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

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    

    cin >> n;

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

        cin >> h[i];

    }

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

    ll ans = solve(n);

    cout << ans;

    

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



#define int long long



int arr[100005];

int dp[100005];



int f(int n)

{

	if(n==1)

	{

		return 0;

	}

	if(n<=0)

	{

	return INT_MAX;

	}

	if(dp[n]!=-1)

	{

		return dp[n];

	}

	int ans1 = INT_MAX, ans2= INT_MAX;

	ans1 = abs(arr[n] - arr[n-1]) + f(n-1);

	if(n>2)

	{

		ans2  = abs(arr[n]-arr[n-2])+f(n-2);

	}

	dp[n] =  min(ans1,ans2);

	return dp[n];

}



int32_t main()

{

	int n;

	cin>>n;

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

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

	cout<<f(n);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>



using namespace std;





int main()

{

	int n;

	cin>>n;

	vector<long long> a(n);



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



	int dp[n];

	fill(dp,dp+n,0);

	dp[0] = 0;

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

	{

		if(i-2>=0)

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

		else

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

	}

	cout<<dp[n-1];

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



#define int long long

int arr[100005];

int dp[100005];

int n;



int f(int i)

{

	if(i==n-1)

	{

		return 0;

	}

	if(i>=n)

	{

		return 1000000000;

	}

	if(dp[i]!=-1)

	{

		return dp[i];

	}

	if(i==n-2)

	{

		return dp[i]= abs(arr[i]-arr[i+1]) + f(i+1);

	}

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

}



int32_t main()

{

	cin>>n;

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

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

	cout<<f(0);

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>



using namespace std;





int main()

{

	int n;

	cin>>n;

	vector<long long> a(n);



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



	int dp[n];

	fill(dp,dp+n,0);

	dp[0] = 0;

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

	{

		if(i-2>=0)

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

		else

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

	}

	cout<<dp[n-1];

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



typedef unsigned long long uLL;

typedef long long int LL;

typedef pair <int,int> pii;

typedef pair <int,pii> piii;

typedef pair <long long,long long> pll;

typedef pair <long long,pll> plll;

const int N = 1e5 + 5;

const int inf = 1e9;

const long long INF = 1e18;

const double PI = acos(-1.0);

const double EPS = 1e-8;

const int MOD = 1000000007;



int n;

int a[ N ];

LL dp[ N ];



LL solve( int idx ) {

        if( idx > n ) return INF;

        if( idx == n ) return 0;

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

        LL ret = INF;

        ret = solve( idx + 1 ) + abs( a[idx+1] - a[idx] );

        ret = min( ret , solve( idx + 2 ) + abs( a[idx+2] - a[idx] ) );

        return dp[idx] = ret;

}

int main( int argc , char const *argv[] ) {

        ios_base::sync_with_stdio( false ); cin.tie( NULL );

        cin >> n;

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

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

        cout << solve( 1 ) << endl;

        return 0;

}
























// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



#define endl "\n"

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

#define see(x) cerr << #x << " = " << x << "\n";

#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())

typedef long long int LL;

typedef pair <int,int> pii;

const int MOD = 1e9 + 7;

const int inf = 1e9;

const double PI = acos(-1.0);

const long long INF = 1e18;

const int N = 1e5 + 5;



int n , a[ N ];

int dp[ N ];



int main( ) {

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

        cin >> n;

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

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

        dp[n] = 0;

        for( int i = n; i >= 1; i-- ) {

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

                        if( i + j <= n ) {

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

                        }

                }

        }

        cout << dp[1] << endl;

        return 0;

}
















// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i,a,b) for(ll i=a;i<b;i++)

#define each(i,a) for(auto&&i:a)

#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))

using namespace std;

using ll=long long;

const ll MOD=1000000007;

const ll LINF=0x1fffffffffffffff;

const vector<ll> four={0,1,0,-1,0};

using tuplis=pair<ll,pair<ll,ll>>;

template<class T>using pq=priority_queue<T,vector<T>,greater<T>>;

template<class T>inline constexpr bool update_min(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}

template<class T>inline constexpr bool update_max(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}





ll n=100002;

vector<ll>h(n),mem(n,LINF);

ll dp(ll i){

    if(i<1)return LINF;

    if(i==1)return 0;

    if(mem[i]!=LINF)return mem[i];

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

    return mem[i];

}

signed main(){

    cin>>n;

    rep(i,1,n+1)cin>>h[i];

    cout<<dp(n);

}








// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll INF = 0x1fffffffffffffff;



int main(){

    ll n;

    cin >> n;

    vector<ll> h(n);

    for(ll& i : h) cin >> i;

    vector<ll> dp(n, INF);

    dp[0] = 0;

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

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

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

    }

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

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <cstdlib>

using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



const long long INF = 1LL << 60;



// 入力

int N;

long long h[100010];



// DP テーブル

long long dp[100010];



int main() {

    int N; cin >> N;

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



    // 初期化 (最小化問題なので INF に初期化)

    for (int i = 0; i < 100010; ++i) dp[i] = INF;



    // 初期条件

    dp[0] = 0;



    // ループ

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

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

        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));

    }



    // 答え

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

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

const ll INF = 1LL << 60;



template<class T> inline bool chmin(T &a,T b){

    if(a > b){

        a = b;

        return 1;

    }

    return 0;

}





int main(void){

    int N;

    cin >> N;

    ll h[N];

    ll dp[N];

    

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

        cin >> h[i];

    }

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

        dp[i] = INF;

    }

    

    dp[0] = 0;

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

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

        if(i > 1){

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

        }

    }

    

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

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



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

#define pi acos(-1)

#define eps 1e-6

#define inf 1e14



typedef long long ll;

typedef vector<int> vi;

typedef pair<int, int> ii;

typedef vector<ii> vii;

typedef vector<vi> vvi;



const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

const int dy[8] = {-1, 0, 1, -1, 1, 0, 1, -1};

const int maxn = 2 * 1e5;

const int mod = 1e9 + 7;

const int maxa = 2 * 1e5;



int mul(int a, int b) { return a * 1LL * b % mod;}

int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b;}

int sub(int a, int b) { return a >= b ? a - b : a - b + mod;}

int pow(int a, int k)

{

    int res = 1;

    while (k)

    {

        if (k % 2) res = mul(res, a);

        a = mul(a, a);

        k /= 2;

    }



    return res;

}



int inv(int a)

{

    return pow(a, mod - 2);

}



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



int f(int id)

{

    if (id == n - 1)

        return 0;



    if (dp[id] != -1)

        return dp[id];



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

    

    if (id + 2 <= n - 1)

        dp[id] = min(dp[id], f(id + 2) + abs(h[id] - h[id + 2]));

                     

    return dp[id];

}



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

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

    cin >> n;

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

        cin >> h[i];



    cout << f(0);

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;



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

#define pi acos(-1)

#define eps 1e-6

#define inf 1e14



typedef long long ll;

typedef vector<int> vi;

typedef pair<int, int> ii;

typedef vector<ii> vii;

typedef vector<vi> vvi;



const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

const int dy[8] = {-1, 0, 1, -1, 1, 0, 1, -1};

const int maxn = 2 * 1e5;

const int mod = 1e9 + 7;

const int maxa = 2 * 1e5;



int mul(int a, int b) { return a * 1LL * b % mod;}

int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b;}

int sub(int a, int b) { return a >= b ? a - b : a - b + mod;}

int pow(int a, int k)

{

    int res = 1;

    while (k)

    {

        if (k % 2) res = mul(res, a);

        a = mul(a, a);

        k /= 2;

    }



    return res;

}



int inv(int a)

{

    return pow(a, mod - 2);

}



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



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cin >> n;

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

        cin >> h[i];



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

    {

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

        if (i > 1)

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

    }

    

    cout << dp[n - 1];

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



#define INF 0x3f3f3f3f

#define MAXN 100010

#define endl "\n"

#define abs(a, b) ((a > b) ? a-b : b-a)



typedef long long int ll;



/* End */



int n;

ll a[MAXN];

ll pd[MAXN];



ll solve(int i) {

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

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

	return pd[i] = min(solve(i+1) + abs(a[i], a[i+1]),

			   (i < n-2) ?  solve(i+2) + abs(a[i], a[i+2]) : INF);

}



int main() {

	cin.tie(NULL);

	ios_base::sync_with_stdio(false);

	

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



	cin >> n;

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



	cout << solve(0) << endl;



	return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



#define INF 0x3f3f3f3f

#define MAXN 100010

#define endl "\n"

#define abs(a, b) ((a > b) ? a-b : b-a)



typedef long long int ll;



/* End */



int n;

ll a[MAXN];

ll pd[MAXN];



int main() {

	cin.tie(NULL);

	ios_base::sync_with_stdio(false);

	

	cin >> n;

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



	pd[n-1] = 0;

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

		if (i < n-2) pd[i] = min(pd[i+1] + abs(a[i], a[i+1]),

			                 pd[i+2] + abs(a[i], a[i+2]));

		else pd[i] = abs(a[i], a[i+1]);

	}



	cout << pd[0] << endl;



	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
// Author : Mohamed Sameh

#include <bits/stdc++.h>

typedef long long ll ;

#define pb push_back

#define f first

#define s second

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

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

#define SZ(a) (int)a.size()

#define Flush fflush(stdout);

using namespace std ;

const int M = 1e5 + 2 ;

int n;

int a[M];

int dp[M];

int solve (int i )

{

    if (i >= n )return 1e9 ;

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

    int &ret = dp[i];

    if (~ret)return ret ;

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

}

int main()

{

    scanf ("%d" , &n );

    for (int i =0 ; i < n ;i++)scanf ("%d" , a+i );

    a[n] =0 ;

    a[n+1] = 0;

    memset(dp , -1 ,sizeof dp );

    cout << solve(0) <<"\n";

}


// Optimized solution to the same problem (faster):
// Author : Mohamed Sameh

#include <bits/stdc++.h>

typedef long long ll ;

#define pb push_back

#define f first

#define s second

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

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

#define SZ(a) (int)a.size()

#define Flush fflush(stdout);

using namespace std ;

const int M = 1e5 + 2 ;

int n;

int a[M];

int dp[M];

int main()

{

    scanf ("%d" , &n );

    for (int i =0 ; i < n ;i++)scanf ("%d" , a+i );

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

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

    {

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

    }

    cout << dp[n-1] <<"\n";

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int n;

int a[100000];

int dp[100000];



int solve(int i)

{

	if (i == n - 1)

		return dp[i] = 0;

	if (dp[i] != -1)

		return dp[i];

	int ans = INT_MAX;

	if (i < n - 1)

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

	if (i < n - 2)

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

	return dp[i] = ans;

}

int main()

{

	cin >> n;

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

		cin >> a[i];

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

	cout << solve(0) << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;



int n;

int a[100000];

int dp[100000];



int main()

{

	cin >> n;

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

		cin >> a[i];

	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;

}


// Fastest known solution for this problem: