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 Scala (2.11.7) (judge verdict: Wrong Answer)


import java.util.Scanner

object Main extends App {

  val FF = (1 << 26) - 1

  val sc = new Scanner(System.in)

  val str = sc.next()
  var cs = Array.fill(26)(Seq[Int](Int.MaxValue))
  str.zipWithIndex
    .groupBy(_._1)
    .toStream
    .foreach {
      case (c, seq) =>
//        println(c, seq)
        cs(c - 'a') = seq.map(_._2) ++ Seq(Int.MaxValue)
    }


  var bf = 0
  var len = 0
  for (c <- str.reverse) {
    bf = bf | (1 << (c - 'a'))

    if (bf == FF) {
      bf = 0
      len = len + 1
    }
  }


//  cs.foreach(println(_))
//  println("info", len, bf)

  val head = Range(0, 26)
    .find(i => ((bf >> i) & 1) == 0).get
  print(('a' + head).toChar)

  var cur = cs(head)(0)
  for (i <- 1 to len) {
    cur = find(cur, len - i + 2)
  }
  println

  def find(x: Int, k: Int): Int = {
    for (c <- 0 to 25) {
      val t = find(x, cs(c))
//      println("inner", ('a' + c).toChar, k, t, cs(c).length - t)
      if (cs(c).length - t <= k) {
        print(('a' + c).toChar)
        return if (cs(c).isEmpty) 0 else cs(c)(t)
      }
    }
    0
  }

  def find(x: Int, seq: Seq[Int]) = {
    var l = 0
    var r = seq.length
    while (l < r) {
      val m = (l + r) / 2
      if (seq(m) <= x) l = m + 1
      else r = m
    }
    l
  }
}