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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.io.*;
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Main().solve();
    }

    final int INF = Integer.MAX_VALUE / 4;

    String s;
    int[][] f;
    void solve() {
        final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try { s = reader.readLine(); } catch (IOException e) {}
        final int N = s.length();
        f = new int[N + 1][26];
        for (int[] f_line : f) Arrays.fill(f_line, INF);
        final int[] last = new int[26]; Arrays.fill(last, INF);
        for (int i = N - 1; i >= 0; i--) {
            char c = s.charAt(i);
            int c_index = (int)(c - 'a');
            last[c_index] = i;
            for (int j = 0; j < 26; j++) {
                f[i][j] = last[j];
            }
        }

        int count = 26;
        int last_char_index = -1;
        boolean[] used = new boolean[N]; Arrays.fill(used, false);
        for (int i = N - 1; i >= 0; i--) {
            char c = s.charAt(i);
            int c_index = (int)(c - 'a');
            if (used[c_index]) continue;
            used[c_index] = true;
            count--;
            if (count == 0) last_char_index = c_index;
        }
        assert last_char_index >= 0;

        int[] g = new int[N]; Arrays.fill(g, INF);
        int[] n = new int[N]; Arrays.fill(n, INF);
        int[] c = new int[N]; Arrays.fill(n, INF);
        for (int i = N - 1; i >= 0; i--) {
            for (int j = 0; j < 26; j++) {
                int k = f[i + 1][j];
                int v = k == INF ? (last_char_index == j ? 2 : 1) : g[k] + 1;
                if (g[i] > v) {
                    g[i] = v;
                    n[i] = k;
                    c[i] = j == last_char_index ? 500 + j : j;
                }
            }
        }
        int i = 0;
        final StringBuilder builder = new StringBuilder();
        while (i < N) {
            int j = c[i];
            if (j >= 500) {
                builder.append((char)(j - 500 + 'a'));
                builder.append((char)(j - 500 + 'a'));
            } else {
                builder.append((char)(j + 'a'));
            }
            i = n[i];
        }
        System.out.println(builder.toString());
    }
}