import scala.io.StdIn.{readInt}

object Main {
  def main(args:Array[String]) = {
    Iterator.continually(readInt).takeWhile(_!=0).foreach { n =>
      var s = 0
      val line = { for(i<-1 to n) yield readInt }.toArray.sorted
      val sum = (for(i<- 0 until n-1) yield { s += line(i);s }).sum
      println(sum)
    }
  }
}