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

using namespace std;



#define MAXN 100003



int abs(int z)

{

    if (z<0)

        return -z;

    else

        return z;

}



int main(void)

{

    int N,i,j;

    int h[MAXN], p[MAXN];

    scanf("%d",&N);

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

    {

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

    }

    p[N-1]=0;

    p[N-2]=abs(h[N-2]-h[N-1]);

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

    {

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

    }

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



    return 0;

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

        scanf("%d", &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]));

    }

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

}

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

#include <vector>

#include <string>

#include <cmath>

#include <set>

#include <stdio.h>

#include <algorithm>

#include <map>

#include <queue>

#include <unordered_map>

#define ll long long

#define pii pair <int, int>

#define pll pair <long long, long long>

#define plxy pair <long long, pll>

#define INT_MAX 1e18

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

using namespace std;

using namespace std;

const int mod=1e9+7;

const int N=1e5+5;

ll dp[N];

int main()

{

    ll n,arr[N];

    cin>>n;

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

        cin>>arr[i];

    dp[0]=0;

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

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

    {

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

    }

    cout<<dp[n-1];

    return 0;

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

        scanf("%d", &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]));

    }

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

}

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

using namespace std;

int main()

{

    int n;

    cin>>n;

    int arr[n];

    long long dp[n];

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

   {

        cin>>arr[i];

   }

   dp[0]=0;

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

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

   {

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

   }

   cout<<dp[n-1];

   return 0;

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

        scanf("%d", &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]));

    }

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

}

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

using namespace std;

typedef long long ll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)

#define x first

#define y second





int main() {

    fast;

    int n;

    cin>>n;

    vector<int> arr(n);

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

        cin>>arr[i];

    }

    vector<int> dp(n);

    dp[0] = 0;

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

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

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

    }

    cout<<dp[n-1];

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

        scanf("%d", &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]));

    }

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

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#pragma GCC optimize("O3")



#include <bits/stdc++.h>



typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

#define F first

#define S second

#define pii pair<int,int>

#define pll pair<ll, ll>

#define vi vector<int>

#define vll vector<ll>

#define vii vector<pii>

#define read(FILE)  freopen(FILE, "r", stdin);

#define out(FILE) freopen(FILE, "w", stdout);

#define clr(x, y) memset(x,y,sizeof(x));

#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);

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

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

#define forr(i, m, n) for(int i=m ; i<=n ; i++)

#define endl '\n'

#define pb push_back

#define re return

const int N = 1e5 + 5;

const ll OO = 2e8;

using namespace std;



int n, cost[N], dp[N],res=0;



bool valid(int i) {

    re i < n;

}



int main() {

    //IO;

    cin >> n;

    rep(i, 0, n) cin >> cost[i];

    //memset(dp,OO, sizeof(dp));

    dp[0] = 0;

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

    rep(i,2,n){

        int next=OO,nextawy=OO;

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

        nextawy=dp[i-2]+abs(cost[i-2]-cost[i]);

        dp[i]=min(next,nextawy);

        //cout<<dp[i]<<" ";

    }

    //n--;

    cout<<dp[n-1];

    //cout<<endl;





}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

        scanf("%d", &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]));

    }

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

}

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



#define ll long long

#define lp(i,n) for(int i=0; i<n; i++)

#define pb push_back

const long double pi=3.141592654;

#define OSOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;



const ll inf = 1e9 +5, mod = 1e9+7,N = 1e5+5;





int main()

{

    OSOS

	int n;

    cin>>n;

    int arr[n];

    lp(i,n)cin>>arr[i];

    int dp[n];

    dp[0] = 0;

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

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

    {

    	ll o1,o2;

    	o1 = dp[i-2]+abs(arr[i-2]-arr[i]);

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

    	dp[i] = min(o1,o2);

    }

    cout<<dp[n-1];

}




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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

        scanf("%d", &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]));

    }

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

}

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



using namespace std;



int v[100007];

int main() {

int n; cin >> n;

vector<int> dp(n+1);

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

dp[n] = 0;

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

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

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

}



cout << dp[1] << endl;

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

        scanf("%d", &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]));

    }

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

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define f(i,s,v) for(int i=(int)s;i<(int)v;++i)

