#!/usr/local/bin/perl

$linenum = 0;
while ($line = <STDIN>) {
        $linenum += 1;
        $line =~ s/^\s+|\s+$//g;
        @words = split(/\s+/, $line);
        # This program uses a trick: for each word, the
        # array
        # item $index{"word"} stores the number of
        # occurrences
        # of that word. Each occurrence is stored in the
        # element
        # $index{"word#n"}, where n is a positive integer.
        if ($words[0] eq "index") {
                if ($index{$words[1]} eq "") {
                        $index{$words[1]} = 1;
                        $occurrence = 1;
                } else {
                        $index{$words[1]} += 1;
                        $occurrence = $index{$words[1]};
                }
                $index{$words[1]."#".$occurrence} =
                        $linenum;
        }
}

# The loop that prints the index takes advantage of the fact
# that, when the list is sorted, the elements that count
# occurrences are always processed just before the
# corresponding elements that store occurrences. For
# example:
# $index{word}
# $index{word#1}
# $index{word#2}
foreach $item (sort keys (%index)) {
        if ($item !~ /#/) {
                print ("\n$item:");
        } else {
                print (" $index{$item}");
        }
}
print ("\n");
