import Control.Applicative ((<$>))

merge :: Int -> Int -> Int -> [Int] -> [Int] -> ([Int], Int)
merge _ _ _ [] ys = (ys,0)
merge _ _ _ xs [] = (xs,0) 
merge i j len xxs@(x:xs) yys@(y:ys)
  | x <= y    = (x: fst res1, snd res1)
  | otherwise = (y: fst res2, snd res2+len-i) 
  where
    res1 = merge (i+1) j len xs yys
    res2 = merge i (j+1) len xxs ys

sort :: [Int] -> ([Int], Int)
sort [] = ([], 0)
sort (x:[]) = ([x], 0)
sort xs = (fst res, snd res + snd a + snd b)
  where
    len = length xs
    a = sort $ take (len`div`2) xs
    b = sort $ reverse $ take (len-len`div`2) $ reverse xs
    res = merge 0 0 (length $ fst a) (fst a) (fst b)

main :: IO ()
main = do
  _ <- getLine
  as <- map read . words <$> getLine :: IO [Int]
  print $ snd $ sort as