import Control.Applicative
import Control.Monad.State
import Data.List (foldl')

main = do
    n <- readLn
    xs <- map read.words<$>getLine :: IO [Int]
    print $ foldl' (\n x -> n + snd x) 0 . mSort n . zip xs $ repeat ( 0 :: Int)

mergeSort xs = mSort n xs
    where n = length xs

mSort :: (Ord a) => Int -> [(a,Int)] -> [(a,Int)]
mSort 0 [] = []
mSort 1 [x] = [x]
mSort n xs = merge nl nr sortedLeft sortedRight
    where nl = n `div` 2
          nr = n - nl
          (left, right) = splitAt nl xs
          sortedLeft = mSort nl left
          sortedRight = mSort nr right

merge ll 0 xs ys = xs
merge 0 lr [] ys = ys
merge ll lr (x:xs) (y:ys)
  | fst x < fst y = x : merge (ll-1) lr xs (y:ys)
  | otherwise     = (fst y, snd y + ll) : merge ll (lr - 1) (x:xs) ys

