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)

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

fn main() {
    let a = util::line();

    let mut positions: Vec<Vec<usize>> = vec![Vec::new(); 26];

    for (i, c) in a.chars()
        .map(|c| (c as u8 - 'a' as u8) as usize)
        .enumerate()
    {
        positions[c].push(i);
    }

    let a: Vec<usize> = (1..)
        .flat_map(move |l| {
            (0..26usize.pow(l.clone() as u32)).map(move |d| {
                let mut v = Vec::new();
                let mut d = d;
                while d > 0 {
                    v.push(d % 26);
                    d = d / 26;
                }
                while v.len() < l {
                    v.push(0)
                }
                v.into_iter().rev().collect::<Vec<_>>()
            })
        })
        .find(|v| {
            let mut last = 0;
            for &c in v.iter() {
                let pc = &positions[c];
                match pc.binary_search(&last) {
                    Ok(i) => last = pc[i] + 1,
                    Err(i) => {
                        if i >= positions[c].len() {
                            return true;
                        } else {
                            last = pc[i] + 1;
                        }
                    }
                }
            }
            false
        })
        .unwrap();

    println!(
        "{}",
        a.iter()
            .map(|&c| ('a' as u8 + c as u8) as char)
            .collect::<String>()
    );
}