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: Wrong Answer)

#include <cstdio>
#include <cstring>

char A[200010];
int AL;
int nxt[200010][26];
int pos[200010];
int posL;
char res[200010];
int resL;

void solve()
{
	int i, j;
	int xt[26];
	for(i=0; i<26; i++)
		xt[i] = -1;
	AL = strlen(A);
	for(i=AL-1; i>=0; i--){
		for(j=0; j<26; j++){
			nxt[i][j] = xt[j];
			xt[A[i]-'a'] = i;
		}
	}
	
	int cnt[26];
	for(i=0; i<26; i++)
		cnt[i] = 0;
	posL = 0;
	for(i=AL-1; i>=0; i--){
		cnt[A[i]-'a'] ++;
		for(j=0; j<26; j++){
			if(cnt[j] == 0)
				break;
		}
		if(j == 26){
			pos[posL] = i;
			posL ++;
			for(j=0; j<26; j++)
				cnt[j] = 0;
		}
	}
	
	resL = posL+1;
	for(i=0; i<26; i++)
		cnt[i] = 0;
	for(i=pos[posL-1]-1; i>=0; i--){
		cnt[A[i]-'a'] ++;
	}
	for(i=0; i<26; i++){
		if(cnt[i] == 0){
			res[0] = 'a' + i;
			break;
		}
	}
	int p1, p2;
	if(resL > 1){
		if(A[0]==res[0])
			p1 = 0;
		else
			p1=nxt[0][res[0]-'a'];
		for(i=1; i<resL-1; i++){
			for(j=0; j<26; j++){
				p2 = nxt[p1][j];
				if(p2 >= pos[posL-1-i])
					break;
			}
			res[i] = 'a' + j;
			p1 = p2;
		}
	}
	else{
		p1 = -1;
	}
	for(i=0; i<26; i++){
		cnt[i] = 0;
	}
	for(i=p1+1; i<AL; i++){
		cnt[A[i]-'a'] ++;
	}
	for(i=0; i<26; i++){
		if(cnt[i] == 0)
			break;	
	}
	res[resL-1] = 'a' + i;
	res[resL] = 0;
	printf("%s\n", res);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	scanf("%s", A);
	solve();
	return 0;
}