文件目录

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, a;
    cin >> n;
    priority_queue<int, vector<int>, greater<int>> pq; // 小顶堆
    while (n--)
    {
        cin >> a;
        pq.push(a);
    }
    int sum = 0;
    while (pq.size() != 1)
    {
        int fir = pq.top();
        pq.pop();
        int sec = pq.top();
        pq.pop();
        int thi = fir + sec;
        sum += thi;
        pq.push(thi);
    }
    cout << sum;
    return 0;
}