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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>

using namespace std;

int const N = 1234567;

int s[N], ans[N];
int z[N];

int was[42];

int main() {
  int c = getchar();
  int n = 0;
  while (c <= 32) c = getchar();
  while (c > 32) {
    s[n++] = c - 'a';
    c = getchar();
  }
  std::reverse(s, s + n);
  int pos = 0;
  int ac = 0;
  int have = 0;
  while (true) {
    int cn = 0;
    for (int i = 0; i < 26; i++) was[i] = 0;
    while (cn < 26 && pos < n) {
      if (!was[s[pos]]) {
        was[s[pos]] = true;
        cn++;
      }
      pos++;
    }
    z[have++] = pos;
    // printf("pos = %d\n", pos);
    if (cn == 26) {
      // ans[ac++] = s[pos - 1];
    } else {
      // for (int i = 0; i < 26; i++) {
      //   if (!was[i]) {
      //     ans[ac++] = i;
      //     break;
      //   }
      // }
      break;
    }
  }
  pos = n - 1;
  for (int i = 0; i < 26; i++) {
    if (!was[i]) {
      ans[ac++] = i;
      break;
    }
  }
  for (int i = have - 2; i >= 0; i--) {
    while (pos >= 0 && s[pos] != ans[ac - 1]) --pos;
    // printf("%d\n", pos);
    --pos;
    for (int j = 0; j < 26; j++) {
      was[j] = 0;
    }
    int to = i == 0 ? 0 : z[i - 1];
    while (pos >= to) was[s[pos--]] = 1;
    bool found = false;
    for (int j = 0; j < 26; j++) {
      if (!was[j]) {
        ans[ac++] = j;
        found = true;
        break;
      }
    }
    assert(found);
  }
  for (int i = 0; i < ac; i++) putchar('a' + ans[i]);
  puts("");
}