Problem p03336 - Generation 1

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 binary string length.
An integer M (1 ≤ M ≤ 10^6), representing another binary string length.
An integer K (1 ≤ K ≤ 10^6), representing the number of operations.
A binary string S of length N, starting with '1'.
A binary string T of length M, starting with '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

Sure! Here is a test case generator for the given problem statement:

```python
import random

def generate_binary_string(length):
    # Ensure the first character is '1' and the rest can be '0' or '1'
    return '1' + ''.join(random.choice('01') for _ in range(length - 1))

def tcgen():
    # Generate the values for N, M, and K within the constraints
    N = random.randint(1, 10**6)
    M = random.randint(1, 10**6)
    K = random.randint(1, 10**6)
    
    # Generate binary strings of length N and M
    S = generate_binary_string(N)
    T = generate_binary_string(M)
    
    return N, M, K, S, T

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

### Explanation:
This generator creates the following values:
1. `N`: The length of the binary string \( S \).
2. `M`: The length of the binary string \( T \).
3. `K`: The number of operations to perform.
4. `S`: A binary string of length \( N \), starting with '1'.
5. `T`: A binary string of length \( M \), starting with '1'.

The constraints (1 ≤ \( K \) ≤ 10^6 and 1 ≤ \( N, M \) ≤ 10^6) are respected by random selection within these ranges. The first character of both \( S \) and \( T \) is guaranteed to be '1', and the rest of the characters are randomly chosen from '0' and '1'.

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