Problem:
Score : 600 points

Problem Statement

A subsequence of a string S is a string that can be obtained by deleting zero or more characters from S without changing the order of the remaining characters.
For example, arc, artistic and (an empty string) are all subsequences of artistic; abc and ci are not.

You are given a string A consisting of lowercase English letters.
Find the shortest string among the strings consisting of lowercase English letters that are not subsequences of A.
If there are more than one such string, find the lexicographically smallest one among them.

Constraints

1 \leq |A| \leq 2 \times 10^5

A consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

A

Output

Print the lexicographically smallest string among the shortest strings consisting of lowercase English letters that are not subsequences of A.

Sample Input 1

atcoderregularcontest

Sample Output 1

b

The string atcoderregularcontest contains a as a subsequence, but not b.

Sample Input 2

abcdefghijklmnopqrstuvwxyz

Sample Output 2

aa

Sample Input 3

frqnvhydscshfcgdemurlfrutcpzhopfotpifgepnqjxupnskapziurswqazdwnwbgdhyktfyhqqxpoidfhjdakoxraiedxskywuepzfniuyskxiyjpjlxuqnfgmnjcvtlpnclfkpervxmdbvrbrdn

Sample Output 3

aca

Solution in OCaml (4.02.3) (judge verdict: Accepted)

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) (0, []) in
  for i = String.length a downto 0 do
    dp.(i) <-
      List.fold_left min (max_int, []) @@
      List.map (fun c ->
        match dp.(CharMap.find c trie.(i)) with
        | exception Not_found -> (1, [c])
        | (n, s) -> (1 + n, c :: s)) alphabet
  done;
  List.iter print_char (snd dp.(0));
  print_newline ()