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

using namespace std;

#define ll long long

#define ld long double

#define sf scanf

#define pf printf

#define pb push_back

#define llu unsigned long long

#define U unsigned int

#define SIZE 1000002

#define pie 3.14159265358979323

#define minuss 1e-6

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

 

#define BIG 100000000

 

ll  lcm(ll a,ll b)

{

    ll GCD=__gcd(a,b);

    ll lcm=(a*b)/GCD;

    return lcm;

}

ll dp[100005];

ll weight[1000005],value[1000005];

ll total,val;

ll call(ll n)

{

    if(n>=total)

        return 0;

 

    if(dp[n]!=-1)

        return dp[n];

 

    ll res1=BIG,res2=BIG;

 

   // if(weight[n]+c<=val)

    res1=abs(weight[n]-weight[n+1]) + call(n+1);

    if(n+2<=total) res2=abs(weight[n]-weight[n+2]) + call(n+2);

    //cout<<n<<" "<<res1<<" "<<res2<<endl;

    dp[n]=min(res1,res2);

    return dp[n];

 

}

int main()

{

    cin>>total;

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

        cin>>weight[i];

 

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

    ll ret=call(1);

    cout<<ret<<endl;

    return 0;

}

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

using namespace std;

#define endl '\n'

#define optimize() ios_base::sync_with_stdio(0);

int n;

int arr[100001];

int cost[100001];



int func(int index)

{

    if(index>=n-1)

        return 0;

    if(cost[index]!=-1)

        return cost[index];





    if(index+1<=n-1 && index+2<=n-1)

    {

        return cost[index]=min(abs(arr[index]-arr[index+1])+func(index+1),abs(arr[index]-arr[index+2])+func(index+2));

    }



    else if(index+1<=n-1)

    {

        return cost[index]=abs(arr[index]-arr[index+1])+func(index+1);

    }





}

int main()

