Problem:
Score : 2400 points

Problem Statement

Takahashi 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.

Input

Input is given from Standard Input in the following format:

N M K
S
T

Output

In 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 1

2 3 3
11
101

Sample Output 1

10000
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 2

5 8 3
10101
10101001

Sample Output 2

100000
10110100

Sample Input 3

10 10 10
1100110011
1011001101

Sample Output 3

10000100000010001000
10000100000000100010

Solution in Python (3.4.3) (judge verdict: Time Limit Exceeded)

def main():
    N, M, K = map(int, input().split())

    MAX_N = 2000000

    s = [int(c) for c in input()][::-1] + [0] * (MAX_N - N)
    t = [int(c) for c in input()][::-1] + [0] * (MAX_N - M)

    len_max = max(N, M) - 1
    st = []
    for i in range(len_max, -1, -1):
        m = []
        if s[i] and t[i]:
            s[i] = t[i] = 0
            xs = xt = 1
            z = K - 1
            j = i + 1

            while xs or xt:
                if not s[j] and not t[j]:
                    if xs and not xt:
                        s[j] = 1
                        st.append(j)
                        len_max = max(len_max, j)
                        break
                    elif not xs and xt:
                        t[j] = 1
                        st.append(j)
                        len_max = max(len_max, j)
                        break

                if not st or st[-1] - j > z:
                    s[j + z] = t[j + z] = 1
                    len_max = max(len_max, j + z)
                    break

                p = st.pop()
                z -= p - j
                j = p

                if s[j] == xs and t[j] == xt:
                    s[j] = t[j] = 0
                    j += 1
                    continue

                if xs and xt:
                    xs = s[j]
                    xt = t[j]
                    s[j] ^= 1
                    t[j] ^= 1
                    m.append(j)
                    j += 1
                    continue

                if s[j] != xs and t[j] != xt:
                    if not z:
                        s[j] = t[j] = 1
                        break
                    else:
                        s[j] = t[j] = 0
                        j += 1
                        z -= 1
                        xs = xt = 1
                        continue

            st += reversed(m)

        elif s[i] or t[i]:
            st.append(i)
    
    js = jt = 0
    while not s[len_max - js]:
        js += 1
    while not t[len_max - jt]:
        jt += 1

    print(*s[len_max - js:: -1], sep='')
    print(*t[len_max - jt:: -1], sep='')


main()