#include <stdio.h>

int main(void)
{
	long int a[10000];
	int i, j;
	int n;
	int m;
	int t;
	long int total;
	
	while (scanf("%d", &n), n != 0){
		
		for (i = 0; i < n; i++){
			scanf("%d", &a[i]);
		}
		for (i = 0; i < n; i++){
			m = i;
			for (j = i; j < n; j++){
				if (a[m] > a[j]){
					m = j;
				}
			}
			t = a[i];
			a[i] = a[m];
			a[m] = t;
		}
		total = 0;
		for (i = 0; i < n - 1; i++){
			a[i + 1] += a[i];
		}
		for (i = 0; i < n - 1; i++){
			total += a[i];
		}
		printf("%ld\n", total);
	}
	return (0);
}