#include<cstdio> #include<algorithm> using namespace std; int main(){ int n,a[10000]; while (scanf("%d", &n) != EOF){ if (n == 0){ break; } for (int i = 0; i < n; i++){ scanf("%d", &a[i]); } sort(a, a + n); int sum = 0; for (int i = 1; i < n; i++){ a[i] = a[i] + a[i - 1]; sum = sum + a[i]; sort(a + i, a + n); } printf("%d\n", sum); } }