import Foundation

func main(){
   let n = Int(readLine()!)!
   let aArray = (readLine()!).split(separator: " ").map({ Int($0)! }).sorted(by: { $0 > $1})
   
   guard aArray.count > 1 else { print(0); return}
   var answer = aArray[0]
   
   var count = 0
   var j = 1
   var i = 1
   while i < n - 1 {
      if count < 2 {
         answer += aArray[i]
         count += 1
      } else {
         j += 1
         count = 1
         answer += aArray[i]
      }
      i += 1
   }
   
   print(answer)
}
main()