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
	pages.sort.each_with_index {|p,i| print (i==0 ? "#{p}" : " #{p}")}
	puts ""
end