#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <algorithm>  // std::unique
#include <cmath>
#include <limits.h>
#include <queue>
#include <unordered_map>
#include <sstream>      // std::ostringstream
#include <bitset>
#include <iomanip>
#include <functional>
#include <set>


#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

using ll = long long;
constexpr auto PrimeBigNum10_9_7 = 1000000007;
const long long INF = 1LL << 60;

#define OUTPUT_DEBUG_LOG

template <typename T>
void DisplayAnswer(const T& v) {
	cout << v << endl;
}
template <typename T>
void DisplayAnswers(const vector<T>& vs) {
	for (const auto& v : vs) {
		cout << v << endl;
	}
}

template <typename T>
void DisplayAnswerOneLine(const vector<T>& vs) {
	for (const auto& v : vs) {
		cout << v << ' ';
	}
	cout << endl;
}


std::vector<std::string> split(const std::string &str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}



template<class T>
void chmin(T& a, T b) {
	if (a > b) {
		a = b;
	}
}


// 素数判定
template <typename T>
bool IsPrimeNumber(T value) {

	for (int i = 2; i * i <= value; ++i) {
		if ((value % i) == 0) {
			return true;
		}
	}
	return false;
}

// 桁数判定
template <typename T>
T GetFigureLength(T value) {
	T figure = 1;
	while (value >= 10) {
		value /= 10;
		++figure;
	}
	return figure;
}

// 素因数分解結果
template <typename T>
map<T, T> GetPrimeFactorize(T value) {

	map<T, T> res;

	for (T i = 2; i * i <= value; ++i) {
		if ((value%i) != 0)	continue;

		T count = 0;
		while ((value % i) == 0) {
			value /= i;
			++count;
		}

		res[i] = count;
	}

	if (value != 1) {
		res[value] = 1;
	}
	return res;
}


void DebugPrint(const vector<ll>& vec) {
	cout << "{";
	for (auto itr = vec.begin(); itr != vec.end(); ++itr) {
		cout << *itr << ",";
	}
	cout << "}" << endl;
}

// valueが2のx乗以下である計算
ll calc2x(ll value) {
	ll n = 0;
	while (value > 0) {
		value /= 2;
		++n;
	}
	return n;
}



struct Vec2 {
	double x;
	double y;

	void rotate(double rad) {
		double s = sin(rad);
		double c = cos(rad);
		double tmpX = this->x*c - this->y*s;
		double tmpY = this->x*s + this->y*c;
		this->x = tmpX;
		this->y = tmpY;
	}
};

void funcA() {

	ll N;
	cin >> N;
	DisplayAnswer(N + N * N + N * N*N);
}

void funcB() {
	string str1, str2;
	cin >> str1 >> str2;

	ll count = 0;
	for (ll i = 0; i < str1.size(); ++i) {
		if (str1[i] != str2[i]) {
			count++;
		}
	}
	DisplayAnswer(count);
}

void funcC() {
	ll N, M, K;
	cin >> N >> M >> K;
	queue<ll> aBooks;
	for (ll i = 0; i < N; ++i) {
		ll n;
		cin >> n;
		aBooks.push(n);
	}
	queue<ll> bBooks;
	for (ll i = 0; i < M; ++i) {
		ll n;
		cin >> n;
		bBooks.push(n);
	}

	ll sum = 0;
	ll bookCount = 0;

	while(1){
		ll s = sum;
		if (aBooks.empty()&&bBooks.empty())	break;

		if (aBooks.empty()) {
			s += bBooks.front();
			bBooks.pop();
		}
		else if (bBooks.empty()) {
			s += aBooks.front();
			aBooks.pop();
		}
		else if (aBooks.front() <= bBooks.front()) {
			s += aBooks.front();
			aBooks.pop();
		}
		else {
			s += bBooks.front();
			bBooks.pop();
		}
		if (s > K) {
			break;
		}
		sum = s;
		bookCount++;
	};

	DisplayAnswer(bookCount);
}

void funcD() {

	ll N;
	cin >> N;

	ll ans = 0;

	vector<map<ll,ll>> divisors(N+1);
	for (ll v = 1; v <= N; ++v){

		/*
		auto map = GetPrimeFactorize(i);
		
		ll count = 1;
		for (auto& m : map) {
			count *= m.second + 1;
		}
		*/

		v = 100;

		/*auto value = v;
		ll count = 1;
		for (ll i = 2; i * i <= value; ++i) {
			if ((value%i) != 0)	continue;

			ll c = 0;
			while ((value % i) == 0) {
				value /= i;
				++c;
			}
			count *= c + 1;
		}
		if (value != 1) {
			count *= 2;
		}*/

		{
			auto value = v;
			map<ll, ll> res;

			for (ll i = 2; i * i <= value; ++i) {
				if ((value%i) != 0)	continue;

				ll count = 0;
				while ((value % i) == 0) {
					value /= i;
					++count;
				}

				res[i] = count;
			}

			if (value != 1) {
				res[value] = 1;
			}
		}

		ll a = 0;

		for (ll i = 0; i < divisors.size(); ++ i ) {

		}
		//DisplayAnswer(count);
		ans += v * a;
	}
	DisplayAnswer(ans);

}

void funcFrog() {
	ll N;
	cin >> N;
	vector<ll> h(N);
	for (ll i = 0; i < N; ++i) {
		cin >> h[i];
	}
	vector<ll> dp(N,INF);

	dp[0] = 0;
	for (ll 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]));
		}
	}

	DisplayAnswer(dp[N - 1]);

}
void funcFrogB() {
	ll N;
	cin >> N;
	vector<ll> h(N);
	for (ll i = 0; i < N; ++i) {
		cin >> h[i];
	}
	vector<ll> dp(N, INF);

	dp[0] = 0;
	for (ll i = 1; i < N; ++i) {

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

		if (i > 1)
		{
			auto d = dp[i - 2] + abs(h[i] - h[i - 2]);
			if ((dp[i] > d)) {
				dp[i] = d;
			}
		}
	}

	DisplayAnswer(dp[N - 1]);

}
int main(void) {

	funcFrog();

	return 0;
}


Measured memory_bytes: 4848