Problem p01655 - Generation 2

Orig Description

Problem Statement
You bought 3 ancient scrolls from a magician. These scrolls have a long string, and the lengths of the strings are the same. He said that these scrolls are copies of the key string to enter a dungeon with a secret treasure.
However, he also said, they were copied so many times by hand, so the string will contain some errors, though the length seems correct. 
Your job is to recover the original string from these strings. When finding the original string, you decided to use the following assumption. 
  The copied string will contain at most d errors. In other words, the Hamming distance of the original string and the copied string is at most d. 
  If there exist many candidates, the lexicographically minimum string is the original string.
Can you find the orignal string?
Input
The input contains a series of datasets.
Each dataset has the following format:
l d
str_1
str_2
str_3
The first line contains two integers l (1 \leq l \leq 100,000) and d (0 \leq d \leq 5,000.)
l describes the length of 3 given strings and d describes acceptable maximal Hamming distance.
The following 3 lines have given strings, whose lengths are l.
These 3 strings consist of only lower and upper case alphabets.
The input ends with a line containing two zeros, which should not be processed. 
Output
Print the lexicographically minimum satisfying the condition in a line.
If there do not exist such strings, print -1.
Sample Input
3 1
ACM
IBM
ICM
5 2
iwzwz
iziwi
zwizi
1 0
A
B
C
10 5
jLRNlNyGWx
yyLnlyyGDA
yLRnvyyGDA
0 0
Output for the Sample Input
ICM
iwiwi
-1
AARAlNyGDA

Extracted Specification

An integer l (1 ≤ l ≤ 100,000), representing a length.
An integer d (0 ≤ d ≤ 5,000), representing a maximum allowable difference.
Three strings of length l, consisting of only lower and upper case alphabets.
The input ends with a line containing two zeros, which should not be processed.

### Example Input:

```
3 1
ACM
IBM
ICM
5 2
iwzwz
iziwi
zwizi
1 0
A
B
C
10 5
jLRNlNyGWx
yyLnlyyGDA
yLRnvyyGDA
0 0
```

### Function Signature:
Write a function f(inputs) that takes in the input as a list of tuples. Each tuple has the form (l, d, str1, str2, str3).

```python
def f(inputs: List[Tuple[int, int, str, str, str]]):
    '''
    inputs: a list of tuples, each containing:
        - an integer l
        - an integer d
        - a string str1
        - a string str2
        - a string str3
    '''
```

Test Case Generator

Sure, I'll create a test case generator for the provided problem statement. Here's a Python function `tcgen()` which generates random test cases for the "ancient scrolls" problem:

```python
import random
import string

def tcgen():
    def generate_string(length):
        return ''.join(random.choices(string.ascii_letters, k=length))
    
    # Randomly generate the length of the strings l
    l = random.randint(1, 100000)
    
    # Randomly generate the maximum acceptable Hamming distance d
    d = random.randint(0, 5000)
    
    # Generate three random strings of length l
    str_1 = generate_string(l)
    str_2 = generate_string(l)
    str_3 = generate_string(l)
    
    return l, d, str_1, str_2, str_3

# Example of generating and printing a test case
if __name__ == "__main__":
    l, d, str_1, str_2, str_3 = tcgen()
    print(f"{l} {d}")
    print(str_1)
    print(str_2)
    print(str_3)
```

### Explanation:
1. **Function `generate_string(length)`**: This helper function generates a random string of given length using lowercase and uppercase alphabets.

2. **Random Parameters**:
    - `l` is randomly chosen between 1 and 100,000.
    - `d` is randomly chosen between 0 and 5000.

3. **Generating Three Strings**:
    - Three strings (`str_1`, `str_2`, `str_3`) of length `l` are generated using the `generate_string` function.

4. **Return Values**:
    - The function returns the length `l`, the maximum Hamming distance `d`, and the three generated strings.

You can run this script to generate a set of test cases. The printed output can then be used directly as input for your problem statement.

Extract Arguments

def extract_arguments(fh):
    datasets = []
    while True:
        l, d = map(int, fh.readline().strip().split())
        if l == 0 and d == 0:
            break
        str_1 = fh.readline().strip()
        str_2 = fh.readline().strip()
        str_3 = fh.readline().strip()
        datasets.append((l, d, str_1, str_2, str_3))
    return datasets