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

#include <vector>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <set>

#include <tuple>

#include <functional>

#include <map>

#include <unordered_map>

#include <queue>

#include <tuple>



using namespace std;



#define endl '\n'



using ull = unsigned long int;

using ll = long long;



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(nullptr);

  const int precision = 13;

  cout.precision(precision);

  cout.setf(ios_base::fixed);



  int n; cin >> n;

  vector<ll> s(3), dp(3);



  cin >> s[1];

  cin >> s[2];



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



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

    cin >> s[i%3];

    dp[i%3] = min(dp[(i-1)%3] + abs(s[(i-1)%3] - s[i%3]), dp[(i-2)%3] + abs(s[i%3] - s[(i-2)%3]));

  }



  cout << dp[n%3] << endl;



  return 0;

}


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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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 <cstdio>

#include <cstdint>

#include <cinttypes>

#include <algorithm>

#include <cstring>



using i32 = std::int_fast32_t;

using i64 = std::int_fast64_t;



inline i32 diff(i32 x, i32 y) {

	return x > y ? x - y : y - x;

}



const int MaxN = 100001;



i32 A[MaxN], dp[MaxN];



signed main(signed argc, char **argv) {

	i32 n;

	scanf("%" SCNdFAST32, &n);



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

		scanf("%" SCNdFAST32, A + i);

	}



	memset(dp, 0x3f, sizeof dp);



	dp[0] = 0;

	dp[1] = diff(A[0], A[1]);

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

		dp[i] = std::min(dp[i - 1] + diff(A[i], A[i - 1]), dp[i - 2] + diff(A[i], A[i - 2]));

	}



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

	return 0;

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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 <cstring>

#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

#include <sstream>

#include <queue>

#include <deque>

#include <bitset>

#include <iterator>

#include <list>

#include <stack>

#include <map>

#include <set>

#include <functional>

#include <numeric>

#include <utility>



#include <cmath>

#include <iomanip>



using namespace std;



int main()

{

  ios::sync_with_stdio(false);

  cin.tie(0);

  int n;

  cin >> n;

  int h[n];

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

    int cur;

    cin >> cur;

    h[i] = cur;

  }

  int minCosts[n];

  minCosts[0] = 0;

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

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

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

  }

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

  return 0;

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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

using namespace std;



//int cnt[26],cnt1[26];

int dp[100005];

int main(){

	int n;

	cin>>n;

	int ar[n];

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

		cin>>ar[i];

	}

	dp[0]=0;

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

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

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

	}

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

	return 0;

}


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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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 vector<int> vi;

typedef vector<long long> vll;

typedef pair<int,int> pii;

typedef vector< pii > vii;



#define ll          long long

#define ff          first

#define ss          second

#define pb          push_back

#define mkp         make_pair

#define sz          size()



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

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

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

#define mem(a,b)    memset(a,b,sizeof(a))

#define pi          2*acos(0.0)

#define End         return 0;

#define nl endl



#define scan1(a)    scanf("%d",&a)

#define scan2(a,b)  scanf("%d %d",&a,&b)

#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)

#define scanl(a)    scanf("%lld",&a)

#define scanll(a,b) scanf("%lld %lld",&a,&b)

#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)



#define print1(a)    printf("%d",a)

#define print2(a,b)  printf("%d %d",a,b)

#define print3(a,b,c)  printf("%d %d %d",a,b,c)

#define printl(a)    printf("%lld",a)

#define printll(a,b) printf("%lld %lld",a,b)

#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)



#define MAXN        100000007

#define INF 0x3f3f3f3f

int main()

{

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

   int n;

   cin>>n;

   vll v(n+3),vv(n+3);

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



   vv[1]=0;vv[2]=abs(v[2]-v[1]);

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

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

   }

   cout<<vv[n]<<endl;

   return 0;

}


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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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 arr[100010];

int dp[100010];



int main (){

	int n;

	cin >> n;

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

		cin >> arr[i];

	}

	dp[1] = 0;

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

	

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

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

	}

	

	cout << dp[n] << endl;

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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 n,h[100005],c[100005];



int main()

{

    cin>>n;

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

        cin>>h[i];

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

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

    {

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

    }

    cout<<c[n-1];

}


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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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;

long long n,h[100010],dp[100010];



int main()

