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 <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#include <queue>
#include <regex>
#include <cassert>
#include <map>
// #include "bits/stdc++.h"

using namespace std;



namespace {
#define rep(i, N, M) for(int i=N, i##_len=(M); i<i##_len; ++i)
#define rep_skip(i, N, M, ...) for(int i=N, i##_len=(M); i<i##_len; i+=(skip))
#define rrep(i, N, M)  for(int i=(M)-1, i##_len=(N-1); i>i##_len; --i)
#define pb push_back


	typedef long long ll;
	typedef unsigned long long ull;
	typedef pair<ll, ll> pll;
	typedef tuple<ll, ll, ll> tll;
	typedef tuple<ll, ll, ll, ll> tll4;
	typedef vector<ll> vll;
	typedef vector<vll> vvll;
	typedef vector<pll> vpll;
	typedef vector<bool> vb;
	typedef vector<vb> vvb;
	typedef vector<string> vs;
	typedef priority_queue<ll> pqll;
	typedef priority_queue<pll, vector<pll>> pqpll;
	typedef priority_queue<ll, vll, greater<ll>> pqll_greater;
	typedef priority_queue<pll, vector<pll>, greater<pll>> pqpll_greater;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>
#define perm(c) sort(all(c));for(bool c##perm=1;c##perm;c##perm=next_permutation(all(c)))


	template<class T, class S>
	T atbit(T n, S i) {
		return (n >> i) % i;
	}

	template<class T>
	T getbit(T i) {
		return 1LL << i;
	}

	constexpr ll POW(ll n, ll m) {
		ll res = 1;
		rep(i, 0, m) {
			res *= n;
		}
		return res;
	}

	vll getDivisors(ll n) {
		vll res;
		ll i = 1;

		for (; i*i < n; i++) {
			if (n%i == 0) {
				res.push_back(i);
				res.push_back(n / i);
			}
		}
		if (i*i == n)res.push_back(i);
		sort(res.begin(), res.end());
		return res;
	}

	vll getDivisors(ll n, ll m) {
		if (n > m) swap(n, m);
		vll res;
		ll i = 1;

		for (; i*i < n; i++) {
			if (n%i == 0) {
				if (m%i == 0) res.push_back(i);
				if (m % (n / i) == 0) res.push_back(n / i);
			}
		}
		if (i*i == n) if (m%i == 0) res.push_back(i);
		sort(res.begin(), res.end());
		return res;
	}


	ll gcd(ll a, ll b) {
		if (a%b == 0) return b;
		else return gcd(b, a%b);
	}

	template<
		typename Inputs,
		typename Functor,
		typename T = typename Inputs::value_type>
		void sort_by(Inputs& inputs, Functor f) {
		std::sort(std::begin(inputs), std::end(inputs),
			[&f](const T& lhs, const T& rhs) { return f(lhs) < f(rhs); });
	}

	template<int I>
	vll proj(vpll v) {
		vll res(v.size());
		rep(i, 0, v.size()) {
			if (!I) res[i] = v[i].first;
			else res[i] = v[i].second;
		}
		return res;
	}


	template<int I, class T>
	vll proj(T v) {
		vll res(v.size());
		rep(i, 0, v.size()) {
			res[i] = get<I>(v[i]);
		}
		return res;
	}
	vector<pll >prime_factorize(ll n) {
		vector<pll> res;
		for (ll p = 2; p*p <= n; ++p) {
			if (n%p != 0)continue;
			ll num = 0;
			while (n%p == 0) { ++num; n /= p; }
			res.push_back({ p,num });
		}
		if (n != 1) res.push_back(make_pair(n, 1));
		return res;
	}

}

ll MOD = 1000000007;
ll INF = 1LL << 60;
string alph = "abcdefghijklmnopqrstuvwxyz";

int main() {
	string A;
	cin >> A;

	ll n = A.size();
	vector<string> dp(n, "aaaaaaaaa");

	vvll next(n, vll(26, n));
	next[n - 1][A.back() - 'a'] = n - 1;
	rrep(i, 0, n - 1) {
		int chr = A[i] - 'a';
		rep(j, 0, 26) {
			if (j != chr) next[i][j] = next[i + 1][j];
			else next[i][j] = i;
		}
	}

	//dp[n - 1] = A.back()== 'a'? 'b':'a';


	auto min_str = [](string& a, string b) {
		if (a.size() > b.size()) {
			a = b;
			return;
		}
		else if (a.size() == b.size() || a > b) {
			a = b;
			return;
		}
	};
	rrep(i, 0, n-1) {
		rep(c, 0, 26) {
			if (next[i][c] == n) min_str(dp[i], string(1, alph[c]));
			else {
				auto k = next[i][c];
				if (k + 1 < n) {
					min_str(dp[i], alph.substr(c, 1) + dp[k + 1]);
				}
				else {
					min_str(dp[i], alph.substr(c, 1) + 'a');
				}
			}
		}
	}

	cout << dp[0];

	return 0;
}