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: if __name__ == "__main__":
      n = int(input())
      A = [int(i) for i in input().split(" ")]
      ansl = [0 for i in range(n)]
      ansr = [0 for i in range(n)]
      suml = 0
      sumr = 0
      xl = 0
      xr = 0
      for i in range(n):
          l = i
          r = n - i - 1
          if i == 0:
              xl = A[l] * -2
              ansl[l] = 1
              suml = 1
  
              xr = A[r]
              ansr[r] = 0
              sumr = 0
          else:
              x = A[l] * -2
              ansl[l] = suml + 1
              while xl > x:
                  xl *= 4
                  ansl[l] += 2
              xl = x
              suml = ansl[l]
  
              ansr[r] = sumr
              while xr < A[r]:
                  xr *= 4
                  ansr[r] += 2 * (n - r - 1)
              sumr = ansr[r]
              xr = A[r]
      ans = int(1e18)
      for i in range(n + 1):
          if i == 0:
              ans = min(ans, ansr[i])
          elif i == n:
              ans = min(ans, ansl[i - 1])
          else:
              ans = min(ans, ansl[i - 1] + ansr[i])
          if ans == 5:
              print(i)
              break
      print(ans)
  
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"}]