const main = (input) => {
  const maxIdx = (arr) => {
    let max = -1
    let idx = -1
 
    for (let i=0; i<arr.length; i++) {
      if (arr[i] > max) {
        max = arr[i]
        idx = i
      }
    }
 
    return idx
  }
 
  input = input.trim().split('\n')
  const nums = input[1].split(' ').map(Number).sort((a, b) => b - a)
 
  let r = [nums.shift()]
 
  let ans = 0
  while (nums.length) {
    const n = nums.shift()
 
    const i = maxIdx(r)
    ans += r[i]
 
    r = [...r.slice(0, i), n, n, ...r.slice(i+1)]
  }
 
  return console.log(ans)
}
 
process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))