6876.Minimal Rotation

Time Limit: 1s Memory Limit: 512MB

A rotation of a string can be generated by moving characters one after another from beginning to end. For example, the rotations of acab are acab , caba , abac , and baca .

Your task is to determine the lexicographically minimal rotation of a string.

Input Format(From the terminal/stdin)

The only input line contains a string of length $n$ . Each character is one of a–z.

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

Output Format(To the terminal/stdout)

Print the lexicographically minimal rotation.

Sample Input

Copy
acab
    \n

Sample Output

Copy
abac
    \n
Source: CSES, String Algorithms, 1110

Submit

请先 登录

© 2025 FAQs