func main() {
let n = Int(readLine()!)!
var A = readLine()!.split(separator: " ").map{Int($0)!}

let q = Queue(2*n, 0)
A.sort{$0>$1}

q.enque(A[0])
var sum = 0
for i in 1..<A.count {
	q.enque(A[i])
	q.enque(A[i])
	sum += q.dequeue()
}
print(sum)
}
main()

class Queue<T> {
	private var q: [T]
	private var head = 0
	private var index = 0
	init(_ max: Int, _ defaultValue: T){
		q = Array(repeating: defaultValue, count: max)
	}

	func enque(_ value: T){
		q[index] = value
		index = (index + 1) % q.count
	}

	func dequeue() -> T {
		let val = q[head]
		head = (head + 1) % q.count
		return val
	}
}
