import Control.Monad
import Control.Applicative

qsort :: [Int] -> [Int]
qsort [] = []
qsort (p:xs) =
  let lt   = filter (< p) xs
      gteq = filter (>= p) xs
  in  qsort lt ++ [p] ++ qsort gteq


penalty :: [Int] -> Int -> Int
penalty xs n = penalty' xs n 0
  where penalty' [] _ acc = acc
        penalty' _  0 acc = acc
        penalty' (y:ys) i acc = penalty' ys (i - 1) (acc + y * i)


main :: IO()
main = forever $ do
  n <- readLn
  line <- map read . words <$> getLine
  print $ penalty (qsort line) n