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)

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let s = sc
        .read::<String>()
        .chars()
        .map(|c| c as usize - 'a' as usize)
        .collect::<Vec<_>>();
    let n = s.len();
    let mut seg_id = vec![0; n];
    let mut cur = 0;
    let mut mask = 0;
    for i in (0..n).rev() {
        mask |= 1 << s[i];
        seg_id[i] = cur;
        if mask == (1 << 26) - 1 {
            mask = 0;
            cur += 1;
        }
    }

    let mut index = vec![vec![]; 26];
    for i in 0..n {
        index[s[i]].push(i);
    }

    for i in 0..26 {
        index[i].reverse();
    }

    let mut cur_pos = 0;
    let mut ans = vec![];
    if mask == 0 {
        match index[0].pop() {
            Some(pos) => {
                ans.push(0);
                cur_pos = pos;
            }
            None => {
                println!("a");
                return;
            }
        }
    } else {
        for i in 0..26 {
            if mask & (1 << i) != 0 {
                continue;
            }
            match index[i].pop() {
                Some(pos) => {
                    ans.push(i);
                    cur_pos = pos;
                    break;
                }
                None => {
                    println!("{}", (i as u8 + 'a' as u8) as char);
                    return;
                }
            }
        }
    }

    loop {
        for i in 0..26 {
            while let Some(pos) = index[i].pop() {
                if pos > cur_pos {
                    index[i].push(pos);
                    break;
                }
            }
        }

        for next in 0..26 {
            match index[next].pop() {
                Some(pos) => {
                    if seg_id[cur_pos] != seg_id[pos] {
                        ans.push(next);
                        cur_pos = pos;
                        break;
                    } else {
                        index[next].push(pos);
                    }
                }
                None => {
                    ans.push(next);
                    for ans in ans.into_iter() {
                        sc.write(format!("{}", (ans as u8 + 'a' as u8) as char));
                    }
                    sc.write("\n");
                    return;
                }
            }
        }
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}