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

totalWaitTime :: [Int] -> Int
totalWaitTime = sum.concat.inits.init