#T449. 解密参赛码
解密参赛码
Description
Sometimes the CodesOJ administrators use peculiar methods to hide the registration codes for their monthly contests. Users can only participate after cracking the code through certain means. Little Tu selects a string S (composed of N lowercase letters, where 5 ≤ N ≤ 5,000,000), then he arranges S clockwise into a circle. Starting from each letter as the beginning, he sequentially picks letters clockwise to form a string. This generates several strings, which he sorts and selects the first one. The registration code for the OJ contest is the position of this string's first letter in the original string minus 1.
For example, take the string "alabala". Following this operation, 7 strings are obtained. After sorting, they are:
aalabal
abalaal
alaalab
alabala
balaala
laalaba
labalaa
The first string is "aalabal", and the position of this 'a' in the original string is 7. Thus, 7 - 1 = 6, so the registration code is 6.
Input Format
First line: A number: N
Second line onwards: The string S (with a line break every 72 characters)
Output Format
A single line containing the obtained registration code
【Data Range】
30% of data: n <= 10000
70% of data: n <= 100000
100% of data: n <= 5000000
Source
Original adapted problem from CodesOJ