{

	scanf("%lld",&n);

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

	{

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

	}

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

	{

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

		if(i>2)

		{

			

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

		}

	}

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

	return 0;

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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 db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'

const int N = 1e5;

const int inf = 1e9;

int A[N+7], dp[N+7];

int n;



int solve(int i) {

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

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

	int res1 = solve(i+1) + abs(A[i]-A[i+1]);

	int res2 = inf;

	if(i+2<=n-1) res2 = solve(i+2)+abs(A[i]-A[i+2]);

	return dp[i] = min(res1, res2);

}

int main(){

	ios_base::sync_with_stdio(0);

	int a,b,T,cas=0;

	cin>>n;

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

	fill(dp,dp+n,-1);

	int res=solve(0);

	cout<<res<<endl;

	return 0;

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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 ull unsigned ll

#define ld long double

#define pll pair<ll, ll>

#define pii pair<int, int>

#define f first

#define se second

#define pb push_back

#define ft fflush(stdout)

 

 

using namespace std;

 

 

const int N = 2e5 + 123;

const int PLS = 3e5 + 123;

const int mod = 1e9 + 7;

const ll inf = 1e16;





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





int main() {

    ios_base::sync_with_stdio(NULL);

    cin.tie(NULL); cout.tie(NULL);

    cin >> n;

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

        cin >> a[i];

    dp[1] = 0;

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

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

    cout << dp[n];

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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 target("avx2")

//#pragma GCC optimize("O3")

   

//#include <x86intrin.h>

#include <bits/stdc++.h>   

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

 

using namespace __gnu_pbds;

using namespace std;



template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

     

#define F first

#define S second           

#define lb lower_bound               

#define ub upper_bound

#define pb push_back

#define pf push_front    

#define ppb pop_back

#define mp make_pair                                     

#define bpp __builtin_popcountll                                                                                        

#define sqr(x) ((x) * (x)) 

#define al 0x3F3F3F3F

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

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

#define in insert

#define ppf pop_front

#define endl '\n'

//#define int long long

 

typedef unsigned long long ull;

typedef long long ll;

typedef long double ld;

typedef pair <int, int> pii;

 

const int mod = (int)1e9 + 7;

const int N = (int)3e5 + 123;

const ll inf = (ll)1e18 + 1;



const double pi = acos (-1.0);

const double eps = 1e-7;                  

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

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



int n;

ll h[N];

ll dp[N];



inline void boost () {                    

   ios_base :: sync_with_stdio (NULL);

   cin.tie (NULL), cout.tie (NULL);          

}                                                     



inline void Solve () {

   cin >> n;

   dp[1] = 0;

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

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

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

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

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

   }

   cout << dp[n];

}



main () {                                       

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

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

   boost ();

   int tt = 1;

   //cin >> tt;   

   while (tt --) {

      Solve ();

   }                                               

   return 0;      

}

                          

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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 maxn 100000

    #define INF 1LL<<60

    using namespace std;

    long long h[maxn+3], dp[maxn+3];

    int n;



    long long solve(int cur){

        if(cur >= n) return INF;

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

        if(dp[cur]!= INF) return dp[cur];

        //long long res1 = INF, res2 = INF;

        long long res1 = solve(cur+1) + llabs(h[cur+1]-h[cur]);

        long long res2 = solve(cur+2) + llabs(h[cur+2]-h[cur]);

        return dp[cur] = min(res1, res2); 

    }



    int main() {

    	// your code goes here

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

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

            

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

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

                dp[i] = INF;

            }



            long long ans = solve(0);

            printf("%lld\n", ans);

        }

    }

     

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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<cmath>

#include<cstdio>

#include<cstring>

using namespace std;

int n,m,f[1100000],w[1100000];

int main ()

{

	cin>>n;

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

	{

		cin>>w[i];

	}

	f[2]=abs(w[2]-w[1]);

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

	{

		f[i]=min(f[i-1]+abs(w[i]-w[i-1]),f[i-2]+abs(w[i]-w[i-2]));

	}	

	cout<<f[n];

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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 <algorithm>

#include <cmath>

#include <cstdlib>

#include <cstdio>

#include <cstring>

#include <iomanip>

#include <string>

#include <set>

#include <vector>

#include <queue>

#include <stack>

#include <map>

using namespace std;

#define ms(a, x) memset(a, x, sizeof(a))

#define fore(i, a, n) for (long long i = a; i < n; i++)

#define ford(i, a, n) for (long long i = n - 1; i >= a; i--)

#define si(a) scanf("%d", &a)

#define sl(a) scanf("%lld", &a)

#define sii(a, b) scanf("%d%d", &a, &b)

#define sll(a, b) scanf("%lld%lld", &a, &b)

#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)

#define debug(a) cout << a << endl

#define pr(a) printf("%d ",a)

#define endl '\n'

#define pi acos(-1.0)

#define tr t[root]

#define lson t[root << 1]

#define rson t[root << 1 | 1]

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

#define ull unsigned long long

const double eps = 1e-8;

inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }

typedef long long ll;

const int inf=0x3f3f3f3f;

const int MAXN = 1e5 + 10;

int n,a[MAXN];

ll dp[MAXN];

int main()

{

	si(n);

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

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

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

 } 

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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 pb push_back

#define F first

#define S second

const int mod = 1e9+7, A = 1e5+5;

ll n, k, h[A], dp[A];

ll table1()

{

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

	return dp[n-1];

}

ll table2()

{

	dp[0] = 0;

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

	{

		dp[i] = 1e9;

		for (int j = max(0, i - (int)k); j < i; j++)

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

	}

	return dp[n-1];

}

int main()

{

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

	cin >> n;

	//cin >> k;

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

	cout << table1();

	//cout << table2();

	return 0;

}


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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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<vector>

using namespace std;

 

int dp[100010];

int n;

int conti;

bool pasa;

int main(){

     cin >> n;

    vector<int> h(n);

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

        conti ++;

        cin >> h[i];

        if(conti > 0){

        conti--;

        pasa = true;

       //printf("prueba")

}

    }

    dp[0] = 0;

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

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

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

    }

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

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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 <vector>

#include <cmath>

#include <map>

#include<algorithm>

#include<string.h>

using namespace std;

int main() {

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

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

   	int n;

   	cin>>n;

   	int a[100000];

   	int b[100000];

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

   		cin>>a[i];

   	b[0]=0;

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

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

   	{

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

	}

	cout<<b[n-1];

}

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

#include <math.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];

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

    {

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

    }

    dp[0] = 0;

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

    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: