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(), nums.shift()];
    var result = al[0];

    if (num === 2) {
        console.log(result);
        return;
    }

    al.push(nums.shift());
    result += al[1];

    if (num === 3) {
        console.log(result);
        return;
    }

    for(let i = 0; i < num - 3; i++) {
        const length = al.length;
        let max = 0;
        let index = 0;

        for (let j = 0; j < length; j++) {
            let a1;
            let a2 = al[i];

            if (j === 0) {
                a1 = al[length - 1];
            } else {
                a1 = al[j - 1];
            }

            if (a2 === a1) {
                max = al[1];
                index = j;
                break;
            } else {
                var sub = Math.min(a1, a2);

                if (sub > max) {
                    max = sub;
                    index = j;
                }
            }
        }

        result += max;
        al.splice(index, 0, nums.shift());
    }

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