sort :: (Ord a) => [a] -> [a]
sort [] = []
sort [a] = [a]
sort arr@(a:ar) = sort [x | x <- arr, x < a] ++ ([x | x <- arr, x == a]++ sort [x | x <- arr, x > a])

mergeSort :: Int -> Int -> Int
mergeSort left right
  |left + 1 < right = (right - left) + mergeSort left mid + mergeSort mid right
  |otherwise = 0
  where
    mid = div (left + right) 2

join' :: (Show a) => Char -> [a] -> String
join' _ [a] = show a
join' c (h:t) = (show h) ++ (c:join' c t)

main :: IO ()
main = do
  n <- fmap (\m -> read m :: Int) getLine
  arr <- fmap ((map (\m -> read m :: Int)) . words) getContents
  putStrLn $ join' ' ' (sort arr)
  print $ mergeSort 0 n