#!/usr/bin/perl -w

use strict;

@ARGV == 0
	or die "syntax: $0 < input > output\n";

my $line;

while (defined ($line = <STDIN>)) {
	chomp $line;
	my @sorted = sort split /\t/, $line, -1;
	my @out;
	my $count = 1;
	my $last = shift @sorted;
	for my $field (@sorted) {
		if ($field eq $last) {
			$count ++;
		} else {
			push @out, $count, $last;
			$count = 1;
			$last = $field;
		}
	}
	push @out, $count, $last;
	print join "\t", @out;
	print "\n";
}
