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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
 
 
public class Main {

	static long MOD = 1_000_000_007;
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		int INF = Integer.MAX_VALUE;
		Scanner sc = new Scanner(System.in);
		char[] A = sc.next().toCharArray();
		int N = A.length;
		int[] dp = new int[N+1];
		Arrays.fill(dp, INF);
		int[][] next = new int[N+1][26];
		for(int[] next_ : next){
			Arrays.fill(next_, N);
		}
		for(int i=N-1; i>=0; i--){
			for(int j=0;j<26;j++)next[i][j] = next[i+1][j];
			next[i][A[i]-'a'] = i;
		}
		
		dp[N] = 1;
		
		for(int i=N-1; i>=0; i--){
			for(int j=0; j<26; j++){
				if(next[i][j] == N){
					dp[i] = 1;
				}else{
					dp[i] = Math.min(dp[next[i][j]+1]+1,dp[i]);
				}
			}
		}
		
		StringBuilder ans = new StringBuilder("");
		int index = 0;
		while(index < N){
			if(dp[index] == 1){
				for(int j=0;j<26;j++){
					boolean isNotExist = true;
					for(int i=index;i<N;i++){
						if(A[i] == (char)('a'+j)){
							isNotExist = false;
							break;
						}
					}
					if(isNotExist){
						ans.append((char)('a'+j));
						index = N;
						break;
					}
				}
			}else{
				for(int j=0; j<26; j++){
					if(dp[index] == dp[next[index][j]]+1){
						ans.append((char)('a'+j));
						index = next[index][j];
						break;
					}
				}
				index++;
			}
		}
		
		
		System.out.println(ans);
		
	}
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (c/b);
	}
}