
import std.stdio, std.typecons, std.conv;
import std.algorithm, std.array, std.string;

alias Tuple!(string, "name", int[], "pages") Word;

void main() {
  Word[string] table;
  int num; string str;
  while(readf("%s %d\n", &str, &num)) {
    if (str in table)
      table[str].pages ~= num;
    else 
      table[str] = Word(str, [num]);
  }
  Word[] words = table.values.array;
  words.sort!((x, y) => x.name < y.name);
  foreach(word; words) {
    sort(word.pages);
    writeln(word.name);
    word.pages.map!(to!(string)).join(" ").writeln;
  }
}