countSorted [] _ c = c
countSorted _ [] c = c
countSorted (r:ref) (x:xs) c
  | r == x = countSorted ref xs (c+1)
  | otherwise = countSorted (r:ref) xs c

main :: IO ()
main = do
  n <- read <$> getLine :: IO Int
  ps <- map read.lines <$> getContents :: IO [Int]
  let m = n`div`2
      as = filter (<=m) ps
      bs = filter (>m) ps
      sca = countSorted [m,m-1..1] (reverse as) 0
      scb = countSorted [m+1,m+2..n] bs 0
      ans = (m-sca)+(m-scb)
      m0idx = ps !! m
      m1idx = ps !! (m+1)
  print $ if ans < m
    then if m0idx < m1idx
      then ans
      else m
    else ans
