Problem p03565 - Generation 2

Orig Description

Score : 300 points
Problem StatementE869120 found a chest which is likely to contain treasure.
However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.
He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.  
One more thing he found is a sheet of paper with the following facts written on it:  
Condition 1: The string S contains a string T as a contiguous substring.
Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.
Print the string S.
If such a string does not exist, print UNRESTORABLE.  
Constraints
1 \leq |S'|, |T| \leq 50
S' consists of lowercase English letters and ?.
T consists of lowercase English letters.
InputInput is given from Standard Input in the following format:
S
T'
OutputPrint the string S.
If such a string does not exist, print UNRESTORABLE instead.  
Sample Input 1?tc????
coder
Sample Output 1atcoder
There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say S = atcoder.
Sample Input 2??p??d??
abc
Sample Output 2UNRESTORABLE
There is no string that satisfies Condition 1, so the string S does not exist.

Extracted Specification

Canonicalized Input Description:

Two strings, S' and T.

1 ≤ |S'|, |T| ≤ 50
S' consists of lowercase English letters and '?'.
T consists of lowercase English letters.

### Example Input:

```
?tc????
coder
```

### Function Signature:
Write a function f(S_prime, T) that takes in the input.
def f(S_prime: str, T: str):
    ''' 
    S_prime: a string 
    T: a string
    '''

Test Case Generator

Sure, let's write a test case generator for the given problem statement. This generator will create random valid inputs for the problem, ensuring the constraints are respected.

```python
import random
import string

def generate_random_string(length, chars):
    """Generate a random string of given length from the specified character set."""
    return ''.join(random.choice(chars) for _ in range(length))

def tcgen():
    # Length of S' and T (1 ≤ |S'|, |T| ≤ 50)
    len_S_prime = random.randint(1, 50)
    len_T = random.randint(1, 50)

    # Generate string T consisting of lowercase English letters
    T = generate_random_string(len_T, string.ascii_lowercase)

    # Generate string S' consisting of lowercase English letters and '?'
    S_prime = generate_random_string(len_S_prime, string.ascii_lowercase + '?')

    return S_prime, T

# Example usage
S_prime, T = tcgen()
print("Generated S':", S_prime)
print("Generated T:", T)
```

### Explanation:

1. **`generate_random_string(length, chars)`:** This helper function generates a random string of a specified length using the characters from the given set `chars`.
   
2. **`tcgen()` function:**
   - Randomly determines the length of `S'` and `T` within the constraints.
   - Generates string `T` consisting of lowercase English letters.
   - Generates string `S'` consisting of lowercase English letters and '?'. 

3. **Example usage:** Calls the `tcgen` function to generate a test case and prints the generated `S'` and `T`.

This code ensures that the test cases are generated adhering to the constraints provided in the problem statement.

Extract Arguments

def extract_arguments(fh):
    S_prime = fh.readline().strip()
    T = fh.readline().strip()
    return S_prime, T