Language: C++

														//"بسم الله الرحمن الرحيم"                         

							//"وأما من امن وعمل صالحا فله جزاء الحسنى وسنقول له من امرنا يسرا"

													 //"tomorrow never will be like today........"
	
										//"Go and try to hack me you are a loooooooser anyway huh *_*........"



#include <iostream>
#include<string>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<cmath>
#include<algorithm>
#include<functional>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
//#include<Bits.h>


#define loop(n) for(int i=0;i<n;i++)
#define cinarr(arr,n) for(int i=0;i<n;i++){cin>>arr[i];}
#define PII pair<int , int>
#define PLL pair<long long,long long>
#define PIS pair<int , string>
#define pb(a) push_back(a)
#define veci vector<int>
#define vecl vector<long long>
#define vecs vector<string>
#define sz(s) int(s.size())
#define p(a) push(a)
#define mkp(a,b) make_pair(a,b)
#define mem2(dp,s1,s2) for(int i = 0 ; i< s1 ; ++i) for(int j = 0 ; j<s2 ; ++j) dp[i][j] = -1;
#define mem3(dp,s1,s2,s3) for(int i = 0 ; i<s1 ; ++i) for(int j = 0 ; j<s2 ; ++j) for(int k = 0 ; k< s3 ; ++k) dp[i][j][k] = -1;
#define fastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const int MX = 2750131+1;

using namespace std;

typedef long long ll;
typedef string str;
typedef double db;
typedef float fl;
typedef int i;
/*

int lst[MX];
int primeIndex[MX];



//if prime lst[i] = i , else lst[i] = greatest divisor.


void sieve()
{

	loop(MX) lst[i] = i;
	for (int i = 2; i < MX; i++)
	{
		if (lst[i] != i)
		{
			// i is the smallest divisor of lst[i]
			lst[i] = i / lst[i]; //gratest divisor.
		}
		else
		{
			for (ll np = i * 1ll * i; np < MX; np += i)
			{
				lst[np] = min(lst[np], i);
			}
		}
	}

	int ind = 1;
	for (int i = 2; i < MX; i++)
	{
		if (lst[i] == i)
			primeIndex[i] = ind++;
	}


}


int find(int i)
{
	if (parent[i] == 0)
		return i;
	return parent[i] = find(parent[i]); // dp memorizing
}

bool Union(int a, int b)
{
	int x = find(a);
	int y = find(b);
	if (x == y)
		return true;
	parent[x] = y;
	return false;
}


bool compare(char p1, char p2)
{
	return p1 > p2;
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a%b);
}


*/
/*
ll OO = 1e9;
int dis[100010];
bool ch[100010];
int n, c, m;
vector< vector<int> > gr;


void dikstra(int src = 1)
{
	priority_queue< pair<int,int>, vector<pair<int,int>> , greater<pair<int,int>> > pq;
	
	pq.p(mkp((int)ch[src], src));
	while (!pq.empty())
	{
		int u = pq.top().second;
		ll w = pq.top().first;
		pq.pop();
		if(w < dis[u])
			dis[u] = w;
		for(auto x : gr[u])
		{
			if (w + (int) ch[x] < dis[x])
				pq.p(mkp(w + (int) ch[x] , x));
		}
	}
}

ll power(ll x, ll y)
{
	ll res = 1;      // Initialize result

	x = x % MOD;  // Update x if it is more than or

	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = (res*x) % MOD;

		// y must be even now
		y = y >> 1; // y = y/2
		x = (x*x) % MOD;
	}
	return res;
}



int arr[100000];
int seg[303000];

void build_SegTree(int l , int r , int pos) // o( n )
{
	if (l == r) { seg[pos] = arr[l]; return; }
	int mid = l + (r - l) / 2;
	build_SegTree(l, mid, 2 * pos + 1);
	build_SegTree(mid+1, r , 2 * pos + 2);
	seg[pos] = (seg[2 * pos + 1] + seg[2 * pos + 2]);
}

int Query(int ql ,int qh ,int l , int r , int pos ) //o( logn )
{
	if (ql <= l && qh >= r) // total overlap
		return seg[pos];
	if (ql > r || qh < l) // no overlap
		return 0;
	int mid = l + (r - l) / 2;
	return  (Query(ql, qh, l, mid, 2 * pos + 1) + Query(ql, qh, mid + 1, r, 2 * pos + 2));
}
*/
const int mx = (int)1e5 + 2;
ll memo[mx];
ll heights[mx];
int n;
ll OO = (ll)1e18;
ll minH( int i)
{
	if (i > n)
		return OO;
	if (i == n)
		return 0;
	ll &ret = memo[i];
	if (ret != -1) return ret;
	ret = OO;
	ret = min(ret, abs(heights[i] - heights[i + 1]) + minH(i + 1));
	ret = min(ret, abs(heights[i] - heights[i + 2]) + minH(i + 2));
	return ret;
}

int main()
{
	fastIO;
	memset(memo, -1, sizeof(memo));
	cin >> n;
	loop(n) cin >> heights[i+1];
	cout << minH(1)<<endl;
	
}



Compiler output:
a.cc: In function 'int main()':
a.cc:221:9: error: 'memset' was not declared in this scope
  221 |         memset(memo, -1, sizeof(memo));
      |         ^~~~~~
a.cc:27:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   26 | #include<math.h>
  +++ |+#include <cstring>
   27 | //#include<Bits.h>