import Control.Monad
import Data.List
main = do
    nums <- fmap reverse $ getData []
    mapM_ print $ map (totalWaitTime.sort) nums

getData :: [[Int]] -> IO [[Int]]
getData nums = do
    n <- readLn
    if n == 0 then return nums
              else do
                  mins <- replicateM n $ fmap read getLine
                  getData $ mins:nums

totalWaitTime = sum.map sum.inits.init