#define rf(i,s,v) for(int i=(int)s-1;i>(int)v;--i)

#include<bits/stdc++.h>

typedef long long ll;

using namespace std;

const ll oo=1e15;

int n;

int a[100005];

bool calculated[100005];

ll value[100005];

ll solve(int idx){

    if(idx>=n) return oo;

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

    if(calculated[idx]) return value[idx];

    ll best=oo;

    f(i,1,3)

        best=min(best,solve(idx+i)+abs(a[idx+i]-a[idx]));

    calculated[idx]=true;

    value[idx]=best;

    return best;

}

int main()

{

    scanf("%d",&n);

    f(i,0,n)

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

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

    return 0;

}


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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

        scanf("%d", &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]));

    }

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

}

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

#include<bits/stdc++.h>

#include<string>

#include<vector>

#include<stack>

#include<cstdio>

#include <algorithm>

using namespace std;

int abs(int x)

{

	return x>0?x:-x;

}

int main()

{

    int n;

    cin>>n;

    int* dp=new int[n+1];

    int* h=new int[n+1];

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

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

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

    {

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

	}

    cout<<dp[n]<<endl;

	return 0;

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

        scanf("%d", &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]));

    }

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

}

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

#include <cstdio>

#include <queue>

#include <vector>

#include <cmath>

using namespace std;



int height[100003];



int dp[100003];



int JumpFrog(int N){

    dp[1]=0;

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

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

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

    }

    return dp[N];

}



int main()

{

    int N;

    while(cin>>N){

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

            cin>>height[i];

        }

        cout<<JumpFrog(N)<<endl;

    }



    return 0;

}

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

#include <stdlib.h>



int min(int a, int b)

{

    return a < b ? a : b;

}

int main()

{

    int n;

    scanf("%d", &n);

    int a[n];

    int dp[n];

    dp[0] = 0;

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

    {

        scanf("%d", &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]));

    }

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

}

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

using namespace std;

#define ll long long

#define ull unsigned long long

#define PII pair<int,int>

#define PSI pair<string,int>

#define PIII pair< int, pair<int,int> >

const int MXN = 1e5;

int a[MXN+5], dp[MXN+5];

int N,K;



int rec(int pos){



    if(pos==N) return 0;

    if(pos>=N) return 1<<30;

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

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

}



void solve(){



    cin>>N;

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

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

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

}



int main(){



    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    solve();

}


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

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

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

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


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

using namespace std;



int n;

int h[100005];

int dp[100005];



int solve(int x){

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

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

    else if (x == n-2){

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

    }

    else {

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

    }

}



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

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cin >> n;

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

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

        cin >> h[i];

    }

    cout << solve(0) << endl;

    return 0;

}

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

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

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

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


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

#define inf INFINITY

#define file freopen( "input.txt" , "r" , stdin) ; freopen( "output.txt" , "w" , stdout) ;

#define Gamed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define _3102_ main()

#define endl '\n'

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

using namespace std;

const int N = 1e5 + 100;

const ll MX = 1e9;

const ll mod = 1e9 + 7;

const double eps = 1e-9 ;



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

ll solve( int i ){

	if ( i < 0 ) return 0 ;

	ll &ret = dp[i] ;

	if ( ~ret ) return ret ;

	if ( i == 0 ) return ret = 0 ;

	if ( i == 1 ) return ret = abs( h[1] - h[0]) ; 

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

}



int _3102_{

	Gamed

	cin >> n ;

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

		cin >> h[i] ;

	}

	memset ( dp , -1 , sizeof dp ) ;

	cout << solve ( n - 1 ) ;



	return 0;

}


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

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

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

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


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



#define fst first

#define snd second

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

#define pb push_back

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

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

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

#define DBG(x) cerr <<#x << " = " << (x) << "\n"



#define SQR(x) ((x) * (x))



#define PI 3.1415926535897932385

#define INF 1000111222

#define eps 1e-7

#define maxN 11



using namespace std;



typedef long long ll;

typedef vector<ll> vll;

typedef pair<ll,ll> pll;

typedef pair<int,int> pii;

typedef vector<string> vstr;

typedef vector<vll> vvll;

typedef vector<bool> vbool;

typedef vector<pll> vpll;

typedef vector<vpll> vvpll;

typedef vector<vbool> vvbool;



