let hashtbl_incr h key = try incr (Hashtbl.find h key) with Not_found -> Hashtbl.add h key (ref 1);; let total = Hashtbl.create 100003;; let space = Str.regexp " +" in try while true do List.iter (hashtbl_incr total) (Str.split space (read_line ())) done with End_of_file -> ();; let words = List.sort String.compare (Hashtbl.fold (fun x y z -> x :: z) total []);; List.iter (fun x -> Printf.printf "%s %d\n" x !(Hashtbl.find total x)) words;;