Exam at British Intelligence
Time limit2sMemory limit1024 MB
Given a string s, find every k such that s splits into k equal-length pieces that are all cyclic shifts of each other.
- Level
Medium6 of 10
- Topics
- String matching, String, Math
- Solved
- No attempts yet
Problem
Finn Maxmisl is an agent of British Intelligence. Every agent must be ready for unexpected situations and must be able to solve any assigned task within seconds. Besides physical standards, the final exam at the intelligence academy also requires solving complex algorithmic tasks. Finn received the following one.
A string of length is given. Call it -splittable if it can be split into contiguous substrings of equal length so that every substring can be obtained from any other one by a cyclic shift.
A string is a cyclic shift of a string if there exist strings and (either may be empty) such that and .
Find all for which the string is -splittable.
Since every method is fair game in intelligence work, Finn asked you for help.
Input
The first line contains the string (), consisting of lowercase Latin letters.
Output
The first line prints the number of suitable values of .
The second line prints the suitable values in increasing order, separated by spaces.
Hint
In the first sample, the string can stay as it is and be split into two strings abba and baab, which are cyclic shifts of each other. It can also be split into four strings ab, ba, ba, and ab, which are cyclic shifts of each other.