import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val a = new Array[Long](N+1)
  for (i <- 1 to N)
    a(i) = in.next().toLong

  val pq = new PriorityQueue[Long]()(Ordering.Long.reverse)
  for (i <- 1 to N)
    pq.enqueue(a(i))

  var ans = 0L
  breakable {
    while (true) {
      val e1 = pq.dequeue()
      if (pq.isEmpty)
        break
      else {
        val e2 = pq.dequeue()
        val now = e1 + e2
        ans += now
        pq.enqueue(now)
      }
    }
  }

  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
