atcoder#ABC135F. [ABC135F] Strings of Eternity
[ABC135F] Strings of Eternity
Score : points
Problem Statement
Given are two strings and consisting of lowercase English letters. Determine if the number of non-negative integers satisfying the following condition is finite, and find the maximum value of such if the number is finite.
- There exists a non-negative integer such that the concatenation of copies of is a substring of the concatenation of copies of .
Notes
- A string is a substring of another string if and only if there exists an integer such that, for any , holds.
- We assume that the concatenation of zero copies of any string is the empty string. From the definition above, the empty string is a substring of any string. Thus, for any two strings and , satisfies the condition in the problem statement.
Constraints
- and consist of lowercase English letters.
Input
Input is given from Standard Input in the following format:
Output
If the number of non-negative integers satisfying the following condition is finite, print the maximum value of such ; if the number is infinite, print -1
.
abcabab
ab
3
The concatenation of three copies of , ababab
, is a substring of the concatenation of two copies of , abcabababcabab
, so satisfies the condition.
On the other hand, the concatenation of four copies of , abababab
, is not a substring of the concatenation of any number of copies of , so does not satisfy the condition.
Similarly, any integer greater than does not satisfy the condition, either. Thus, the number of non-negative integers satisfying the condition is finite, and the maximum value of such is .
aa
aaaaaaa
-1
For any non-negative integer , the concatenation of copies of is a substring of the concatenation of copies of . Thus, there are infinitely many non-negative integers that satisfy the condition.
aba
baaab
0
As stated in Notes, always satisfies the condition.