Suffixes
(Time limit: 1 sec. Memory limit: 16 MB Difficulty: 45%)
Let the string be a sequence of lowercase letters of the English alphabet. For example, empty sequence "" is a string, the word "aabaf" or an infinite sequence of letters "a" are strings too.
The i-th suffix Si of the string S is the string S from which the first i letters are cut: so, for the string S = “aabaf” the suffixes will be:
S0 = “aabaf”
S1 = “abaf”
S2 = “baf”
S3 = “af”
S4 = “f”
S5 = S6 = S7 = . . . = “”
The suffixes are defined for all i > 0.
The cyclic extension S* of a finite string S is a string obtained by appending it to itself an infinite number of times. So,
S* = S0* = “aabafaabafaa...”
S1* = “abafabafabaf...”
S2* = “bafbafbafbaf...”
S3* = “afafafafafaf...”
S4* = “ffffffffffff...”
S5* = S6* = S7*= . . . = “”
For a given string S, find out how many of its suffixes Si have the same cyclic extension as the string S itself that is the number of different i such that S*= Si*.
Input
Input contains a string S consisting of 1 to 105 lowercase letters of the English alphabet.
Output
Output the number of suffixes of the string S having the same cyclic extension as itself.
Samples
¹ | INPUT.TXT | OUTPUT.TXT |
1 | aa | 2 |
2 | ab | 1 |
3 | qqqq | 4 |
4 | xyzzyxy | 1 |
Äëÿ îòïðàâêè ðåøåíèÿ çàäà÷è íåîáõîäèìî çàðåãèñòðèðîâàòüñÿ è àâòîðèçîâàòüñÿ!
|