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: Runtime Error)

#include <bits/stdc++.h>
using namespace std;
char s[2050000];
bool vis[26];
int cnt=0;
int dp[2050000];
char ans[2050000];
int tot=0;
int main(){
	memset(ans, 0, sizeof(ans));
	scanf("%s", s+1);
	int n=strlen(s+1);
	reverse(s+1, s+1+n);
	dp[0]=1;
	for(int i=1;s[i];i++){
		if(!vis[s[i]-'a']){
			vis[s[i]-'a']=true;
			cnt++;
			if(cnt==26){
				memset(vis, false, sizeof(vis));
				cnt=0;
				dp[i]=dp[i-1]+1;
				continue;
			}
		}
		dp[i]=dp[i-1];
	}
	memset(vis, false, sizeof(vis));
	if(dp[n]!=dp[n-1]){
		for(int i=1;i<=dp[n];i++)printf("a");
		printf("\n");
	}
	else{
		int tot=0;
		for(int i=n;i>=1;i--){
			if(dp[i]!=dp[i-1]){tot=i;break;}
			vis[s[i]-'a']=true;
		}
		int last=0;
		for(int i=0;i<26;i++)if(!vis[i]){
			ans[dp[n]]=i+'a';
			last=i;
			break;
		}
		memset(vis, false, sizeof(vis));
		for(int i=tot, j=dp[n]-1;i>=1;i--){
			if(s[i]-'a'==last){
				memset(vis, false, sizeof(vis));
				int cnt=0;
				while(i&&dp[i]==dp[i-1]){
					if(cnt!=0)vis[s[i]-'a']=1;
					cnt++;
					i--;
				}
				for(int k=0;k<26;k++){
					if(!vis[k]){
						ans[j]=k+'a';
						last=k;
						break;
					}
				}
				j--;
				i++;
			}
		}

		for(int i=dp[n];i>=1;i--)printf("%c", ans[i]);
		printf("\n");
	}
}