object Main extends App {
  import scala.annotation.tailrec
  
  @tailrec
  def solve(a:List[Long],ans:Long):Long = {
    a match {
      case h::t => solve(t.tail.dropRight(1),ans+t.head)
      case _ => ans
    }
  }
 
  val n = readLong
  val a = readLine.split(" ").map{_.toLong}.sortWith{_ >= _}.toList
  println(solve(a,0))
}