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::fmt::*;
use std::io::Write;
use std::io::*;

trait MyRead {
    fn read_one<T: FromStr>(&mut self) -> Option<T>;
    fn r<A: FromStr>(&mut self) -> A;
    fn r2<A: FromStr, B: FromStr>(&mut self) -> (A, B);
    fn r3<A: FromStr, B: FromStr, C: FromStr>(&mut self) -> (A, B, C);
    fn r4<A: FromStr, B: FromStr, C: FromStr, D: FromStr>(&mut self) -> (A, B, C, D);
    fn rn<A: FromStr>(&mut self, n: usize) -> Vec<A>;
}
impl<'a> MyRead for BufReader<StdinLock<'a>> {
    fn read_one<T: FromStr>(&mut self) -> Option<T> {
        let s = self.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 r<A: FromStr>(&mut self) -> A {
        self.read_one().unwrap()
    }
    fn r2<A: FromStr, B: FromStr>(&mut self) -> (A, B) {
        (self.r(), self.r())
    }
    fn r3<A: FromStr, B: FromStr, C: FromStr>(&mut self) -> (A, B, C) {
        (self.r(), self.r(), self.r())
    }
    fn r4<A: FromStr, B: FromStr, C: FromStr, D: FromStr>(&mut self) -> (A, B, C, D) {
        (self.r(), self.r(), self.r(), self.r())
    }
    fn rn<A: FromStr>(&mut self, n: usize) -> Vec<A> {
        (0..n).map(|_| self.r()).collect()
    }
}

trait MyWrite {
    fn print<A: Display>(&mut self, a: &A);
    fn p<A: Display>(&mut self, a: &A);
    fn p2<A: Display, B: Display>(&mut self, a: &A, b: &B);
    fn p3<A: Display, B: Display, C: Display>(&mut self, a: &A, b: &B, c: &C);
    fn p4<A: Display, B: Display, C: Display, D: Display>(&mut self, a: &A, b: &B, c: &C, d: &D);
    fn pns<A: Display>(&mut self, v: &Vec<A>);
    fn pnl<A: Display>(&mut self, v: &Vec<A>);
}
impl<'a> MyWrite for BufWriter<StdoutLock<'a>> {
    fn print<A: Display>(&mut self, a: &A) {
        write!(self, "{}", a).ok();
    }
    fn p<A: Display>(&mut self, a: &A) {
        self.print(a);
        self.print(&'\n');
    }
    fn p2<A: Display, B: Display>(&mut self, a: &A, b: &B) {
        self.print(a);
        self.print(&' ');
        self.p(b);
    }
    fn p3<A: Display, B: Display, C: Display>(&mut self, a: &A, b: &B, c: &C) {
        self.print(a);
        self.print(&' ');
        self.p2(b, c);
    }
    fn p4<A: Display, B: Display, C: Display, D: Display>(&mut self, a: &A, b: &B, c: &C, d: &D) {
        self.print(a);
        self.print(&' ');
        self.p3(b, c, d);
    }
    fn pns<A: Display>(&mut self, v: &Vec<A>) {
        let n = v.len();
        for (i, x) in v.iter().enumerate() {
            if i + 1 == n {
                self.p(x);
            } else {
                self.print(x);
            }
        }
    }
    fn pnl<A: Display>(&mut self, v: &Vec<A>) {
        v.iter().map(|x| self.p(x)).count();
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(|| {
            let cin = std::io::stdin();
            let mut cin = BufReader::new(cin.lock());
            let cout = std::io::stdout();
            let mut cout = BufWriter::new(cout.lock());
            solve(&mut cin, &mut cout)
        })
        .unwrap()
        .join()
        .unwrap();
}

use std::collections::*;

fn solve<R: MyRead, W: MyWrite>(cin: &mut R, cout: &mut W) {
    while let Some(s) = cin.read_one::<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 mut ans: Vec<u8> = Vec::new();
        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 {
                    ans.push(c);
                    cur = i + 1;
                    break;
                }
            }
        }

        cout.p(&ans.iter().map(|&c| (c + b'a') as char).collect::<String>());
    }
}