import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.Char
import Control.Monad

main = do
    n <- readLn :: IO Int
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    os <- VUM.replicate (10^5+1) (0 :: Int)
    es <- VUM.replicate (10^5+1) (0 :: Int)
    let h = n `quot` 2
    forM_ [1,3..n-1] $ \i -> do
        VUM.modify os (+1) (xs VU.! i)
        VUM.modify es (+1) (xs VU.! (i-1))
    (mo,io) <- VU.maximum . flip VU.zip (VU.fromList [1..10^5]) <$> VU.unsafeFreeze os :: IO (Int, Int)
    (me,ie) <- VU.maximum . flip VU.zip (VU.fromList [1..10^5]) <$> VU.unsafeFreeze es :: IO (Int, Int)
    print $ 
        case (mo == h, me == h) of
            (True, True) -> 
                case (io == ie) of
                    True -> h 
                    False -> 0
            _ -> h - mo + h - me