#include
#include
#include
#include
using namespace std;
int n;
int main()
{
cin>>n;
priority_queue,greater>heap;
for(int i=0;i>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<