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)

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub trait BinarySearch<T> {
    fn lower_bound(&self, &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}

fn main() {
    let a = read::<String>()
        .chars()
        .map(|x| x.to_digit(36).unwrap() as usize - 10)
        .collect::<Vec<_>>();

    let n = a.len();

    let mut poses = vec![Vec::new(); 26];
    for (i, &ch) in a.iter().enumerate() {
        poses[ch].push(i);
    }

    let mut dp = vec![std::usize::MAX; n];
    let mut dp_from = vec![std::usize::MAX; n];
    let mut dp_from_ch = vec![std::usize::MAX; n];
    dp[n - 1] = 1;

    for i in (1..n).rev() {
        for ch in 0..26 {
            let pos_idx = poses[ch].lower_bound(&(i));
            if pos_idx == poses[ch].len() {
                if dp[i - 1] > 1 {
                    dp_from[i - 1] = std::usize::MAX;
                    dp_from_ch[i - 1] = ch;
                    dp[i - 1] = 1;
                }
            } else {
                let pos: usize = poses[ch][pos_idx];
                if dp[i - 1] > 1 + dp[pos] {
                    dp[i - 1] = 1 + dp[pos];
                    dp_from[i - 1] = pos;
                    dp_from_ch[i - 1] = ch;
                }
            }
        }
    }

    let mut min_dp = std::usize::MAX;
    let mut min_ch_begin = std::usize::MAX;
    for ch in 0..26 {
        if poses[ch].is_empty() {
            println!("{}", std::char::from_digit(ch as u32 + 10, 36).unwrap());
            return;
        }
        if min_dp > dp[poses[ch][0]] {
            min_dp = dp[poses[ch][0]];
            min_ch_begin = ch;
        }
    }

    let mut ans = vec![min_ch_begin];
    let mut itr = poses[min_ch_begin][0];
    loop {
        ans.push(dp_from_ch[itr]);
        itr = dp_from[itr];
        if itr == std::usize::MAX {
            break;
        }
    }
    println!(
        "{}",
        ans.iter()
            .map(|&x| std::char::from_digit(x as u32 + 10, 36).unwrap())
            .collect::<String>()
    );
}