Baltic Olympiad in Informatics: 2004 Day 2, Problem 1
A string is called a -repeat if is obtained by concatenating times some seed string with length . For example, the string abaabaabaaba
is a -repeat with aba
as the seed string. That is, the seed string aba
is characters long, and the whole string is obtained by repeating it times.
You are given a string . Find one -repeat that occurs as a substring within with a as large as possible.
Constraints
only consists of a
or b
.
Input Specification
The first line of input contains one integer : the length of the input string .
The next lines describe the string . Each line contains one character (either a
or b
).
Output Specification
Output three integers, each on its own line. They report the -repeat your program found as follows:
- The first line consists of the repeat count that is maximized.
- The second line consists of the length of the seed string that is repeated times.
- The third and final line consists of the position at which the -repeat starts.
If there are multiple solutions with the same , your program can output any one of them.
Sample Input
17
b
a
b
b
a
b
a
a
b
a
a
b
a
a
b
a
b
Sample Output
4
3
5
Sample Explanation
A -repeat is found starting at the character of the input string (which is line of the input file).
The underlined substring of shows the -repeat. No substring of has more than repeats.
Comments