Programmer's school

Forgot password?
[problems] [status] [courses] [info] [register]
Login:   Password:    

Cyclic Shifts

(Time limit: 5 sec. Memory limit: 16 MB Difficulty: 76%)

A cyclic shift of the string s is the string sk+1sk+2…sns1s2…sk for some k (0 ≤ k < n) where n is the length of the string s.

For a given string, construct all cyclic shifts, sort them lexicographically, output the last column, and find the position of the original string in this list.

Input

The only line of input contains a string consisting of characters with ASCII codes 33 to 127. The string length can be up to 105.

Output

In the first line of the output, print the position of the given string in the sorted list of cyclic shifts. If there are several such positions, then the position with the smallest number should be printed. In the second line, output the last column of the sorted cyclic shift table.

Sample

INPUT.TXTOUTPUT.TXT
1abraka2
karaab

Note

Firstly, we write out all 6 cyclic shifts of the string "abraka" and sort the resulting list lexicographically:

Original listSorted list
abraka
brakaa
rakaab
akaabr
kaabra
aabrak
aabrak
abraka
akaabr
brakaa
kaabra
rakaab

Now we see that the original word is in the 2-nd position in the sorted list, and the last column is the string "karaab".

Для отправки решения задачи необходимо зарегистрироваться и авторизоваться!


 C++ programming language
 Solution of olympiad tasks
 Regional competition
 Books by Fyodor Menshikov
 USE in informatics
 Training olympics
 Introduction
 Integer arithmetic
 Sorting algorithms
 Long arithmetic
 C++ Standard Template Library
 Dynamic programming
 Combinatorics
 Computational geometry
 String
 Data structures
 Graph theory - 1
 Graph theory - 2
 Simple tasks
 Algorithms on strings
 Polynomial hash
 A. Funktsiya Eylera
 B. Obratnyy element
 C. Hesh-funktsiya
 D. Vzlom hesh-funktsii
 E. Reklamnyy shchit
 F. Minimalnyy sdvig
 G. Slova
 H. Stroki - 3
 I. Podpalindromy
 J. Tsiklicheskie sdvigi

Krasnoyarsk regional Palace of pioneers, (c)2006 - 2025, ИНН 246305493507, E-mail: admin@acmp.ru