#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>order_set;
typedef pair<int, int>pr;
#define all(i) i.begin() , i.end()
#define ft first
#define sn second
#define pb push_back
#define totalone(mask) __builtin_popcount(mask)
#define chkbit(mask,bit) (mask&(1LL << bit))
// debug section start
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// debug section closed
#define en "\n"
#define sum(n) ((1LL*(n)*(n+1))/ 2LL)
#define sqr(n) (1LL*(n)*(n))
#define vag(a,b) ((a + b - 1)/b)
#define MAXN 100010
#define inf 1e6+5
const int mod = 1e9 + 7;
ll n;
ll a[MAXN];
ll mem[MAXN][2];
ll add(ll x, ll y)
{
return abs(x - y);
}
ll f(ll i, ll st)
{
if (i == n - 1) {
if (st == 0) {
return 0;
}
return add(a[i], a[i - 1]);
}
if (mem[i][st] != -1) return mem[i][st];
ll an = 1e18;
if (st == 0) {
if (i + 1 < n)
an = min(an, add(a[i], a[i + 1]) + f(i + 1, 0));
if (i + 2 < n)
an = min(an, add(a[i], a[i + 2]) + f(i + 2, 1));
}
else {
// 0 2 1 3
if (i + 1 < n)
an = min(an, add(a[i], a[i - 1]) + add(a[i + 1], a[i - 1]) + f(i + 1, 0));
if (i + 2 < n)
an = min(an, add(a[i], a[i - 1]) + add(a[i + 2], a[i - 1]) + f(i + 2, 1));
}
return mem[i][st] = an;
}
void solve()
{
cin >> n;
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
if (n == 1) {
cout << 0 << en; return;
}
memset(mem, -1, sizeof(mem));
ll an = f(0, 0);
an = min(an, f(1, 1));
cout << an << en;
}
int main()
{
IOS;
ll t;
t = 1;
// cin >> t;
int c = 0;
while ( t-- )
{
// cout << "Case " << ++c << ": ";
solve();
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbG9uZyBsb25nIGludCBsbDsKI2RlZmluZSBJT1MgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsgIGNpbi50aWUoMCk7IGNvdXQudGllKDApOwoKI2luY2x1ZGUgPGV4dC9wYl9kcy9hc3NvY19jb250YWluZXIuaHBwPgojaW5jbHVkZSA8ZXh0L3BiX2RzL3RyZWVfcG9saWN5LmhwcD4KdXNpbmcgbmFtZXNwYWNlIF9fZ251X3BiZHM7Cgp0eXBlZGVmIHRyZWU8aW50LCBudWxsX3R5cGUsIGxlc3M8aW50PiwgcmJfdHJlZV90YWcsIHRyZWVfb3JkZXJfc3RhdGlzdGljc19ub2RlX3VwZGF0ZT5vcmRlcl9zZXQ7CnR5cGVkZWYgcGFpcjxpbnQsIGludD5wcjsKI2RlZmluZSBhbGwoaSkgICAgIGkuYmVnaW4oKSAsIGkuZ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AgIGlmIChpID09IG4gLSAxKSB7CiAgICAgICAgaWYgKHN0ID09IDApIHsKICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIHJldHVybiBhZGQoYVtpXSwgYVtpIC0gMV0pOwogICAgfQogICAgaWYgKG1lbVtpXVtzdF0gIT0gLTEpIHJldHVybiBtZW1baV1bc3RdOwogICAgbGwgYW4gPSAxZTE4OwogICAgaWYgKHN0ID09IDApIHsKICAgICAgICBpZiAoaSArIDEgPCBuKQogICAgICAgICAgICBhbiA9IG1pbihhbiwgYWRkKGFbaV0sIGFbaSArIDFdKSArIGYoaSArIDEsIDApKTsKICAgICAgICBpZiAoaSArIDIgPCBuKQogICAgICAgICAgICBhbiA9IG1pbihhbiwgYWRkKGFbaV0sIGFbaSArIDJdKSArIGYoaSArIDIsIDEpKTsKICAgIH0KICAgIGVsc2UgewogICAgICAgIC8vIDAgMiAxIDMKICAgICAgICBpZiAoaSArIDEgPCBuKQogICAgICAgICAgICBhbiA9IG1pbihhbiwgYWRkKGFbaV0sIGFbaSAtIDFdKSArIGFkZChhW2kgKyAxXSwgYVtpIC0gMV0pICsgZihpICsgMSwgMCkpOwogICAgICAgIGlmIChpICsgMiA8IG4pCiAgICAgICAgICAgIGFuID0gbWluKGFuLCBhZGQoYVtpXSwgYVtpIC0gMV0pICsgYWRkKGFbaSArIDJdLCBhW2kgLSAxXSkgKyBmKGkgKyAyLCAxKSk7CiAgICB9CiAgICByZXR1cm4gbWVtW2ldW3N0XSA9IGFuOwp9CnZvaWQgc29sdmUoKQp7CiAgICBjaW4gPj4gbjsKICAgIGZvciAobGwgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICBjaW4gPj4gYVtpXTsKICAgIH0KICAgIGlmIChuID09IDEpIHsKICAgICAgICBjb3V0IDw8IDAgPDwgZW47IHJldHVybjsKICAgIH0KCiAgICBtZW1zZXQobWVtLCAtMSwgc2l6ZW9mKG1lbSkpOwoKICAgIGxsIGFuID0gZigwL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