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: Time Limit Exceeded)

#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const int MOD = 1000000007;
const int LOG = 20;
const int INF = 1000000010;

int n, dp[N][26], DP[N], cnt[N];
string s;
vector<int> ind[26];
string res;
int ans;

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s;
	n = s.size();
	for (int i = 0; i < s.size(); i++){
		ind[s[i] - 'a'].pb(i + 1);
		cnt[s[i] - 'a']++;
		//cout << s[i] - 'a' << '\n';
	}
	for (int i = 0; i < 26; i++){
		if (cnt[i] == 0){ 
			string res = "";
			res += ('a' + i);
			//cout << "YSE" << endl;
			cout << res;
			return 0;
		}
	}
	memset(DP, 31, sizeof DP);
	DP[0] = n + 1;
	ans = INF;
	//cout << "YES" << endl;
	for (int i = 1; i <= n; i++){
		//cout << DP[i - 1] << ' ' << endl;
		for (int j = 0; j < 26; j++){
			int koj = lower_bound(all(ind[j]), DP[i - 1]) - ind[j].begin();
			//cout << i << ' ' << j << ' ' << koj << '\n';
			if (koj == 0){
				ans = min(ans, i);
			}
			else{
				dp[i][j] = ind[j][koj - 1];
				DP[i] = min(DP[i], dp[i][j]);
			}
			//cout << i << ' ' << j << ' ' << dp[i][j] << endl;
		}
	}
	//cout << "YES" << endl;
	int koj;
	for (int i = 0; i < 26; i++){
		int K = lower_bound(all(ind[i]), DP[i - 1]) - ind[i].begin();
		if (K == 0){
			koj = i;
			res += 'a' + i;
			break;
		}
	}
	//cout << res << endl;
	int id;
	for (int i = 0; i < 26; i++){
		int K = lower_bound(all(ind[koj]), dp[ans - 1][i]) - ind[koj].begin();
		//cout << dp[ans - 1][i] << ' ' << koj << ' ' << K << '\n';
		if (K == 0){
			res += 'a' + i;
			id = i;
			koj = dp[ans - 1][i];
	//		cout << "YES" << endl;
			break;
		}
	}
	//cout << res << '\n';
	int Now = ans - 2;
	//cout << Now << ' ' << dp[1][0] << endl;
	while (res.size() != ans){
		for (int i = 0; i < 26; i++){
			int K = lower_bound(all(ind[id]), dp[Now][i]) - ind[id].begin();
			//cout << i << ' ' << id << ' ' << K << ' ' << dp[Now][i] << '\n';
			if (K != 0 && ind[id][K - 1] == koj){
				res += ('a' + i);
				id = i;
				koj = dp[Now][i];
				Now--;
				break;
			}
		}
	}
	cout << res;
	return 0;
}