loop do
  n = gets.to_i
  break if n==0
  ts = Array.new
  n.times{
    ts << gets.to_i
  }
  p 0 if n==1
  ts.sort!
  wt = (0..n-2).inject([0]){|seq,i| seq<<(seq[i]+ts[i])}
  total = wt.inject{|x,y| x+y}
  puts total
end