Question
Lexicographical String Challenge

In a realm of words, Ram and Alice receive a unique string S. They start with two empty containers, A and B, aiming to collaboratively create the lexicographically smallest string A. They operate as follows:

  • Ram can take a letter from the front of S and pass it to Alice, who adds it to the end of her container B.
  • Alice can take a letter from the end of her container B and append it to string A.
Their objective is to ensure that, when finished, string A is the lexicographically smallest possible and matches the length of S.
Input
The first line of the input contains a single string S, containing only lowercase alphabets.
Output
Print the lexicographical minimum string A, that we can obtain.
Example
Sample Input
cab
Sample Output
abc

Online