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

 

using namespace std;

 

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

#define pd(n) printf("%.12lf", n)

#define pf(n) printf("%d", n)

#define p() printf("\n")

#define ps() printf(" ")

#define ll long long

#define ull unsigned long long

#define MAX 1e9

const int mod = 1000 * 1000 * 1000 + 7;

#define ex 1e18

#define dbl 2e09

#define qu(q) queue<int> q

#define pqu(q) priority_queue<int> q

#define len(s) s.length()

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

#define pb(x) push_back(x)

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

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

#define F first

#define S second

#define clr(x) x.clear()

#define LOG(x) std::cout << x << std::endl;

 

const int INF = 0x3f3f3f3f;

const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

const double PI = 3.14159265359;

 

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

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



int a[100005];

int dp[100005];

int n;

int solve(int idx){

    if(idx==(n-1))

        return 0;

    if(idx>=n)

        return INF;

    int &ret = dp[idx];

    if(~ret)

        return ret;

    ret = INF;

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

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

    return ret;

}







int main(){



    cin>>n;

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

        cin>>a[i];

    }

    memset(dp,-1,sizeof dp);

    cout<<solve(0)<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3772158730575954x):
/*

██╗  ██╗ █████╗ ██████╗ ███████╗███████╗███╗   ███╗        ██╗  ██╗██╗  ██╗ █████╗ ██╗     ███████╗██████╗

██║ ██╔╝██╔══██╗██╔══██╗██╔════╝██╔════╝████╗ ████║        ██║ ██╔╝██║  ██║██╔══██╗██║     ██╔════╝██╔══██╗

█████╔╝ ███████║██████╔╝█████╗  █████╗  ██╔████╔██║        █████╔╝ ███████║███████║██║     █████╗  ██║  ██║

██╔═██╗ ██╔══██║██╔══██╗██╔══╝  ██╔══╝  ██║╚██╔╝██║        ██╔═██╗ ██╔══██║██╔══██║██║     ██╔══╝  ██║  ██║

██║  ██╗██║  ██║██║  ██║███████╗███████╗██║ ╚═╝ ██║███████╗██║  ██╗██║  ██║██║  ██║███████╗███████╗██████╔╝

╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═════╝

Believe in yourself ,( try and try and then try ), You can do it  

*/

#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

#include<unordered_map>

#define endl "\n"

#define Ceil(x,y) ((x+y-1)/y)

#define clr(arr, x) memset(arr, x, sizeof arr)

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

#define allr(s) s.rbegin(),s.rend()

#define rt(s) return cout<<s,0

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

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

#define OO 0x3f3f3f3f3f3f3f3fLL

const int oo = 0x3f3f3f3f, mod = 1e9 + 7;

using namespace std;

typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;

//x = xDegrees*3.14159265 / 180;

//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);

//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));

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

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

void K_K(){

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

}

ll gcd(ll a, ll b) {

	return b == 0 ? abs(a) : gcd(b, a % b);

}

ll lcm(ll a, ll b) {

	return a / gcd(a, b) * b;

}

int n;

vector<int>arr;

map < pair<int, int>, int > dp;

int sol(int idx, int cur){

	if (idx >= n){

		if (cur == arr[n - 1])

			return 0;

		return oo;

	}

	if (dp.find({ idx, cur }) != dp.end())

		return dp[{idx, cur}];

	int ch1 = sol(idx + 1, arr[idx]) + abs(cur - arr[idx]);

	int ch2 = sol(idx + 2, arr[idx]) + abs(cur - arr[idx]);

	return dp[{idx, cur}] = min(ch1, ch2);

}

int main(){

	K_K();

	cin >> n;

	arr.resize(n);

	for (auto &it : arr)

		cin >> it;

	cout << sol(0, arr[0]);

}