const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const lines = input.split('\n')
    const N = lines[0] - 0
    const A = lines[1].split(" ").map(Number)

    A.sort((a, b) => b - a)

    let com = 0
    let b = [A[0], 1]
    for (let i = 1; i < N; i++) {
        if (b[1] > i) {
            com += b[0]
        } else {
            com += A[i - 1]
        }
        if (A[i - 1] !== A[i]) {
            b = [A[i - 1], i * 2]
        }
    }

    console.log(com)

})(input)
