function Main(input) {
    input = input.trim().split('\n');
    //const n = parseInt(input[0], 10);
    const a = input[1].split(' ').sort((a,b) => parseInt(b, 10) - parseInt(a, 10));
    const ring = [];
    let sum = 0;

    a.forEach((el, idx) => {
        let maxComfort = 0;
        let center, left, right, comfort;
        let ins;
        if(idx === 0) {
            ring.push(parseInt(el, 10));
            return;
        }
        if(ring.length % 2 === 0){
            center = ring.length/2;
            left = ring[center-1];
            right = ring[center];
            comfort = left > right ? right : left;
            if(maxComfort < comfort){
                maxComfort = comfort;
                ins = center;
            }
        }else if(idx !== 1){
            center = Math.floor(ring.length/2);
            left = ring[center-1];
            right = ring[center];
            comfort = left > right ? right : left;
            if(maxComfort < comfort){
                maxComfort = comfort;
                ins = center;
            }

            center = Math.ceil(ring.length/2);
            left = ring[center-1];
            right = ring[center];
            comfort = left > right ? right : left;
            if(maxComfort < comfort){
                maxComfort = comfort;
                ins = center;
            }
        }
        left = ring[ring.length -1];
        right = ring[0];
        comfort = left > right ? right : left;
        if(maxComfort < comfort){
            maxComfort = comfort;
            ins = ring.length;
        }
        ring.splice(ins, 0, parseInt(el, 10));
        sum += maxComfort;
    });
    console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));