TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

Here's a very important and basic problem in string:

Given a string S = s1s2s3...sl, define it's i-th rotation to be sisi+1...sls1...si-1.

So for example, if S = "bacaa", it's five rotations are: "bacaa", "acaab", "caaba", "aabac", "abaca".

Now the question is simple: given the string S, find among its all rotations the lexicographically smallest one. In the above example where S = "bacaa", the answer is "aabac".

p.s. see if you can solve it without using sophisticated data structure like suffix array!

Input Format

The input consists of multiple test case, terminated by EOF. Each test case is simply the string S.

Output Format

For each testcase, output the lexicograhically smallest rotation of the input string.



Constraint


1 <= |S| <= 2000000

Sample Input 1

bacaa
aaa
zxcvbnm

Sample Output 1

aabac
aaa
bnmzxcv

Hints

Problem Source

Migrated from old NTUJ.

Classic

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 100000