module Main where
import Debug.Trace
import Data.List
import qualified Data.Sequence as S
import qualified Data.ByteString.Char8 as B
import Data.Int
import Data.Char
import Data.Array
import Data.Maybe
import qualified Data.Map as M
import Data.Ord
import Data.Functor
import Control.Applicative
import Control.Monad

solve :: [Int] -> Int -> Int
solve l n = count where
    (count, _) = msort l n

merge :: Int-> (Int, [Int]) -> (Int, [Int]) -> (Int, [Int])
merge ln (lc, ll) (rc, rl) = iter ln (lc + rc) [] ll rl where
    iter _ c ml [] rl = (c, reverse ml ++ rl)
    iter _ c ml ll [] = (c, reverse ml ++ ll)
    iter d c ml ll@(l:ls) rl@(r:rs) 
        | l <= r   = d `seq` iter (d-1) c (l:ml) ls rl
        |otherwise = c `seq` iter d (c+d) (r:ml) ll rs
    
msort :: [Int] -> Int-> (Int, [Int])
msort l 1 = (0, l)
msort l n = merge ln (msort ll ln) (msort rl rn) where
        (ln, rn) = (div n 2, n - ln)
        (ll, rl) = splitAt ln l

readIntLn:: IO Int
readIntLn = (fst . fromJust . B.readInt) <$> B.getLine

readIntList:: IO [Int]
readIntList = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

main :: IO() 
main = do
    n <- readIntLn
    l <- readIntList
    print $ solve l n

