import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto X = A.map!(a => log2(a)).array;

    auto plus = new long[](N);  // +の項の先頭インデックスがiであるときの+側の最小操作回数
    auto minus = new long[](N); // -の項の末尾インデックスがiであるときの-側の最小操作回数
    minus[0] = 1;

    auto queue = new DList!(Tuple!(real, real, int, int));
    queue.insertBack(tuple(X[0], X[0], 0, 0));

    foreach (i; 1..N) {
        minus[i] = minus[i-1] + 1;
        auto t = tuple(X[i], X[i], i, i);
        while (!queue.empty && t[0] > queue.back[1]) {
            long diff = ceil(t[0] - queue.back[1]).to!long;
            if (diff % 2 == 1) diff += 1;
            minus[i] += diff * (queue.back[3] - queue.back[2] + 1);
            queue.back[0] += diff;
            queue.back[1] = t[1];
            queue.back[3] = t[3];
            t = queue.back;
            queue.removeBack;
        }
        queue.insertBack(t);
    }

    queue = new DList!(Tuple!(real, real, int, int));
    queue.insertFront(tuple(X[N-1], X[N-1], N-1, N-1));

    foreach_reverse (i; 0..N-1) {
        plus[i] = plus[i+1];
        auto t = tuple(X[i], X[i], i, i);
        while (!queue.empty && t[1] > queue.front[0]) {
            long diff = ceil(t[1] - queue.front[0]).to!long;
            if (diff % 2 == 1) diff += 1;
            plus[i] += diff * (queue.front[3] - queue.front[2] + 1);
            queue.front[0] = t[0];
            queue.front[1] += diff;
            queue.front[2] = t[2];
            t = queue.front;
            queue.removeFront;
        }
        queue.insertFront(t);
    }


    long ans = 1L << 59;

    foreach (i; 0..N+1) {
        if (i == 0) {
            ans = min(ans, plus[0]);
        } else if (i == N) {
            ans = min(ans, minus[N-1]);
        } else {
            ans = min(ans, minus[i-1] + plus[i]);
        }
    }

    ans.writeln;
}