indices = Hash.new
 
readlines.each do |l|
    word, page = l.chomp.split
    if indices.has_key?(word)
        indices[word] << page.to_i
    else
        indices[word] = [page.to_i]
    end
end
 
indices.sort.each do |word,pages| 
    puts word
    puts pages.sort.join(' ')
end