Problem p01655 - Generation 1

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) and an integer d (0 ≤ d ≤ 5,000).
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 a list of tuples as input.
def f(inputs: List[Tuple[int, int, str, str, str]]):
    '''
    inputs: a list of tuples, where each tuple contains:
        - an integer
        - an integer
        - a string
        - a string
        - a string
    '''

Test Case Generator

Sure, I will provide a test case generator for the described problem statement.

To generate test cases for this problem, we need to generate:
1. A random length `l` for the strings.
2. A random acceptable maximum Hamming distance `d`.
3. Three strings of length `l` consisting of random upper and lower case alphabets.

Here is a Python function that generates test cases according to the given problem statement:

```python
import random
import string

def generate_random_string(length):
    return ''.join(random.choices(string.ascii_letters, k=length))

def tcgen():
    # Generate random length l (1 ≤ l ≤ 100,000)
    l = random.randint(1, 100000)
    
    # Generate random acceptable maximal Hamming distance d (0 ≤ d ≤ 5,000) 
    d = random.randint(0, 5000)
    
    # Generate 3 strings of length l
    str_1 = generate_random_string(l)
    str_2 = generate_random_string(l)
    str_3 = generate_random_string(l)
    
    return (l, d, str_1, str_2, str_3)


# Example of generating a test case
l, d, str_1, str_2, str_3 = tcgen()
print(f"{l} {d}")
print(str_1)
print(str_2)
print(str_3)
```

### Explanation:
- `generate_random_string(length)`: This helper function generates a random string of a specified length consisting of upper and lower case alphabets.
- `tcgen()`: The main test case generator function:
  - It first generates a random length `l` between 1 and 100,000.
  - Then, it generates a random acceptable maximal Hamming distance `d` between 0 and 5,000.
  - After that, it generates three random strings of length `l`.
  - Finally, it returns `l`, `d`, `str_1`, `str_2`, and `str_3`.

You can call `tcgen()` to generate test cases and print them in the required format. The above example demonstrates how to generate a test case and print it.

### Note:
- Ensure that your environment can handle large strings and random operations efficiently, as the maximum length can be quite large.
- This generator provides random strings and may not always generate strings that are within the acceptable Hamming distance `d`. Additional logic can be added if you need to guarantee that generated strings adhere to specific constraints related to Hamming distances.

Extract Arguments

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

# if __name__ == "__main__":
#     input_path = sys.argv[1]
#     with open(input_path, 'r') as fh:
#         inputs = extract_arguments(fh)
#         for input_tuple in inputs:
#             f(*input_tuple)