import Data.List

ans :: [Int] -> Int
ans t =
  let s = reverse $ sort t
      z = zip [0..] s
      o = foldl (\s (a,b) -> s + a*b) 0 z
  in
    o

main = do
  c <- getContents
  let i  = drop 1 $ map read $ lines c :: [Int]
      i' = takeWhile (/= 0) i
      o  = ans i'
  putStrLn $ show o