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 LuaJIT (2.0.4) (judge verdict: Accepted)

local s = io.read()
local n = #s
local cycle_end_pos = {}
local box = {}
for i = 1, 26 do
  box[i] = false
end
local t = {}
for i = 1, n do
  t[i] = s:sub(i, i):byte() - 96
end
local boxcnt = 0
for i = 1, n do
  local v = t[i]
  if not box[v] then
    box[v] = true
    boxcnt = boxcnt + 1
    if boxcnt == 26 then
      table.insert(cycle_end_pos, i)
      boxcnt = 0
      for j = 1, 26 do box[j] = false end
    end
  end
end
-- node = (#cycles + 1) * 26
local edge = {}
local invedge = {}
local canuse = {}

for i = 1, (#cycle_end_pos + 1) * 26 do
  edge[i] = {}
  invedge[i] = {}
  canuse[i] = false
end

local first_pos = {}
local last_pos = {}
for ic = 1, #cycle_end_pos do
  local spos = ic == 1 and 1 or cycle_end_pos[ic - 1] + 1
  local epos = cycle_end_pos[ic]
  for i = 1, 26 do
    box[i] = false
    first_pos[i] = 0
    last_pos[i] = 0
  end
  boxcnt = 0
  for i = spos, epos do
    local v = t[i]
    if first_pos[v] == 0 then
      first_pos[v] = i
    end
    last_pos[v] = i
  end
  for i = 1, 26 do
    local src = (ic - 1) * 26 + i
    for j = 1, 26 do
      if last_pos[j] <= first_pos[i] then
        local dst = ic * 26 + j
        table.insert(edge[src], dst)
        table.insert(invedge[dst], src)
      end
    end
  end
end
for i = 1, 26 do
  local idx = #cycle_end_pos * 26 + i
  canuse[idx] = true
end
if #cycle_end_pos == 0 then
  for i = 1, n do
    local v = t[i]
    local idx = #cycle_end_pos * 26 + v
    canuse[idx] = false
  end
else
  for i = cycle_end_pos[#cycle_end_pos] + 1, n do
    local v = t[i]
    local idx = #cycle_end_pos * 26 + v
    canuse[idx] = false
  end
end
local tasks = {}
for i = 1, 26 do
  local idx = #cycle_end_pos * 26 + i
  if canuse[idx] then
    table.insert(tasks, idx)
  end
end
local done = 0
while done < #tasks do
  done = done + 1
  local invsrc = tasks[done]
  for i = 1, #invedge[invsrc] do
    local invdst = invedge[invsrc][i]
    if not canuse[invdst] then
      canuse[invdst] = true
      table.insert(tasks, invdst)
    end
  end
end
local ret = {}
local curpos = 0
for i = 1, 26 do
  if canuse[i] then
    curpos = i
    table.insert(ret, string.char(96 + i))
    break
  end
end
for ic = 1, #cycle_end_pos do
  for i = 1, #edge[curpos] do
    local dst = edge[curpos][i]
    if canuse[dst] then
      curpos = dst
      table.insert(ret, string.char(96 + dst - 26 * ic))
      break
    end
  end
end
print(table.concat(ret))