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>
#define fo(i, x, y) for(int i = x, _b = y; i <= _b; i ++)
#define ff(i, x, y) for(int i = x, _b = y; i <  _b; i ++)
#define fd(i, x, y) for(int i = x, _b = y; i >= _b; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

#define gc getchar

int get() {
	char c = ' ';
	while(c != '0' && c != '1') c = gc();
	return c - '0';
}

const int N = 2e6 + 5;

int n, m, k;
int a[N], b[N];

struct P {
	int x, y;
	P(int _x = 0, int _y = 0) {
		x = _x, y = _y;
	}
};

P z[N]; int z0;

void dg(int w, int k) {
	//pp("%d %d %d %d\n", w, k, z0, z[z0].x);
	if(z0 == 0 || z[z0].x - w > k) {
		z[++ z0] = P(w + k, 3);
		return;
	}
	int l = z0;
	int nk = k - (z[z0].x - w);
	while(l > 1 && z[l - 1].x == z[l].x + 1 && z[l - 1].y == z[l].y) l --;
	P x1 = z[l]; x1.x ++;
	P x2 = z[z0]; x2.y ^= 3;
	if(l > 1 && z[l - 1].x == z[l].x + 1) {
		z0 = l - 2;
		dg(z[l].x + 1, nk);
		z[++ z0] = x2;
	} else {
		z0 = l - 1;
		z[++ z0] = x1;
		z[++ z0] = x2;
	}
}

int main() {
	scanf("%d %d %d", &n, &m, &k);
	fd(i, n, 1) a[i] = get(); 
	fd(i, m, 1) b[i] = get();
	fd(i, max(n, m), 1) {
		if(a[i] + b[i] == 1) {
			z[++ z0] = P(i, a[i] + b[i] * 2);
		} else
		if(a[i] + b[i] == 2) {
			dg(i, k);
		}
	}
	memset(a, 0, sizeof a);
	memset(b, 0, sizeof b);
	fo(i, 1, z0) a[z[i].x] = z[i].y & 1, b[z[i].x] = (z[i].y & 2) >> 1;
	int m1 = 0, m2 = 0;
	fo(i, 1, max(n, m) + k) {
		if(a[i]) m1 = i;
		if(b[i]) m2 = i;
	}
	fd(i, m1, 1) pp("%d", a[i]); hh;
	fd(i, m2, 1) pp("%d", b[i]); hh;
}