module StringMap = Map.Make (String)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let ss = Array.init n @@ fun _ -> Scanf.scanf "%s\n" @@ fun s -> s in
  List.iter print_endline @@
  List.rev @@
  fst @@
  List.fold_left (fun (ss, n) (s, m) ->
    if n < m
    then ([s], m)
    else if n = m then (s :: ss, n)
    else (ss, n)) ([], 0) @@
  StringMap.bindings @@
  Array.fold_left (fun m s ->
    StringMap.add s (1 + try StringMap.find s m with Not_found -> 0) m) StringMap.empty ss