/**
ソート自体は 100,000要素でもごく短時間で終わる

ランダムな配列の用意:
const as = Array.from(Array(10000).keys()).map(a=>Math.ceil(Math.random()*1000000000))
 */



const main = async () => {
  const input = require('fs').readFileSync('/dev/stdin', 'UTF-8').trim()
  const [hString, aStrings] = input.split('\n')
  const h = Number(hString)
  const as = aStrings.split(' ').map(Number)
  as.sort((a, b) => b - a)

  let sum = 0
  const circle = []

  let digits = 1

  while (as.length) {

    for (let i = 0; i < digits; i++) {
      const a = as.shift()

      const comfortableness = Math.min(
        circle[i * 2 - 1] || circle[circle.length - 1] || 0,
        circle[i * 2] || circle[0] || 0
      )

      circle.splice(i * 2, 0, a)

      sum += comfortableness
      // 0, 2, 4, 6... に splice(i * 2, 0, a)

      if (as.length === 0) {
        break;
      }
    }

    digits++
  }

  console.log(sum)
}

main()