function D173(_input) {
    var lines = _input.split("\n");
    var num = lines.shift()*1;
    var nums = lines[0].split(' ').map(v => v*1).sort((v1, v2) => v2 - v1);
    var al = [nums.shift()];
    var result = 0;

    for(let i = 0; i < num - 1; i++) {
        const t = nums.shift();
      
        if (al.length > 1) {
            result += al[1];
        } else {
            result += al[0];
            al.push(t);
        }
    }

    console.log(result);
}
D173(require("fs").readFileSync("/dev/stdin", "utf8"));
