import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    string line;
    string[] words;
    int[][string] map;
    while (true) {
        line = readln;
        if (line.empty) break;
        line = line.chomp;
        string[] _ = line.split(" ").array;
        string word = _[0];
        int page = _[1].to!int;
        words ~= word;
        map[word] ~= page;
    }
    words = words.sort.uniq.array;
    foreach (word; words) {
        writeln(word);
        writefln("%(%s %)", map[word].sort);
    }

}