import Control.Applicative
import Control.Monad.State

main = do
    n <- getLine
    xs <- map read.words<$>getLine
    print $ inversions xs

bubbleSort xs = runState (bSort xs) 0

bSort :: [Int] -> State Int [Int]
bSort [] = return []
bSort xs = do
    (y:ys) <- bubble xs
    ys' <- bSort ys
    return (y:ys')

bubble :: [Int] -> State Int [Int]
bubble [x] = return [x]
bubble (x:xs) = do
    (y:ys) <- bubble xs
    if x > y
       then modify (+1) >> return (y:x:ys)
       else return (x:y:ys)

inversions []     = 0
inversions (x:xs) = under x xs + inversions xs

under x = length.filter (<x)

