6889.String Transform

Time Limit: 1s Memory Limit: 512MB

Consider the following string transformation:

append the character # to the string (we assume that # is lexicographically smaller than all other characters of the string)generate all rotations of the stringsort the rotations in increasing orderbased on this order, construct a new string that contains the last character of each rotation

For example, the string babc becomes babc# . Then, the sorted list of rotations is #babc , abc#b , babc# , bc#ba , and c#bab . This yields a string cb#ab .

Input Format(From the terminal/stdin)

The only input line contains the transformed string of length $n+1$ . Each character of the original string is one of a–z.

  • $1 \le n \le 10^6$

Output Format(To the terminal/stdout)

Print the original string of length $n$ .

Sample Input

Copy
cb#ab
     \n

Sample Output

Copy
babc
    \n
Source: CSES, String Algorithms, 1113

Submit

请先 登录

© 2025 FAQs