Problem p02962 - Generation 2

Orig Description

Score : 600 points
Problem StatementGiven are two strings s and t consisting of lowercase English letters. Determine if the number of non-negative integers i satisfying the following condition is finite, and find the maximum value of such i if the number is finite.
There exists a non-negative integer j such that the concatenation of i copies of t is a substring of the concatenation of j copies of s.
Notes
A string a is a substring of another string b if and only if there exists an integer x (0 \leq x \leq |b| - |a|) such that, for any y (1 \leq y \leq |a|), a_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 s and t, i = 0 satisfies the condition in the problem statement.
Constraints
1 \leq |s| \leq 5 \times 10^5
1 \leq |t| \leq 5 \times 10^5
s and t consist of lowercase English letters.
InputInput is given from Standard Input in the following format:
s
t
OutputIf the number of non-negative integers i satisfying the following condition is finite, print the maximum value of such i; if the number is infinite, print -1.
Sample Input 1abcabab
ab
Sample Output 13
The concatenation of three copies of t, ababab, is a substring of the concatenation of two copies of s, abcabababcabab, so i = 3 satisfies the condition.
On the other hand, the concatenation of four copies of t, abababab, is not a substring of the concatenation of any number of copies of s, so i = 4 does not satisfy the condition.
Similarly, any integer greater than 4 does not satisfy the condition, either. Thus, the number of non-negative integers i satisfying the condition is finite, and the maximum value of such i is 3.
Sample Input 2aa
aaaaaaa
Sample Output 2-1
For any non-negative integer i, the concatenation of i copies of t is a substring of the concatenation of 4i copies of s. Thus, there are infinitely many non-negative integers i that satisfy the condition.
Sample Input 3aba
baaab
Sample Output 30
As stated in Notes, i = 0 always satisfies the condition.

Extracted Specification

Canonicalized Input Description:

Two strings \( s \) and \( t \) consisting of lowercase English letters.

### Example Input:
```
abcabab
ab
```

### Function Signature:
Write a function `f(s, t)` that takes in the input.
```python
def f(s: str, t: str):
    '''
    s: a string
    t: a string
    '''
```

Test Case Generator

Sure, let's build a test case generator for the given problem statement. The generator will create random strings `s` and `t` with lengths that fit within the specified constraints. Here's the Python code for the test case generator:

```python
import random
import string

def generate_string(length):
    return ''.join(random.choice(string.ascii_lowercase) for _ in range(length))

def tcgen():
    # Generating random lengths for s and t within the given constraints
    len_s = random.randint(1, 5 * 10**5)
    len_t = random.randint(1, 5 * 10**5)
    
    # Generating random strings s and t of the specified lengths
    s = generate_string(len_s)
    t = generate_string(len_t)
    
    return s, t

# Example use
s, t = tcgen()
print(s)
print(t)
```

This test case generator does the following:

1. Defines a helper function `generate_string(length)` that generates a random string of lowercase English letters of the given length.
2. `tcgen()` function generates random lengths for `s` and `t` within the specified constraints (1 ≤ |s| ≤ 5 x 10^5 and 1 ≤ |t| ≤ 5 x 10^5).
3. Uses the `generate_string` function to create random strings `s` and `t` of the generated lengths.
4. Returns the generated strings `s` and `t`.

You can use this generator to create multiple test cases for the problem by calling `tcgen()` repeatedly.

Extract Arguments

def extract_arguments(fh):
    s = fh.readline().strip()
    t = fh.readline().strip()
    return s, t