import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Data.Sequence         (Seq (..), ViewL (..), ViewR (..), (<|),
                                        (><), (|>))
import qualified Data.Sequence         as S

read' :: B.ByteString -> Int
read' bs | Just (n, _) <- B.readInt bs = n

merge :: Seq Int -> Seq Int -> (Seq Int, Int)
merge xs ys
    | S.null xs = (ys, 0)
    | S.null ys = (xs, 0)
    | a :< as <- S.viewl xs
    , b :< bs <- S.viewl ys =
        if a <= b
            then (S.singleton a, 0) <:> merge as ys
            else (S.singleton b, S.length xs) <:> merge xs bs

(<:>) :: (Seq Int, Int) -> (Seq Int, Int) -> (Seq Int, Int)
(xs, m) <:> (ys, n) = (xs >< ys, m + n)

mergeSort :: Seq Int -> (Seq Int, Int)
mergeSort xs
    | S.length xs == 1 = (xs, 0)
    | otherwise        = let (as, i) = mergeSort ls
                             (bs, j) = mergeSort rs
                             (cs, k) = merge as bs
                          in (cs, i + j + k)
  where
    mid = S.length xs `div` 2
    (ls, rs) = S.splitAt mid xs

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

