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 PyPy3 (2.4.0) (judge verdict: Wrong Answer)

import sys
input = sys.stdin.readline
S = list(input())[: -1]
N = len(S)
dp = [[[N, 0] for _ in range(26)] for _ in range(N + 1)]
a = ord("a")
S.reverse()
cs = [[0] * 26 for _ in range(N + 1)]
for i in range(N):
  for j in range(26): cs[i + 1][j] += cs[i][j]
  cs[i + 1][ord(S[i]) - a] += 1
for j in range(26):
  dp[0][j][0] = 1

for i in range(N):
  x = ord(S[i]) - a
  for j in range(26):
    if x == j: continue
    if dp[i + 1][j][0] > dp[i][j][0]:
      dp[i + 1][j][0] = dp[i][j][0]
      dp[i + 1][j][1] = dp[i][j][1]
  for j in range(26):
    if dp[i + 1][x][0] > dp[i][j][0]:
      if cs[i][j] - cs[dp[i][j][1] + 1][j]: continue
      dp[i + 1][x][0] = dp[i][j][0] + 1
      dp[i + 1][x][1] = i

x = 0
res = []
for j in range(26):
  if dp[-1][x][0] > dp[-1][j][0]: x = j
#print(dp)
i = N
while i:
  #print(i, res)
  res.append(chr(x + a))
  i = dp[i][x][1] - (i == dp[i][x][1])
  for j in range(26):
    if dp[i][x][0] > dp[i][j][0]: x = j
print("".join(res))