{-# LANGUAGE BangPatterns #-}

import           Control.Applicative
import           Control.Monad
import           Debug.Trace

merge :: [Int] -> [Int] -> ([Int], Int)
merge xs ys = go 0 [] xs ys
  where
    go !k !ts [] bs = (reverse ts ++ bs, k)
    go !k !ts as [] = (reverse ts ++ as, k)
    go !k !ts (a:as) (b:bs)
        | a > b = go (k + length (a:as)) (b : ts) (a : as) bs
        | otherwise = go k (a : ts) as (b : bs)

mergeSort :: [Int] -> ([Int], Int)
mergeSort xs
    | length r <= 1 = merge l r
    | otherwise     = let (ls, ln) = mergeSort l
                          (rs, rn) = mergeSort r
                          (as, an) = merge ls rs
                       in (as, ln + rn + an)
  where
    (!l, !r) = splitAt (length xs `div` 2) xs

main :: IO ()
main = do
    getLine
    xs <- fmap read . words <$> getLine
    let (_, n) = mergeSort xs
    print n

