Problem p03565 - Generation 1

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:

A string S' consisting of lowercase English letters and '?' with a length between 1 and 50.
A string T consisting of lowercase English letters with a length between 1 and 50.

### 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! Here's a test case generator for the problem statement you provided. This generator will create random valid inputs for the problem, ensuring that the constraints are respected.

```python
import random
import string

def tcgen():
    # Generate random lengths for S' and T
    len_S = random.randint(1, 50)
    len_T = random.randint(1, min(50, len_S))
    
    # Generate a random string T consisting of lowercase English letters
    T = ''.join(random.choice(string.ascii_lowercase) for _ in range(len_T))
    
    # Generate a random string S' with lowercase letters and '?'
    S_prime = []
    for _ in range(len_S):
        if random.random() < 0.3:  # 30% chance of being a '?'
            S_prime.append('?')
        else:
            S_prime.append(random.choice(string.ascii_lowercase))
    S_prime = ''.join(S_prime)
    
    return S_prime, T

# Example of generating a test case
S_prime, T = tcgen()
print("S' =", S_prime)
print("T =", T)
```

This function generates:
- A random length `len_S` for the string `S'`.
- A random length `len_T` for the string `T` such that `len_T <= len_S`.
- A random string `T` of length `len_T` consisting of lowercase English letters.
- A random string `S'` of length `len_S` consisting of lowercase English letters and the character '?'.

The function prints an example generated test case. You can call this function multiple times to generate different test cases for your problem.

Extract Arguments

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