```#include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
int main()
{
int n;
scanf(“%d”,&n);
int x;
priority_queue[HTML_REMOVED],greater[HTML_REMOVED]> heap;
while (n–)
{
scanf(“%d”,&x);
heap.push(x);
}
int res=0;
while(heap.size()>1)
{
int a=heap.top();
heap.pop();
int b=heap.top();
heap.pop();
res+=a+b;
heap.push(a+b);
}
cout << res <<endl;
return 0;
}
```