{-# 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

solve :: Int -> [Int] -> Int
solve n as = minimum $ zipWith (+) posLst negLst
  where
  posLst = costLst 0 as
  negLst = reverse $ costLst 1 $ reverse as

costLst :: Int -> [Int] -> [Int]
costLst app xs = map fst $ scanr (upd app) (0,0) (zip xs (tail xs ++ [big]))

upd app (x,y) (!a, !len)
  | x <= y = (a+app, len+1)
  | otherwise = (a+app+c*len, len+1)
  where c = 2 * ((cost x y + 1) `div` 2)

big = 10 ^ 10

epsilon = 2 ** (-64)

log2 :: Int -> Double
log2 x = logBase 2 (fromIntegral x)

cost x y = ceiling (log2 x - log2 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
