program negative_doubling
  implicit none
  integer :: n, a(200000) = 0, c(200000) = 0, i, j, k, m
  real(8) :: b(200000) = 0.d0
  read(*,*) n
  read(*,*) a(1:n)
  b(1:n) = log2(real(a(1:n),8))
  do i = 2, n
    if (b(i) >= b(i-1)) cycle
    c(i) = ceiling(b(i-1)-b(i))
    c(i) = c(i)+mod(c(i),2)
    b(i) = b(i)+real(c(i),8)
  end do
  m = sum(c(1:n))
  do i = 1, n
    c(i) = 0
    b(i) = log2(real(a(i),8))
    do j = i-1, 1, -1
      if (b(j) >= b(j+1)) cycle
      c(j) = ceiling(b(j+1)-b(j))
      c(j) = c(j)+mod(c(j),2)
      b(j) = b(j)+real(c(j),8)
    end do
    k = c(i+1)
    do j = i+1, n
      if (k > c(j)) k = c(j)
      if (k == 0) exit
      c(j) = c(j)-k
      b(j) = b(j)-2.d0*real(k,8)
    end do
    m = min(m,sum(c(1:n))+i)
  end do
  write(*,'(i0)') m
  stop
contains
  elemental real(8) function log2(x)
    implicit none
    real(8), intent(in) :: x
    log2 = log(x)/log(2.d0)
    return
  end function log2
end program negative_doubling