let () =
  let comp x y =
    let s = String.compare (fst x) (fst y) in
    if s = 0 then
      if (snd x) > (snd y) then 1 else -1
    else
      s
  in
  let rec read h =
    try let (x,y) = Scanf.scanf " %s %d\n" (fun x y -> (x,y)) in
        read ((x,y)::h)
    with End_of_file -> h
  in
  let l = read [] in
  let sorted = List.sort comp l in
  let rec loop prev = function
      [] -> print_newline ()
    | h::tl ->
       if prev = (fst h) then
         Printf.printf " %d" (snd h)
       else
         begin
           if prev != "" then Printf.printf "\n" else ();
           Printf.printf "%s\n%d" (fst h) (snd h)
         end;
       loop (fst h) tl

  in loop "" sorted
;;