fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map { Item(it.toInt(), 2) }.sortedByDescending { it.f }

    var max = aa[0].f.toLong()
    var maxIdx = 1

    for (i in 2 until n) {
        if (aa[maxIdx].cnt == 0) {
            maxIdx += 1
        }
        max += aa[maxIdx].f
        aa[maxIdx].cnt--
    }

    println(max)
}

data class Item(val f: Int, var cnt: Int)