import Control.Applicative
import Control.Monad

qsort :: [Int] -> [Int]
qsort [] = []
qsort (p:xs) = qsort lt ++ [p] ++ qsort gteq
  where lt   = [x | x <- xs, x < p ]
        gteq = [x | x <- xs, x >= p]

solver' :: Int -> [Int] -> Int
solver' 0 _      = 0
solver' _ []     = 0
solver' n (x:xs) = (n-1) * x + solver' (n-1) xs


solver :: Int -> [Int] -> Int
solver n xs = solver' n (qsort xs)

main ::IO()
main = do
  n <- (read :: String -> Int) <$> getLine
  unless (n == 0) $ do
    line <- map (read :: String -> Int) <$> replicateM n getLine
    print $ solver n line
    main