{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
trace _ = id

solve :: Int -> [Int] -> Int
solve n as = answer
  where
  va = VU.fromListN n as 
  posLst :: VU.Vector Int
  posLst = trace ("posLst " ++ show posLst0) posLst0
  posLst0 = VU.reverse $ costLst n $ VU.reverse va
  negLst :: VU.Vector Int
  negLst = trace ("negLst " ++ show negLst0) negLst0
  negLst0 = costLst n va
  answer = VU.minimum $ VU.izipWith f posLst negLst
    where f i pos neg = 2 * (pos + neg) + i

costLst :: Int -> VU.Vector Int -> VU.Vector Int
costLst n xs = VU.scanl' (+) 0 eVec
  where
    initAcc :: (Int, [(Int, Int)])
    initAcc = (0, [(0, big)])
    f :: (Int, [(Int,Int)]) -> Maybe (Int, (Int, [(Int,Int)]))
    f (i, steps@((len, gap):rem))
      | i == n = Nothing
      | 4 * x <= xNext = Just (0, (i+1, (1, costF xNext x):steps))
      | x <= xNext = Just (0, (i+1, (len+1, gap):rem))
      | otherwise = Just (c, (i+1, newSteps))
      where
        x = xs VU.! i
        xNext | i == 0    = big
              | otherwise = xs VU.! (i-1)
        (newSteps, c) = g (costC x xNext) 0 1 steps
        g :: Int -> Int -> Int -> [(Int,Int)] -> ([(Int,Int)], Int)
        g h cost len step = trace ("g " ++ show (h,cost,len,step,a)) a
          where a = g0 h cost len step
        g0 !h !cost !len ((tLen,gap):rem)
          | h <= gap = ((newLen, gap-h):rem, newCost)
          | otherwise = g (h-gap) newCost newLen rem
          where newCost = cost + h*tLen
                newLen = len + tLen
    eVec = trace ("eVec " ++ show eVec0) eVec0
    eVec0 = VU.unfoldrN n f initAcc

big = 10 ^ 10

epsilon = 2 ** (-64)

log4 :: Int -> Double
log4 x = logBase 4 (fromIntegral x)

costC x y = ceiling (log4 x - log4 y - epsilon)
costF x y = floor (log4 x - log4 y + epsilon)

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
      line2:remLines2 = remLines1
      as = map readBInt line2
  in solve n as

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents
