while True:
n= int(input())
if n==0:break
A=list(map(int,input().split()))
tmp=[]
while len(A)>=2:
res=0;A.sort()
for _ in range(2):
res+=A.pop(0)
tmp.append(res)
A.insert(0,res)
print(sum(tmp))