import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    val b = new ArrayBuffer[Int]
    Iterator.continually(readLine).takeWhile(_.trim!="0").foreach { s =>
      val n = s.trim.toInt
      var total = 0
      val line = { for(i<-1 to n) yield readInt }.toArray.sorted
      val t = (for(i<- 0 until n-1) yield { total += line(i);total }).sum
      b.append(t)
    }
    println(b.mkString("\n"))
  }
}