Problem p03336 - Generation 3

Orig Description

Score : 2400 points
Problem StatementTakahashi and Aoki love calculating things, so they will play with numbers now.
First, they came up with one positive integer each. Takahashi came up with X, and Aoki came up with Y.
Then, they will enjoy themselves by repeating the following operation K times:
Compute the bitwise AND of the number currently kept by Takahashi and the number currently kept by Aoki. Let Z be the result.
Then, add Z to both of the numbers kept by Takahashi and Aoki.
However, it turns out that even for the two math maniacs this is just too much work.
Could you find the number that would be kept by Takahashi and the one that would be kept by Aoki eventually?
Note that input and output are done in binary.
Especially, X and Y are given as strings S and T of length N and M consisting of 0 and 1, respectively, whose initial characters are guaranteed to be 1.
Constraints
1 ≤ K ≤ 10^6
1 ≤ N,M ≤ 10^6
The initial characters of S and T are 1.
InputInput is given from Standard Input in the following format:
N M K
S
T
OutputIn the first line, print the number that would be kept by Takahashi eventually; in the second line, print the number that would be kept by Aoki eventually.
Those numbers should be represented in binary and printed as strings consisting of 0 and 1 that begin with 1.
Sample Input 12 3 3
11
101
Sample Output 110000
10010
The values of X and Y after each operation are as follows:
After the first operation: (X,Y)=(4,6).
After the second operation: (X,Y)=(8,10).
After the third operation: (X,Y)=(16,18).
Sample Input 25 8 3
10101
10101001
Sample Output 2100000
10110100
Sample Input 310 10 10
1100110011
1011001101
Sample Output 310000100000010001000
10000100000000100010

Extracted Specification

An integer N (1 ≤ N ≤ 10^6), representing some quantity.
An integer M (1 ≤ M ≤ 10^6), representing some quantity.
An integer K (1 ≤ K ≤ 10^6), representing the number of operations.
A binary string S of length N, where the initial character is guaranteed to be '1'.
A binary string T of length M, where the initial character is guaranteed to be '1'.

### Example Input:

```
2 3 3
11
101
```

### Function Signature:
Write a function f(N, M, K, S, T) that takes in the input.
def f(N: int, M: int, K: int, S: str, T: str):
    '''
    N: an integer
    M: an integer
    K: an integer
    S: a binary string
    T: a binary string
    '''

Test Case Generator

Certainly! A test case generator for the given problem statement can be written in Python. Here's a sample implementation:

```python
import random

def generate_binary_string(length):
    return '1' + ''.join(random.choice('01') for _ in range(length - 1))

def tcgen():
    N = random.randint(1, 10**6)
    M = random.randint(1, 10**6)
    K = random.randint(1, 10**6)
    
    S = generate_binary_string(N)
    T = generate_binary_string(M)
    
    return N, M, K, S, T

# Example usage:
N, M, K, S, T = tcgen()
print(N)
print(M)
print(K)
print(S)
print(T)
```

### Explanation:
1. **generate_binary_string(length)**:
   - This function generates a binary string of the given length, ensuring that the first character is '1'.

2. **tcgen()**:
   - This function generates the values for `N`, `M`, and `K` within their respective constraints.
   - It uses the `generate_binary_string` function to create valid binary strings `S` and `T` of lengths `N` and `M`, respectively.

### Example Output:
When you run the `tcgen()` function, it will output values satisfying the constraints. Here is an example of what the output may look like:

```
435
769
123456
100011101001010110...
110101001010110101...
```

Note:
- The ellipses (`...`) indicate that the binary strings `S` and `T` will be long strings, potentially up to lengths of `10^6`.

Feel free to use and modify this generator according to your needs for generating test cases for this problem.

Extract Arguments

def extract_arguments(fh):
    N, M, K = map(int, fh.readline().strip().split())
    S = fh.readline().strip()
    T = fh.readline().strip()
    return N, M, K, S, T