{

    optimize();



    cin>>n;

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

    {

        cin>>arr[i];

    }



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



    int res=func(0);

    cout<<res<<endl;

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

using namespace std;

int n;

long long h[100005];

long long dp[100005];



long long solve(int i){

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

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



	dp[i] = 1e17;

	if(i+1 <= n-1)

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

	if(i+2 <= n-1)

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



	return dp[i];

}



int main(){

	scanf("%d", &n);

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

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

	memset(dp, -1, sizeof dp);

	cout<<solve(0)<<endl;

	return 0;

}

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

using namespace std;

#define endl '\n'

#define optimize() ios_base::sync_with_stdio(0);

int n;

int arr[100001];

int cost[100001];



int func(int index)

{

    if(index>=n-1)

        return 0;

    if(cost[index]!=-1)

        return cost[index];





    if(index+1<=n-1 && index+2<=n-1)

    {

        return cost[index]=min(abs(arr[index]-arr[index+1])+func(index+1),abs(arr[index]-arr[index+2])+func(index+2));

    }



    else if(index+1<=n-1)

    {

        return cost[index]=abs(arr[index]-arr[index+1])+func(index+1);

    }





}

int main()

{

    optimize();



    cin>>n;

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

    {

        cin>>arr[i];

    }



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



    int res=func(0);

    cout<<res<<endl;

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

using namespace std;

#define ll long long

#define pb push_back

#define mp make_pair

#define ull  unsigned long long

#define vll  vector <long long>

#define pll pair <long long,long long>

#define f first

#define s second

#define up upper_bound

#define lp lower_bound

#define pq priority_queue

#define inf 1e10

#define minf -1e10

#define pi 3.14159265

#define mod 300000000000000000

#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);

int main()

{

    ll n;

    cin>>n;

    vll vec;

    ll ara[100001];

    memset(ara,0,sizeof(ara));

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

    {

        ll num;

        cin>>num;

        vec.pb(num);

    }

    ll ans=0;

    ara[n-2]=abs(vec[n-2]-vec[n-1]);

    for(ll i=n-3;i>=0;i--)

    {

        ara[i]=min(abs(vec[i]-vec[i+1])+ara[i+1],abs(vec[i]-vec[i+2])+ara[i+2]);

    }

    cout<<ara[0]<<endl;

}


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

using namespace std;

#define endl '\n'

#define optimize() ios_base::sync_with_stdio(0);

int n;

int arr[100001];

int cost[100001];



int func(int index)

{

    if(index>=n-1)

        return 0;

    if(cost[index]!=-1)

        return cost[index];





    if(index+1<=n-1 && index+2<=n-1)

    {

        return cost[index]=min(abs(arr[index]-arr[index+1])+func(index+1),abs(arr[index]-arr[index+2])+func(index+2));

    }



    else if(index+1<=n-1)

    {

        return cost[index]=abs(arr[index]-arr[index+1])+func(index+1);

    }





}

int main()

{

    optimize();



    cin>>n;

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

    {

        cin>>arr[i];

    }



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



    int res=func(0);

    cout<<res<<endl;

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

#define INF 0x3f3f3f3f

using namespace std;

const int maxn = 1e6+10;

int a[maxn];

int dp[maxn];

int main()

{

    int n;

    memset(dp,INF,sizeof dp);

    scanf("%d",&n);

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

    {

        scanf("%d",a+i);

    }

    dp[1]=0;

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

    {

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

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

    }

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

    return 0;

}


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

using namespace std;

#define endl '\n'

#define optimize() ios_base::sync_with_stdio(0);

int n;

int arr[100001];

int cost[100001];



int func(int index)

{

    if(index>=n-1)

        return 0;

    if(cost[index]!=-1)

        return cost[index];





    if(index+1<=n-1 && index+2<=n-1)

    {

        return cost[index]=min(abs(arr[index]-arr[index+1])+func(index+1),abs(arr[index]-arr[index+2])+func(index+2));

    }



    else if(index+1<=n-1)

    {

        return cost[index]=abs(arr[index]-arr[index+1])+func(index+1);

    }





}

int main()

{

    optimize();



    cin>>n;

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

    {

        cin>>arr[i];

    }



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



    int res=func(0);

    cout<<res<<endl;

}
// Slower C++ solution:
#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;

}

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

using namespace std;

#define endl '\n'

#define optimize() ios_base::sync_with_stdio(0);

int n;

int arr[100001];

int cost[100001];



int func(int index)

{

    if(index>=n-1)

        return 0;

    if(cost[index]!=-1)

        return cost[index];





    if(index+1<=n-1 && index+2<=n-1)

    {

        return cost[index]=min(abs(arr[index]-arr[index+1])+func(index+1),abs(arr[index]-arr[index+2])+func(index+2));

    }



    else if(index+1<=n-1)

    {

        return cost[index]=abs(arr[index]-arr[index+1])+func(index+1);

    }





}

int main()

{

    optimize();



    cin>>n;

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

    {

        cin>>arr[i];

    }



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



    int res=func(0);

    cout<<res<<endl;

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

#define pb emplace_back

#define ll long long

#define mp make_pair

#define PI acos(-1)

using namespace std;

ll dp[200005],a[200005],n;

ll solve(ll idx)

{

    if(idx>=n-1)

        return 0;

    if(dp[idx]!=-1)

        return dp[idx];

    ll res=INT_MAX;

    if(idx+1<n)

        res=min(res,abs(a[idx+1]-a[idx])+solve(idx+1));

    if(idx+2<n)

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

    return dp[idx]=res;

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    ll i,j,k,x,y,z,m,t,l,r;

    cin>>n;

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

        cin>>a[i];

    memset(dp,-1,sizeof dp);

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

}














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

using namespace std;

#define endl '\n'

#define optimize() ios_base::sync_with_stdio(0);

int n;

int arr[100001];

int cost[100001];



int func(int index)

{

    if(index>=n-1)

        return 0;

    if(cost[index]!=-1)

        return cost[index];





    if(index+1<=n-1 && index+2<=n-1)

    {

        return cost[index]=min(abs(arr[index]-arr[index+1])+func(index+1),abs(arr[index]-arr[index+2])+func(index+2));

    }



    else if(index+1<=n-1)

    {

        return cost[index]=abs(arr[index]-arr[index+1])+func(index+1);

    }





}

int main()

{

    optimize();



    cin>>n;

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

    {

        cin>>arr[i];

    }



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



    int res=func(0);

    cout<<res<<endl;

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

#define fr(i,a,n) for(ll i=a;i<n;i++)

#define YES cout<<"YES"<<endl

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

#define NO cout<<"NO"<<endl

#define pb(x) emplace_back(x)

#define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define vi vector<ll>

#define mi map<ll,ll>

#define pi pair<ll,ll>

#define what(x) cout<<#x<<" ="<<x<<endl;

#define scn(n) scanf("%d",&n)

#define print(a) printf("%d",a);

using namespace std;

using ll =int;

ll n;



ll dp[200005],a[200005]={1000000000};

ll invalid=1e9;

ll cnt=0;

int solve(ll i,ll p)

{ //cnt++;

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

    if(i>=n)return 1e9;

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

    //what(p-a[i]);

    //cout<<i<<" GG "<<i+1<<endl;



    ll x=abs(a[i+1]-a[i])+solve( i+1,a[i]);



   // what(x);



    ll y=abs(a[i+2]-a[i])+solve(i+2,a[i]);

   // cout<<i<<" "<<i+2<<endl;

   //what(x); what(y);

    x=min(x,y);







    return dp[i]=x;



}



int main()

{

    ll t;

    memset(dp,-1,sizeof dp);



    scn(n);

    fr(i,0,n)cin>>a[i];



    solve(0,a[0]);



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

    //what(cnt);

    //fr(i,0,n)cout<<dp[i]<<" ";



}




















































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

using namespace std;

#define endl '\n'

#define optimize() ios_base::sync_with_stdio(0);

int n;

int arr[100001];

int cost[100001];



int func(int index)

{

    if(index>=n-1)

        return 0;

    if(cost[index]!=-1)

        return cost[index];





    if(index+1<=n-1 && index+2<=n-1)

    {

        return cost[index]=min(abs(arr[index]-arr[index+1])+func(index+1),abs(arr[index]-arr[index+2])+func(index+2));

    }



    else if(index+1<=n-1)

    {

        return cost[index]=abs(arr[index]-arr[index+1])+func(index+1);

    }





}

int main()

{

    optimize();



    cin>>n;

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

    {

        cin>>arr[i];

    }



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



    int res=func(0);

    cout<<res<<endl;

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

using namespace std;

int n;

long long dp[100009],ans;

long long arr[100009];

int solve(int idx)

{

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

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

    ans=solve(idx+1)+(abs(arr[idx+1]-arr[idx]));

    if(idx+2<n)

       {

           ans=min(ans,solve(idx+2)+ abs(arr[idx+2]-arr[idx]));

       }

    return dp[idx]=ans;

}

int main()

{

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

    cin>>n;

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

    cout<<solve(0)<<endl;

    return 0;

}


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

using namespace std;

#define endl '\n'

#define optimize() ios_base::sync_with_stdio(0);

int n;

int arr[100001];

int cost[100001];



int func(int index)

{

    if(index>=n-1)

        return 0;

    if(cost[index]!=-1)

        return cost[index];





    if(index+1<=n-1 && index+2<=n-1)

    {

        return cost[index]=min(abs(arr[index]-arr[index+1])+func(index+1),abs(arr[index]-arr[index+2])+func(index+2));

    }



    else if(index+1<=n-1)

    {

        return cost[index]=abs(arr[index]-arr[index+1])+func(index+1);

    }





}

int main()

{

    optimize();



    cin>>n;

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

    {

        cin>>arr[i];

    }



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



    int res=func(0);

    cout<<res<<endl;

}
// Slower C++ solution:
#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;

}


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

using namespace std;

#define endl '\n'

#define optimize() ios_base::sync_with_stdio(0);

int n;

int arr[100001];

int cost[100001];



int func(int index)

{

    if(index>=n-1)

        return 0;

    if(cost[index]!=-1)

        return cost[index];





    if(index+1<=n-1 && index+2<=n-1)

    {

        return cost[index]=min(abs(arr[index]-arr[index+1])+func(index+1),abs(arr[index]-arr[index+2])+func(index+2));

    }



    else if(index+1<=n-1)

    {

        return cost[index]=abs(arr[index]-arr[index+1])+func(index+1);

    }





}

int main()

{

    optimize();



    cin>>n;

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

    {

        cin>>arr[i];

    }



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



    int res=func(0);

    cout<<res<<endl;

}
// Slower C++ solution:
// 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;

}

// Faster C++ solution for the same problem (measured speedup: 2.625940846038161x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.442530183649864x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.7959759493342116x):
#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];

}
// Slower C++ solution:
#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);

}

// Faster C++ solution for the same problem (measured speedup: 1.7955424726771532x):
#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];

}
// Slower C++ solution:
#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;

}
























// Faster C++ solution for the same problem (measured speedup: 1.7910402330546673x):
#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;

}
// Slower C++ solution:
#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);

}








// Faster C++ solution for the same problem (measured speedup: 2.6033900350993187x):
#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;

}