#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#define mod 1000000007
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, a, b) for (long long i = (a); i <= (b); i++)
#define FORD(i, a, b) for (long long i = (a); i >= (b); i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define debug(x) cout << #x << '=' << (x) << endl;
#define debugp(x) cout << #x << "= {" << (x.first) << ", " << (x.second) << "}" << endl;
#define debug2(x, y) cout << "{" << #x << ", " << #y << "} = {" << (x) << ", " << (y) << "}" << endl;
#define debugv(v)         \
    cout << #v << " : ";  \
    for (auto x : v)      \
        cout << x << ' '; \
    cout << endl;
#define all(x) x.begin(), x.end()
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
typedef long long ll;
typedef unsigned long long ull;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int &n, int b) { n |= two(b); }
inline void unset_bit(int &n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n)
{
    int res = 0;
    while (n && ++res)
        n -= n & (-n);
    return res;
}
template <class T>
void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
void chmin(T &a, const T &b) { a = min(a, b); }

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

long long int lcm(long long int a, long long int b)
{
    return (a * b) / gcd(a, b);
}

long long int max(long long int a, long long int b)
{
    if (a > b)
        return a;
    return b;
}

long long int power(long long int x, long long int y)
{
    long long int res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}

long long int powermod(long long int x, long long int y)
{
    long long int res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

long long mulmod(long long a, long long b)
{
    long long res = 0;
    a %= mod;
    while (b)
    {
        if (b & 1)
            res = (res + a) % mod;
        a = (2 * a) % mod;
        b >>= 1;
    }

    return res;
}

bool isPrime(long long int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}

long double dist(long long int x1, long long int y1, long long int x2, long long int y2)
{
    return (long double)sqrt((long double)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
}
long long int squaredist(long long int x1, long long int y1, long long int x2, long long int y2)
{
    return ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

long long int nCr(long long int n, long long int r)
{
    if (r == 0)
        return 1;
    return (n * nCr(n - 1, r - 1)) / r;
}

long long int countDivisors(long long int n)
{
    long long int cnt = 0;
    for (int i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
                cnt++;
            else
                cnt = cnt + 2;
        }
    }
    return cnt;
}

unsigned long long int countDivisibles(unsigned long long int A, unsigned long long int B, unsigned long long int M)
{
    if (A % M == 0)
        return (B / M) - (A / M) + 1;

    return (B / M) - (A / M);
}

long long int xorRange(long long int x, long long int y)
{
    if (x % 2 == 0)
    {
        long long int pattern[] = {y, 1, y + 1, 0};
        return pattern[(int)((y - x) % 4)];
    }
    else
    {
        long long int pattern[] = {x, x ^ y, x - 1, (x - 1) ^ y};
        return pattern[(int)((y - x) % 4)];
    }
}

unsigned long long int maxOrRange(unsigned long long int l, unsigned long long int r)
{
    while (l < r)
        l &= (l + 1);
    return (l & r);
}

long long mul(long long a, long long b)
{
    return (a * b) % mod;
}

long long mul(long a, long long b, long long c)
{
    return mul(mul(a, b), c);
}

long long mul(long long a, long long b, long long c, long long d)
{
    return mul(mul(a, b), mul(c, d));
}

long long add(long long a, long long b)
{
    return (a + b) % mod;
}

long long neg(long long a)
{
    return (mod - (a % mod)) % mod;
}

long long sub(long long a, long long b)
{
    return add(a, neg(b));
}

long long minv(long long a)
{
    int b = mod - 2;
    long long ans = 1;
    while (b)
    {
        if (b % 2)
            ans = mul(ans, a);
        a = mul(a, a);
        b /= 2;
    }
    return ans;
}

long long divi(long long a, long long b)
{
    return mul(a, minv(b));
}

bool sortdesc(const std::tuple<int, int, int> &a, const std::tuple<int, int, int> &b)
{
    return (std::get<0>(a) > std::get<0>(b));
}

std::vector<long long> fni(100000);
std::vector<long long> nni(100000);
std::vector<long long> fact(100000);

void Inv_Num_Fact_Factorial(long long p, long long N)
{
    fni[0] = fni[1] = nni[0] = nni[1] = fact[0] = 1;
    for (int i = 1; i <= N; i++)
    {
        if (i >= 2)
        {
            nni[i] = mul(nni[p % i], (p - p / i));
            fni[i] = mul(nni[i], fni[i - 1]);
        }
        fact[i] = mul(fact[i - 1], i);
    }
}

long long fnCr(long long int N, long long int R)
{
    return mul(fact[N], fni[R], fni[N - R]);
}

bool findParity(int x)
{
    int y = x ^ (x >> 1);
    y = y ^ (y >> 2);
    y = y ^ (y >> 4);
    y = y ^ (y >> 8);
    y = y ^ (y >> 16);
    if (y & 1) return 1;
    return 0;
}

using namespace std;

class Graph 
{ 
    int V;    // No. of vertices 
  
    // In a weighted graph, we need to store vertex  
    // and weight pair for every edge 
    list< pair<int, int> > *adj; 
  
public: 
    Graph(int V);  // Constructor 
  
    // function to add an edge to graph 
    void addEdge(int u, int v, int w); 
  
    // prints shortest path from s 
    int shortestPath(int s); 
}; 
  
// Allocates memory for adjacency list 
Graph::Graph(int V) 
{ 
    this->V = V; 
    adj = new list< pair<int, int> >[V]; 
} 
  
void Graph::addEdge(int u, int v, int w) 
{ 
    adj[u].push_back(make_pair(v, w)); 
    adj[v].push_back(make_pair(u, w)); 
} 
  
// Prints shortest paths from src to all other vertices 
int Graph::shortestPath(int src) 
{ 
    // Create a set to store vertices that are being 
    // prerocessed 
    set< pair<int, int> > setds; 
  
    // Create a vector for distances and initialize all 
    // distances as infinite (INF) 
    vector<int> dist(V, INF); 
  
    // Insert source itself in Set and initialize its 
    // distance as 0. 
    setds.insert(make_pair(0, src)); 
    dist[src] = 0; 
  
    /* Looping till all shortest distance are finalized 
       then setds will become empty */
    while (!setds.empty()) 
    { 
        // The first vertex in Set is the minimum distance 
        // vertex, extract it from set. 
        pair<int, int> tmp = *(setds.begin()); 
        setds.erase(setds.begin()); 
  
        // vertex label is stored in second of pair (it 
        // has to be done this way to keep the vertices 
        // sorted distance (distance must be first item 
        // in pair) 
        int u = tmp.second; 
  
        // 'i' is used to get all adjacent vertices of a vertex 
        list< pair<int, int> >::iterator i; 
        for (i = adj[u].begin(); i != adj[u].end(); ++i) 
        { 
            // Get vertex label and weight of current adjacent 
            // of u. 
            int v = (*i).first; 
            int weight = (*i).second; 
  
            //  If there is shorter path to v through u. 
            if (dist[v] > dist[u] + weight) 
            { 
                /*  If distance of v is not INF then it must be in 
                    our set, so removing it and inserting again 
                    with updated less distance.   
                    Note : We extract only those vertices from Set 
                    for which distance is finalized. So for them,  
                    we would never reach here.  */
                if (dist[v] != INF) 
                    setds.erase(setds.find(make_pair(dist[v], v))); 
  
                // Updating distance of v 
                dist[v] = dist[u] + weight; 
                setds.insert(make_pair(dist[v], v)); 
            } 
        } 
    } 
  
    // Print shortest distances stored in dist[] 
    // printf("Vertex   Distance from Source\n"); 
    // for (int i = 0; i < V; ++i) 
    //     printf("%d \t\t %d\n", i, dist[i]); 
    return dist[V-1];
} 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int V;
    cin >> V;
    Graph g(V);
    int arr[V];
    REP(i,V){
        cin >> arr[i];
    } 
    REP(i,V-2){
        g.addEdge(i,i+1,abs(arr[i+1]-arr[i]));
        g.addEdge(i,i+2,abs(arr[i+2]-arr[i]));
    }
    g.addEdge(V-2,V-1,abs(arr[V-1]-arr[V-2]));

    cout << g.shortestPath(0); 

}


Measured memory_bytes: 19840