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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;
const int N = 2000005;
int n, m, k, a[N], b[N], ra[N], rb[N];
char str[N];
vector<pair<int, int> > stk, vec;
int main() {
	scanf("%d%d%d %s", &n, &m, &k, str + 1);
	for (int i = 1; i <= n; i++) a[n - i + 1] = str[i] - '0';
	scanf(" %s", str + 1);
	for (int i = 1; i <= m; i++) b[m - i + 1] = str[i] - '0';
	for (int i = max(n, m); i >= 1; i--) {
		if (a[i] + b[i] == 1) stk.push_back(make_pair(i, a[i] * 2 + b[i]));
		if (a[i] + b[i] <= 1) continue;
		int z = k, pos = i, x = 3;
		while (!stk.empty()) {
			pair<int, int> tmp = stk.back();
			if (pos == tmp.first) {
				stk.pop_back();
				if ((x ^ tmp.second) == 3) {
					x = 3;
					if (z) z--;
					else break;
				} else if (x == 3) {
					x &= tmp.second;
					vec.push_back(make_pair(pos, tmp.second ^ 3));
				}
				pos++;
			} else if (x == 3) {
				if (tmp.first - pos > z) break;
				z -= tmp.first - pos;
				pos = tmp.first;
			} else break;
		}
		if (x == 3) ra[pos + z] = rb[pos + z] = 1;
		else vec.push_back(make_pair(pos, x));
		while (!vec.empty()) {
			stk.push_back(vec.back());
			vec.pop_back();
		}
	}
	while (!stk.empty()) {
		int i = stk.back().first;
		int x = stk.back().second;
		stk.pop_back();
		ra[i] = x / 2;
		rb[i] = x % 2;
	}
	int l = max(n, m) + k;
	while (ra[l] == 0) l--;
	for (int i = l; i >= 1; i--) putchar('0' + ra[i]);
	putchar('\n');
	l = max(n, m) + k;
	while (rb[l] == 0) l--;
	for (int i = l; i >= 1; i--) putchar('0' + rb[i]);
	putchar('\n');
	return 0;
}