#include <stdio.h>

void mergesort(int nx, int ny, int *x)
{
	int i, j, k;
	int a[10010];
	
	for (i = 0; i < nx; i++){
		a[i] = *(x + i);
	}
	if (nx > 1){
		mergesort(nx / 2, nx - nx / 2, a);
	}
	for (i = 0; i < ny; i++){
		a[nx + i] = *(x + (nx + i));
	}
	if (ny > 1){
		mergesort(ny / 2, ny - ny / 2, a + nx);
	}
	
	i = 0;
	j = 0;
	k = 0;
	while (k < nx + ny){
		if (a[i] < a[nx + j] && i < nx || j == ny){
			*(x + k) = a[i];
			i++;
		}
		else {
			*(x + k) = a[nx + j];
			j++;
		}
		k++;
	}
}

int main(void)
{
	int i;
	int n;
	int t[1024];
	int w;
	int total;
	
	while (scanf("%d", &n), n != 0){
		
		for (i = 0; i < n; i++){
			scanf("%d", &t[i]);
		}
		
		mergesort(n / 2, n - n / 2, t);
		
		total = 0;
		w = 0;
		for (i = 0; i < n; i++){
			total += w;
			w += t[i];
		}
		printf("%d\n", total);
		
	}
	return (0);
}