#abc135f. [abc135_f]Strings of Eternity

[abc135_f]Strings of Eternity

Problem Statement

Given are two strings ss and tt consisting of lowercase English letters. Determine if the number of non-negative integers ii satisfying the following condition is finite, and find the maximum value of such ii if the number is finite.

  • There exists a non-negative integer jj such that the concatenation of ii copies of tt is a substring of the concatenation of jj copies of ss.

Notes

  • A string aa is a substring of another string bb if and only if there exists an integer xx (0leqxleqba)(0 \\leq x \\leq |b| - |a|) such that, for any yy (1leqyleqa)(1 \\leq y \\leq |a|), ay=bx+ya_y = b_{x+y} 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 ss and tt, i=0i = 0 satisfies the condition in the problem statement.

Constraints

  • 1leqsleq5times1051 \\leq |s| \\leq 5 \\times 10^5
  • 1leqtleq5times1051 \\leq |t| \\leq 5 \\times 10^5
  • ss and tt consist of lowercase English letters.

Input

Input is given from Standard Input in the following format:

ss tt

Output

If the number of non-negative integers ii satisfying the following condition is finite, print the maximum value of such ii; if the number is infinite, print -1.


Sample Input 1

abcabab
ab

Sample Output 1

3

The concatenation of three copies of tt, ababab, is a substring of the concatenation of two copies of ss, abcabababcabab, so i=3i = 3 satisfies the condition.

On the other hand, the concatenation of four copies of tt, abababab, is not a substring of the concatenation of any number of copies of ss, so i=4i = 4 does not satisfy the condition.

Similarly, any integer greater than 44 does not satisfy the condition, either. Thus, the number of non-negative integers ii satisfying the condition is finite, and the maximum value of such ii is 33.


Sample Input 2

aa
aaaaaaa

Sample Output 2

-1

For any non-negative integer ii, the concatenation of ii copies of tt is a substring of the concatenation of 4i4i copies of ss. Thus, there are infinitely many non-negative integers ii that satisfy the condition.


Sample Input 3

aba
baaab

Sample Output 3

0

As stated in Notes, i=0i = 0 always satisfies the condition.