#include <bits/stdc++.h>
#define READ freopen ("input.txt","r",stdin)
#define nnn 20
using namespace std;
typedef long long ll;
typedef vector < int > vi;
int main()
{
//READ;
priority_queue<int>A;
int n;
while(scanf("%d",&n)==1&&n)
{
for(int i=0; i<n; i++)
{
int x;
scanf("%d",&x);
A.push(-x);
}
ll sum=0;
while(A.size()>1)
{
int p=A.top();
A.pop();
int q=A.top();
A.pop();
sum+=(ll)(abs(p)+abs(q));
A.push(-1*(abs(p)+abs(q)));
// cout<<A.top()<<endl;
}
cout<<sum<<endl;
while(!A.empty()) A.pop();
}
return 0;
}
#define READ freopen ("input.txt","r",stdin)
#define nnn 20
using namespace std;
typedef long long ll;
typedef vector < int > vi;
int main()
{
//READ;
priority_queue<int>A;
int n;
while(scanf("%d",&n)==1&&n)
{
for(int i=0; i<n; i++)
{
int x;
scanf("%d",&x);
A.push(-x);
}
ll sum=0;
while(A.size()>1)
{
int p=A.top();
A.pop();
int q=A.top();
A.pop();
sum+=(ll)(abs(p)+abs(q));
A.push(-1*(abs(p)+abs(q)));
// cout<<A.top()<<endl;
}
cout<<sum<<endl;
while(!A.empty()) A.pop();
}
return 0;
}