while true
    n = gets.to_i
    break if n == 0
    arr = []
    n.times{arr << gets.to_i}
    arr.sort!
    1.upto(n-1){|i| arr[i] += arr[i - 1]}
    sum = 0
    arr[0..-2].each{|x| sum += x}
    puts sum
end

