#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define srep(i) for(int i = 0; i < s.size(); i++)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 1e9
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int N, W, A, B;
int a[100005];
int h[100005];
int weight[105] = {}, value[105] = {};
ll dp[100000005];
ll dp2[10005][10005];
int in = 0;
int cnt = 0;

template <typename T> T gcd(T a, T b) {
    if(a < b) {
        swap(a, b);
    }
    if(a % b == 0)
        return b;
    return gcd(b, a % b);
}

ll fib(ll n) {
    dp[0] = 0;
    dp[1] = 1;
    for(int i = 2; i <= n; i++) {
        dp[i] = dp[i - 1] + dp[i - 2];
    }
    return dp[n];
}

// void rec(int i, int j) {
//     cout << "i: " << i << " j: " << j << " cnt: " << cnt << endl;
//     cnt++;

//     if(i == N) {
//         return;
//     }

//     // cout << " cnt2: " << cnt << endl;
//     rec(i + 1, j);
//     cout << " cnt3: " << cnt << endl;
//     rec(i + 1, j + 1);
//     cout << " cnt4: " << cnt << endl;

//     return;
// }

void insert_sort(int a[], int n) {
    for(int i = 1; i < n; i++) {
        int v = a[i];
        int j = i - 1;
        for(; j >= 0; j--) {
            if(a[j] > v)
                a[j + 1] = a[j];
            else
                break;
        }
        a[j + 1] = v;
    }
}

void bubble_sort(int a[], int n) {
    bool flag = true;
    for(int i = 0; flag; i++) {
        flag = false;
        for(int j = n - 1; j > i; j--) {
            if(a[j] < a[j - 1]) {
                swap(a[j], a[j - 1]);
                flag = true;
            }
        }
    }
}

void select_sort(int a[], int n) {
    for(int i = 0; i < n - 1; i++) {
        int mini = i;
        for(int j = i + 1; j < n; j++) {
            if(a[mini] > a[j]) {
                mini = j;
            }
        }
        if(i != mini) {
            swap(a[mini], a[i]);
        }
    }
}

void merge(int a[], int left, int mid, int right) {
    vector<int> buf;
    for(int i = left; i < mid; ++i)
        buf.push_back(a[i]);
    for(int i = right - 1; i >= mid; --i)
        buf.push_back(a[i]);

    int iterator_left = 0;
    int iterator_right = (int)buf.size() - 1;
    for(int i = left; i < right; ++i) {
        if(buf[iterator_left] <= buf[iterator_right]) {
            a[i] = buf[iterator_left++];
        } else {
            a[i] = buf[iterator_right--];
        }
        cnt++;
    }
}

void merge_sort(int a[], int left, int right) {
    if(left == right - 1)
        return;
    int mid = left + (right - left) / 2;

    merge_sort(a, left, mid);
    merge_sort(a, mid, right);
    merge(a, left, mid, right);
}

void quick_sort(int a[], int left, int right) {
    if(left >= right - 1)
        return;

    int pivot_index = left + (right - left) / 2;
    int pivot = a[pivot_index];
    swap(a[pivot_index], a[right - 1]);

    int i = left;
    for(int j = left; j < right - 1; ++j) {
        if(a[j] < pivot)
            swap(a[i++], a[j]);
    }
    swap(a[i], a[right - 1]);

    quick_sort(a, left, i);
    quick_sort(a, i + 1, right);
}

int binary_search(int a[], int n, int target) {
    int left = 0;
    int right = n;
    int mid;
    while(left < right) {
        mid = left + (right - left) / 2;
        if(a[mid] == target) {
            return 1;
        } else if(a[mid] < target) {
            left = mid + 1;
        } else {
            right = mid;
        }
    }
    return 0;
}

ll all_search(int i) {

    if(i == N - 1) {
        return 0;
    } else if(i + 2 == N) {
        return all_search(i + 1) + abs(h[i + 1] - h[i]);
    } else {
        return min(all_search(i + 1) + abs(h[i + 1] - h[i]),
                   all_search(i + 2) + abs(h[i + 2] - h[i]));
    }
}

ll dp_recursive(int i) {
    if(dp[i] >= 0) {
        return dp[i];
    }

    if(i == N - 1) {
        return 0;
    } else if(i + 2 == N) {
        return dp[i] = all_search(i + 1) + abs(h[i + 1] - h[i]);
    } else {
        return dp[i] = min(all_search(i + 1) + abs(h[i + 1] - h[i]),
                           all_search(i + 2) + abs(h[i + 2] - h[i]));
    }
}

ll dp_for(int n) {
    dp[0] = 0;
    for(int i = 1; i < n; i++) {
        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
        if(i > 1) {
            dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        }
    }
    return dp[n - 1];
}

int main() {
    cin >> N;
    rep(i, N) cin >> h[i];
    memset(dp, -1, sizeof(dp));
    cout << dp_for(N) << endl;
}


Measured memory_bytes: 783616