hash = Hash.new {|hash, key| hash[key] = []}
while (str = gets) != nil
  word, page = str.split
  hash[word] << page.to_i
end
hash.values.each {|item| item.sort!}
hash = Hash[hash.sort]
hash.each {|k, v| puts k, v.join(" ")}