exception Solved of string

module CharMap = Map.Make (Char)

let alphabet =
  [ 'a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'; 'i'; 'j'; 'k'; 'l'; 'm';
    'n'; 'o'; 'p'; 'q'; 'r'; 's'; 't'; 'u'; 'v'; 'w'; 'x'; 'y'; 'z']

let () =
  let a = read_line () in
  let trie = Array.make (String.length a + 1) CharMap.empty in
  for i = String.length a - 1 downto 0 do
    trie.(i) <- CharMap.add a.[i] (i + 1) trie.(i + 1)
  done;
  let dp = Array.make (String.length a + 1) "" in
  for i = String.length a downto 0 do
    dp.(i) <-
      List.fold_left (fun s s' ->
        if String.length s < String.length s' then s
        else if String.length s' < String.length s then s'
        else min s s') a @@
    List.map (fun c ->
      String.make 1 c ^
      try dp.(CharMap.find c trie.(i))
      with Not_found -> "") alphabet
  done;
  print_endline dp.(0)
