Problem:
Score : 800 points

Problem Statement

There are N positive integers A_1, A_2, ..., A_N.
Takahashi can perform the following operation on these integers any number of times:

Choose 1 \leq i \leq N and multiply the value of A_i by -2.

Notice that he multiplies it by minus two.

He would like to make A_1 \leq A_2 \leq ... \leq A_N holds.
Find the minimum number of operations required. If it is impossible, print -1.

Constraints

1 \leq N \leq 200000

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the answer.

Sample Input 1

4
3 1 4 1

Sample Output 1

3

One possible solution is:

Choose i=4 and multiply the value of A_4 by -2. A_1, A_2, A_3, A_4 are now 3, 1, 4, -2.

Choose i=1 and multiply the value of A_1 by -2. A_1, A_2, A_3, A_4 are now -6, 1, 4, -2.

Choose i=4 and multiply the value of A_4 by -2. A_1, A_2, A_3, A_4 are now -6, 1, 4, 4.

Sample Input 2

5
1 2 3 4 5

Sample Output 2

0

A_1 \leq A_2 \leq ... \leq A_N holds before any operation is performed.

Sample Input 3

8
657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097

Sample Output 3

7

Solution in PyPy3 (2.4.0) (judge verdict: Wrong Answer)


"""
Writer: SPD_9X2
https://atcoder.jp/contests/caddi2018/tasks/caddi2018_c

まさか、3分探索か？？？
正負が変わる位置を決め撃ったら、あとは貪欲に決まる
正負が変わる位置を1だけ右に変更したとする
すると、基準点より左は回数は単調増加し、右は単調減少する

→3分探索可能そう！！
数字がでかくなりすぎるから根本的な問題か？
C++だと longlongを突破しそう…

4を何回掛ければ左の数以上になるか、を持っておく？
3回のとき、
左に4**N がかかっていれば、4**(N+3)を掛けて対応できる

おなじになるとき、逆向きは-xにしておけばよい
そうでないときは-x+1でおｋ
"""

def want(ind):

    ret = 0

    now = 0
    for i in range(ind+1,N):
        now = max(0,now+lmul[i])
        ret += now*2
    
    now = 0
    for i in range(ind-1,-1,-1):
        ret += 1
        if i == ind-1:
            continue
        now = max(0,now+rmul[i])
        ret += now*2        

    return ret

N = int(input())
a = list(map(int,input().split()))

lmul = [0]
rmul = []

for i in range(N-1):
    L = a[i]
    R = a[i+1]

    if L >= R:
        num = 0
        while R < L:
            R *= 4
            num += 1

        lmul.append(num)

        if R==L:
            rmul.append(-1*num)
        else:
            rmul.append(-1*num+1)

    else:

        num = 0
        while R > L:
            L *= 4
            num += 1

        rmul.append(num)

        if R==L:
            lmul.append(-1*num)
        else:
            lmul.append(-1*num+1)

rmul.append(0)

#print (lmul,rmul)
#for i in range(N+1):
#    print (want(i))

l = -1
r = N+2

while r-l > 2:

    m1 = (l*2+r)//3
    m2 = (l+r*2)//3

    r1 = want(m1)
    r2 = want(m2)

    if r1 < r2:
        r = m2
    else:
        l = m1

ans = float("inf")
for i in range(l-3,r+3):

    if i < 0 or i > N+1:
        continue
    ans = min(ans , want(i))

print (ans)