data = {}

gets(nil).split("\n").each do |line|
  word, page = line.split(' ')
  data[word] = [] unless data[word]
  data[word].push page.to_i
end

data.sort.each do |word, pages|
  puts word
  puts pages.sort.join(' ')
end