import Control.Monad
import Data.List
main = do
    n <- readLn
    if n == 0 then return ()
              else do
                  nums <- replicateM n readLn
                  mapM_ print $ map (totalWaitTime.sort) nums

totalWaitTime = sum.concat.inits.init