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 Rust (1.15.1) (judge verdict: Accepted)

use std::str::*;
use std::io::*;

fn read<T: FromStr>() -> Option<T> {
    let s = stdin().bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    if s.is_empty() {
        None
    } else {
        s.parse::<T>().ok()
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

use std::collections::*;

fn solve() {
    while let Some(s) = read::<String>() {
        let a = s.bytes().map(|c| c - b'a').collect::<Vec<u8>>();
        let n = s.len();
        let mut pos = vec![vec![]; 26];
        for i in 0..n {
            pos[a[i] as usize].push(i);
        }
        for i in 0..26 {
            pos[i].push(n);
        }

        let mut s = BTreeSet::<u8>::new();
        let mut len = vec![0; n];
        for i in (0..n).rev() {
            s.insert(a[i]);
            if s.len() == 26 {
                len[i] = len[i + 1] + 1;
                s.clear();
            } else if i != n - 1 {
                len[i] = len[i + 1];
            } else {
                len[i] = 1;
            }
        }

        let stdout = stdout();
        let mut buf = BufWriter::new(stdout.lock());
        let mut cur = 0;
        for k in (0..len[0]).rev() {
            for c in 0..26 {
                let ipos = pos[c as usize].binary_search(&cur).unwrap_or_else(|e| e);
                let i = pos[c as usize][ipos];
                let l = if i + 1 < n { len[i + 1] } else { 0 };
                if l == k {
                    write!(&mut buf, "{}", (c + b'a') as char).ok();
                    cur = i + 1;
                    break;
                }
            }
        }
        writeln!(&mut buf, "").ok();
    }
}