h = {}

while line = gets
  key, value = line.chomp.split
  h[key] ? h[key] << value.to_i : h[key] = [value.to_i]
end

h.each do |k, v|
  h[k].sort!
end

h.sort.each do |str, arr|
  puts str, arr.join(" ")
end