poj3252
poj-3252
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
typedef long long LL;
int main()
{
priority_queue<LL, vector<LL>, greater<LL> >q;
int n;
scanf("%d", &n);
while(n--)
{
LL t;
scanf("%lld", &t);
q.push(t);
}
LL cost = 0;
while(q.size() > 1)
{
LL a = q.top(); q.pop();
LL b = q.top(); q.pop();
cost += (a + b);
q.push(a + b);
}
printf("%lld\n", cost);
return 0;
}