import scala.collection.immutable.LinearSeq
import scala.io.StdIn
import scala.collection.mutable.{Map => MMap}


object Main extends App {
  val N = StdIn.readInt()
  val A = StdIn.readLine().split(' ').map(_.toLong)
  val sortedA = A.sortBy(-_)
  var (conf1,conf2):(Long,Long) = (0,0)

  var confSum:Long = 0
  for(a <- sortedA){
    confSum += (if(conf2 == 0) conf1 else conf2)
    if(conf1 <= a){
      conf2 = conf1
      conf1 = a
    }else if(conf2 <= a){
      conf2 = a
    }
  }

  println(confSum)



}
