#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
	
	int guest[10001];
	int time[10001] = {0},i = 0;
	
	while(scanf("%d", &guest[i]), guest[i] != 0) i++;
	guest[i++] = 0;
	sort(guest, guest+i);
	
	for(i = 1; guest[i] != 0; i++){
		time[i] = guest[i-1] + time[i-1];
		printf("%d %d\n", guest[i], time[i]);
	}
	
	int time_sum = 0;
	for(i = 2; time[i] != 0; i++){
		time_sum += time[i];
	}
	
	printf("%d\n", time_sum);
	
	return(0);
}