vll ns,dp;

ll n;



ll solve(ll pos){

	ll & d = dp[pos];

	if(d != -1) return d;

	ll v=INF;

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

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

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

	return d = v;

}



int main(){FIN

	

	cin >> n;

	ns.resize(n);

	dp.assign(100010,-1);

	fore(i,0,n)cin >> ns[i];

	

	solve(0);

	

	cout << dp[0] << "\n";



	return 0;

}


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

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

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

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


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

using namespace std;



#define fi first

#define se second

#define pb push_back

#define dbg(x) cout << #x << " = " << x << endl

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



typedef long long ll;

typedef long double ld;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<pii> vii;



const int MAX = 1e5;

const int INF = 1e9;

vi stone(MAX + 5);

vi dp(MAX + 5, -1);

int n;



int sol(int i){

    if(i >= n) return INF;

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

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

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

    if(i + 2 < n){

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

    }

    return dp[i];

}



int main(){

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    #ifdef LOCAL

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

    #else

        #define endl '\n'

    #endif

    cin >> n;

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

        cin >> stone[i];

    cout << sol(0) << endl;

    return 0;

}

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

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

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

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


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

using namespace std;

//-------------------------------------------MACROS---------------------------------------------

#define 	TIEMPO_CORRIDA		cerr << "tiempo: "<<1.0*clock()/CLOCKS_PER_SEC <<" seg.\n";

#define 	FILES				freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);

#define 	FORIT(it,e)			for(it = e.begin() ; it != e.end() ; it++)

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

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

#define 	FORSW(i,a,b,sw)		for(i = a ; i < b && sw ; i++)

#define 	RFORSW(i,a,b,sw)	for(i = a ; i >= b && sw ; i--)

#define 	fast 				ios::sync_with_stdio(false),cin.tie(),cout.tie();

#define 	to_int(x) 			atoi(x.data())

#define 	to_long(x) 			atoll(x.data())

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

#define 	RALL(x) 			x.rbegin(),x.rend()

typedef 	long long 			ll;

typedef 	pair<int,int> 		pi;

typedef 	pair<ll,ll> 		pl;

const		int 				modN = 1e9+7;

const		double 				PI = 3.1415926535897932384626433832795028841;

//---------------------------------------------------------------------------------------------

const int tam = 6e5;

const int oo=1e9;

int ar[tam],memo[tam];

int n;



int f(int x){

	if (memo[x]!=-1) return memo[x];

	if(x == n-1) return memo[x]=0;

	int a=oo , b=oo;

	if(x+1 <n) a = f(x+1) + abs(ar[x+1]-ar[x]); 

	if(x+2 <n) b = f(x+2) + abs(ar[x+2]-ar[x]);

	return memo[x]=min(a,b);

}



int main(){

	int i;

	while(scanf("%d",&n)==1){

		memset(memo,-1,sizeof memo);

		FOR(i,0,n) scanf("%d",&ar[i]);

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

	}

	return 0;

}

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

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

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

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


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

using namespace std ;

//priority_queue<int,vector<int>,greater<int> >x ;

int h[100008] , dp[100008] ;

int main(){

    int n ;

    cin >> n ;

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

        cin >> h[i] ;

    }

    

    dp[0]=0 ;

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

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

}

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

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

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

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


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

using namespace std;

typedef long long int ll;



ll mini(ll a, ll b){

    return (a<b)? a : b;

}





int main(){

    ll n; cin>> n;

    ll a[n], b[n]={0};

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

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

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

        b[i]=mini(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]));

    }

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

}


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

#include<cstdio>

#include<algorithm>



int main(){

  int s;

  long long st[100001],p[100001];

  scanf("%d",&s);

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

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

  }

  p[0]=0;

  p[1]=0;

  p[2]=(st[2]-st[1] < 0) ? st[1]-st[2] : st[2]-st[1];

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

    p[i] = std::min(p[i-1] + ((st[i]-st[i-1] < 0) ? st[i-1]-st[i] : st[i]-st[i-1]) , p[i-2] + ((st[i]-st[i-2] < 0) ? st[i-2]-st[i] : st[i]-st[i-2]));

  }

  printf("%lld\n",p[s]);

  return 0;

}


// Fastest known solution for this problem: