#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <iterator>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <climits>
#include <cassert>
#define BUG puts("here!!!");
using namespace std;
struct Node {
long long w;
bool operator < (const Node &a) const {
return w > a.w;
}
}tmp;
int main() {
int T;
priority_queue<Node> Q;
scanf("%d", &T);
while(T--) {
scanf("%lld", &tmp.w);
Q.push(tmp);
}
long long a, b, ans = 0;
while(Q.size() > 1) {
a = Q.top().w; Q.pop();
b = Q.top().w; Q.pop();
tmp.w = a+b;
Q.push(tmp);
ans += tmp.w;
}
cout << ans << endl;
return 0;
}
10-18