import java.util.*

fun main() {
  val N = readInt()
  val AN = readInts().sortedDescending()

  val queue = PriorityQueue<Int>() { a, b -> b - a }

  var sum = 0L
  fun joinCircle(a: Int) {
    if (queue.isEmpty()) {
      queue.add(a)
    } else {
      val q = queue.poll()
      sum += q
      queue.add(a)
      queue.add(a)
    }
  }

  AN.forEach { joinCircle(it) }
  println(sum)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }
