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::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;

struct State {
    s: String,
    v: usize,
}

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

    let mut graph = (0..(n + 2)).map(|_| { Vec::new() }).collect::<Vec<_>>();
    let source = n;
    let sink = n + 1;

    for next in 0..26 {
        if pos[next].is_empty() {
            graph[source].push(sink);
        } else {
            let x = pos[next].front().unwrap();
            graph[source].push(*x);
        }
    }

    for i in 0..n {
        let c = (a[i] - 'a' as u8) as usize;
        pos[c].pop_front();
        for next in 0..26 {
            if pos[next].is_empty() {
                graph[i].push(sink);
            } else {
                let x = pos[next].front().unwrap();
                graph[i].push(*x);
            }
        }
    }

    let mut q = VecDeque::new();
    let mut dist = vec![n * 2; n + 2];
    q.push_back(State { s: "".to_owned(), v: source });
    dist[source] = 0;
    while !q.is_empty() {
        let state = q.pop_front().unwrap();
        if state.v == sink {
            println!("{}", state.s);
            return;
        }

        for i in 0..26 {
            let c = (i as u8 + 'a' as u8) as char;
            let next = graph[state.v][i];
            if dist[next] <= dist[state.v] + 1 {
                continue;
            }
            dist[next] = dist[state.v] + 1;
            q.push_back(State { s: state.s.clone() + &c.to_string(), v: next });
        }
    }
}

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()
    }
}