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;
        if(idx === 0) {
            ring.push(parseInt(el, 10));
            return;
        }
        let j = 0;
        for(let i=0; i<ring.length; i++){
            let left = ring[i];
            let right = ring[i+1] ? ring[i+1] : ring[0];
            let comfort = left > right ? right : left;
            if(maxComfort < comfort) {
                maxComfort = comfort;
                j = i;
            }
        }
        ring.splice(j+1, 0, parseInt(el, 10));
        sum += maxComfort;
    });
    console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));