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: Time Limit Exceeded)

use std::io;
use std::io::{Read, Stdin};
use std::str;
use std::str::FromStr;
use std::usize;
use std::cmp;
use std::fmt::Debug;
use std::i64::MAX;
use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::collections::VecDeque;
use std::collections::BTreeSet;

fn rec(depth: usize, q: &mut VecDeque<u8>, pos: &Vec<Vec<usize>>, n: usize) -> bool {
    if q.len() == depth {
        let mut cur: i32 = -1;
        for p in q.iter() {
            let i = *p as usize;
            //            println!("i={}, cur={}, q={:?}, pos[i]={:?}", i, cur, q, pos[i]);
            match pos[i].binary_search(&((cur + 1) as usize)) {
                Ok(t) => cur = pos[i][t] as i32,
                Err(t) => if t >= pos[i].len() {
                    cur = n as i32;
                } else {
                    cur = pos[i][t] as i32;
//                    println!("cur={}", cur);
                },
            };
            if cur >= n as i32 {
                return true;
            }
        }
        return false;
    }
    for i in 0..26 {
        q.push_back(i);
        if rec(depth, q, pos, n) {
            return true;
        }
        q.pop_back();
    }
    return false;
}


fn main() {
    let mut sc = Scanner::new();
    let a = sc.parse::<String>().into_bytes();
    let mut pos = (0..26).map(|_| {
        Vec::new()
    }).collect::<Vec<_>>();
    for i in 0..a.len() {
        let c = (a[i] - 'a' as u8) as usize;
        pos[c].push(i);
    }

    let mut q = VecDeque::new();
    for i in 0..1000 {
        if rec(i, &mut q, &pos, a.len()) {
            for p in q.iter() {
                print!("{}", (*p + 'a' as u8) as char)
            }
            println!();
            return;
        }
    }
}

struct Scanner {
    stdin: Stdin,
    buf: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            buf: Vec::with_capacity(256),
        }
    }

    fn parse<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let mut it = self.stdin.lock().bytes();
        let mut c = it.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = it.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = it.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse::<T>().unwrap()
    }
}