def main(input = STDIN)
  while (n = gets.to_i) != 0
    array = []
    n.times do
      array << gets.to_i
    end
    sum = 0
    array.sort.reverse.each_with_index{|i, idx|sum += idx * i}
    puts sum
  end
end
main