program negative_doubling
  implicit none
  integer :: n, a(200000,2) = 0, dp(200000,0:15,2) = 0, m, i, j, x, y
  real(8) :: b(200000,2) = 0.d0
  read(*,*) n
  read(*,*) a(1:n,1)
  a(1:n,2) = a(n:1:-1,1)
  b(1:n,:) = log4(real(a(1:n,:),8))
  do x = 0, 15
    dp(n,x,:) = 2*x
  end do
  do i = n-1, 1, -1
    do x = 0, 15
      do j = 1, 2
        y = max(x+ceiling(b(i,j)-b(i+1,j)),0)
        if (y <= 15) then
          dp(i,x,j) = dp(i+1,y,j)+2*x
        else
          dp(i,x,j) = dp(i+1,15,j)+2*x+2*(y-15)*(n-i-1)
        end if
      end do
    end do
  end do
  dp(1:n,:,2) = dp(n:1:-1,:,2)
  m = min(dp(1,0,1),dp(n,0,2)+n)
  do i = 2, n
    m = min(m,dp(i,0,1)+dp(i-1,0,2)+i-1)
  end do
  write(*,'(i0)') m
  stop
contains
  elemental real(8) function log4(x)
    implicit none
    real(8), intent(in) :: x
    log4 = log(x)/log(4.d0)
    return
  end function log4
end program negative_doubling