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 sys
  
  read = sys.stdin.buffer.read
  readline = sys.stdin.buffer.readline
  readlines = sys.stdin.buffer.readlines
  
  """
  ・正、負の部分に分けて。本質的には正の場合ができればよい
  ・4A_i > A_{i+1} となってるものはまとめる。運命共同体の区間たちができる
  ・一番弱い区間と勝負する。成長すると次の区間とマージできる
  """
  
  N, *A = map(int, read().split())
  
  
  def calc_positive_case(N, A):
      INF = 1 << 32
      # ある場所を始点として、そこから全部positiveにしたい場合
      dp = [0] * N
      left_end = []
      right_end = []
      items = []
      mult_cnt = 0
      for i, x in enumerate(A[::-1]):
          left_end.append(x)
          right_end.append(x)
          items.append(1)
          # 最小の矛盾を解消
          while len(items) >= 2:
              l2, l1 = left_end[-2:]
              r2, r1 = right_end[-2:]
              n2, n1 = items[-2:]
              if r1 * 4 <= l2:
                  # mergeせず
                  break
              while r1 > l2:
                  l2 *= 4
                  r2 *= 4
                  mult_cnt += n2
              left_end.pop()
              left_end[-1] = l1
              right_end.pop()
              right_end[-1] = r2
              items.pop()
              items[-1] += n1
          if right_end[0] > INF:
              right_end[0] = INF
          dp[i] = mult_cnt
      return dp[::-1]
  
  
  pos = calc_positive_case(N, A)  # ある点を正の始点としたときに必要な、4倍の回数
  neg = calc_positive_case(N, A[::-1])[::-1]  # ある点を負の始点としたときの～～
  
  pos = [2 * x for x in pos] + [0]
  neg = [0] + [2 * x + i for i, x in enumerate(neg, 1)]  # -2倍の初期コストが乗る
  
  answer = min(x + y for x, y in zip(pos, neg))
  print(answer)
  
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"}]