output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_1 A_2 ... A_N
attempt: import math
  
  N = int(input())
  A = list(map(int, input().split()))
  
  
  # k個目を固定すると仮定したときの操作回数
  def process(A, k):
      left = 0
      t = A[k]
      for i in range(k - 1, -1, -1):
          a = A[i]
          if a > t:
              if t > 0:
                  left += 1
                  t = a * (-2)
              else:
                  l = math.ceil(math.log2(abs(t)) - math.log2(abs(a)))
                  if l % 2 == 0:
                      l += 1  # 奇数にする
                  left += l
                  t = -(a * 2**l)
          else:
              t = a
      right = 0
      t = A[k]
      for i in range(k + 1, N):
          a = A[i]
          if t > a:
              l = math.ceil(math.log2(abs(t)) - math.log2(abs(a)))
              if l % 2 == 1:
                  l += 1  # 偶数にする
              right += l
              t = a * 2**l
          else:
              t = a
      return left + right
  
  
  # 3分探索
  fr = 0
  to = N
  while to - fr > 2:
      mid1 = fr + ((to - fr)) // 3
      mid2 = fr + ((to - fr) * 2) // 3
      if process(A, mid1) < process(A, mid2):
          to = mid2
      else:
          fr = mid1
  print(min(process(A, fr), process(A, fr + 1)))
  
problem_description: 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`.
samples: [{"input": "4\n    3 1 4 1", "output": "3\n    \n\nOne possible solution is:\n\n  * 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.\n  * 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.\n  * 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.\n\n* * *"}, {"input": "5\n    1 2 3 4 5", "output": "0\n    \n\nA_1 \\leq A_2 \\leq ... \\leq A_N holds before any operation is performed.\n\n* * *"}, {"input": "8\n    657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097", "output": "7"}]