#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(void){
	
	vector<int> cus;
	vector<int> wait;
	int i=0,n,sum=0,temp=0,num;

	cin>>num;

	for(int k=0;k<num;k++){
		
		cin>>n;
		if(i>1000||n==0){
			break;
		}
		cus.push_back(n);
		i++;
	}
	
	sort(cus.begin(),cus.end());

	for(unsigned int k=0;k<cus.size();k++){
		for(unsigned int m=0;m<k;m++){
			temp=temp+cus[m];
		}
		wait.push_back(temp);
		temp=0;
	}
	
	for(unsigned int k=0;k<wait.size();k++){
		sum=sum+wait[k];
	}
	cout<<sum<<endl;
}