#include <bits/stdc++.h>
using namespace std;

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("C:\\Users\\M\\alg\\practice\\clion_main\\input.txt", "r", stdin);
    freopen("C:\\Users\\M\\alg\\practice\\clion_main\\output.txt", "w", stdout);
#endif
}


#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#define all(x) x.begin(), x.end()
#define vb vector<bool>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define vc vector
#define $ make_pair

#ifndef LOCAL
#define cerr if(0) cerr
#define DBG(...) (true)
#endif

#define D double
#define int long long

// ----------------------------- CODE NOW ------------------------

const int INF = 1000000000000000000;

struct num {
    int x, s;
    num(int x_ = 0, int s_ = 0) {
        x = x_, s = s_;
    }
};

bool operator<=(num a, num b) {
    int x = min(a.s, b.s);
    a.s -= x;
    b.s -= x;
    if (a.s == 0) {
        while (a.x > b.x && b.s > 0) {
            --b.s;
            b.x *= 4;
        }
        return a.x <= b.x;
    }
    else {
        while (a.x <= b.x && a.s > 0) {
            a.x *= 4;
            --a.s;
        }
        return a.x <= b.x;
    }
}

void solve(vi &arri, vi &res) {
    int n = arri.size();
    vi prev(n, -1);
    res[0] = res[1] = 0;
    vc<num> arr(n);
    for (int i = 0; i < n; ++i) {
        arr[i] = num(arri[i], 0);
    }
    for (int i = 1; i < n; ++i) {
        if (arr[i] <= arr[i - 1]) {
            auto t = arr[i];
            ++t.s;
            if (t <= arr[i - 1]) {
                prev[i] = i - 1;
            }
            else {
                prev[i] = prev[i - 1];
            }
            res[i + 1] = res[i];
        }
        else {
            int j = i;
            int glob_delta = 0;
            while (j != 0) {
                int delta = 0;
                while (!(arr[j] <= arr[j - 1])) {
                    ++arr[j - 1].s;
                    ++delta;
                }
                int cnt = delta;
                if (cnt == 0) {
                    break;
                }
                delta *= j - 1 - prev[j - 1];
                glob_delta += delta;

                bool two_or_more_elements = (j - 1 - prev[j - 1] >= 2);
                j = prev[j - 1] + 1;
                if (two_or_more_elements) {
                    arr[j].s += cnt;
                }
            }
            prev[i] = j - 1;
            res[i + 1] = res[i] + glob_delta * 2;
        }
    }
}

bool FLAG = false;

void solve2(vi &arri, vi &res) {
    int n = arri.size();
    res[0] = res[1] = 0;
    vc<num> arr(n);
    for (int i = 0; i < n; ++i) {
        arr[i] = num(arri[i], 0);
    }
    for (int i = 1; i < n; ++i) {
        int cnt = 0;
        for (int j = i - 1; j >= 0; --j) {
            while (!(arr[j + 1] <= arr[j])) {
                ++arr[j].s;
                ++cnt;
            }
        }
        res[i + 1] = res[i] + 2 * cnt;
        if (FLAG) {
            cerr << "After step i: ";
            for (int j = 0; j < n; ++j) {
                cerr << "(" << arr[j].x << ", " << arr[j].s << ") ";
            }
            cerr << endl;
        }
    }
}

void print(vi &a, int k) {
    for (int i = 0; i < min((int)a.size(), k); ++i) {
        cerr << a[i] << " ";
    }
    cerr << endl;
}

signed main() {
    doRoutine();

    /*
    srand(123326142);
    while (true) {
        int n = 10;
        vi a(n);
        for (int i = 0; i < n; ++i) {
            a[i] = abs(rand()) % 100 + 1;
        }
        vi r1(n + 1), r2(n + 1);
        solve(a, r1);
        solve2(a, r2);
        if (r1 != r2) {
            cerr << "WRONG" << endl;
            FLAG = true;
        }
        if (FLAG) {
            print(a, 100);
            print(r1, 100);
            print(r2, 100);
            solve(a, r1);
            solve2(a, r2);
        }
    }

    return 0;
     */

    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    vi ra = a;
    reverse(all(ra));

    vi dp1(n + 1), dp2(n + 1);
    solve(a, dp1);
    solve(ra, dp2);

    int ans = INF;
    for (int l = 0; l <= n; ++l) {
        ans = min(ans, l + dp1[l] + dp2[n - l]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11308