#define scanf_s scanf
//#define sscanf_s sscanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 1001
#define _MAX 10
#define HO 6
int main(void)
{
	while (1) {
		int n, ti[61] = { 0 }, t,sum = 0,sum_2 = 0,a;
		scanf_s("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < n; ++i) {
			scanf_s("%d", &t);
			++ti[t];
		}
		for (int i = 1; i <= 60; ++i) {
			if (ti[i] != 0) {
				sum_2 += sum;
				sum += (ti[i] * i);
				if (ti[i] > 1) {
					 a = (ti[i] + 1) * (ti[i] / 2) + ((ti[i] % 2) * (ti[i] / 2 + 1));
					 printf("%d %d %d ", sum_2 * ti[i],a, a*i);
					 sum_2 += (sum_2 * ti[i]) + (a * i) - sum;
				}
			}
		}
		printf("%d\n", sum_2);
	}
}