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)

#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

char A[200000];
int group[200000];
vector<int> index_list[26];

signed main()
{
	cin >> A;
	int len = strlen(A);

	int cnt = 0;
	int g = 0;

	bool flg[26] = {};
	for (int i = len - 1; i >= 0; i--)
	{
		char n = A[i] - 'a';
		index_list[n].push_back(i);
		if (!flg[n])
		{
			cnt++;
		}
		flg[n] = true;
		group[i] = g;
		if (cnt == 26)
		{
			memset(flg, 0, sizeof(flg));
			cnt = 0;
			g++;
		}
	}

	for (int c = 0; c < 26; c++)
	{
		REVERSE(index_list[c]);
	}

	string ans = "";
	int index = -1;

	for (int i = g; i >= 0; i--)
	{
		for (int c = 0; c < 26; c++)
		{
			auto it = UPPER_BOUND(index_list[c], index);
			if (i > 0)
			{
				int n = *it;
				int gg = group[n];
				if (gg == i - 1)
				{
					ans += (char)(c + 'a');
					index = n;
					break;
				}
			}
			else
			{
				if (it == index_list[c].end())
				{
					ans += (char)(c + 'a');
					break;
				}
			}
		}
	}

	cout << ans << endl;
}