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 Common Lisp (SBCL 1.1.14) (judge verdict: Accepted)

;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (ql:quickload '(:cl-debug-print :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (declare #.OPT)
  (let* ((s (read-line))
         (n (length s))
         (nexts (make-array (list n 26) :element-type 'uint32))
         (dp (make-array (+ n 1) :element-type 'uint32))
         (seqs (make-array (+ n 1) :element-type 'list)))
    (declare ((simple-array character (*)) s)
             (uint31 n))
    (let ((table (make-array 26 :element-type 'uint32 :initial-element n)))
      (loop for i from (- n 1) downto 0
            do (setf (aref table (- (char-code (aref s i)) 97)) i)
               (dotimes (c 26)
                 (setf (aref nexts i c) (aref table c)))))
    (setf (aref dp n) 1)
    (setf (aref seqs n) (list #\a))
    (loop for i from (- n 1) downto 0
          for res = #xffffffff
          do (dotimes (c 26)
               (if (= n (aref nexts i c))
                   (when (< 1 res)
                     (setf res 1)
                     (setf (aref seqs i) (list (code-char (+ c 97)))))
                   (let ((new-value (+ 1 (aref dp (+ 1 (aref nexts i c))))))
                     (when (< new-value res)
                       (setf res new-value)
                       (setf (aref seqs i)
                             (cons (code-char (+ c 97))
                                   (aref seqs (+ 1 (aref nexts i c)))))))))
             (setf (aref dp i) res))
    (dolist (c (aref seqs 0))
      (write-char c))
    (terpri)))

#-swank (main)