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



int main(){
	int n,tmp;
	vector<int> v;
	cin>>n;
	for(int i = 0; i < n; i++){
		cin>>tmp;
		v.push_back(tmp);
	}   
	
	int sum = 0,ans = 0,a,b;            
	while(v.size() > 1){
		sort(v.begin(),v.end());
		a = v[0];
		b = v[1];
		v.erase(v.begin(),v.begin()+2);
		sum = a + b;
		ans += sum; 
		v.push_back(sum);

	}          
	cout<<ans;                                                                               
}