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: Wrong Answer)

#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int a[N],b[N]; vector<int> A,B;
struct node
{	int s,w;node *pre,*nxt;
	node(int _s=0,int _w=0):s(_s),w(_w){pre=nxt=0;}
}*S,*T;
inline void ins(node *p,int s,int w)
{node *x=new node(s,w);p->nxt->pre=x;x->nxt=p->nxt;p->nxt=x;x->pre=p;}
inline void del(node *x){x->pre->nxt=x->nxt;x->nxt->pre=x->pre;}
inline void work(int x,int k)
{	int la=x;
	for(node *i=S->nxt,*j=i->nxt;i!=T;i=j->nxt)
	{	if(i->s-la>k) break; k-=i->s-la;
		int cur=3&i->w; i->w=i->w==2?1:2;
		if(i->nxt!=T&&i->nxt->s!=i->s+1){ins(i,i->s+1,cur);return;}
		for(j=i->nxt;j!=T;j=j->nxt)
		if(j->s==j->pre->s+1){del(j);if(j->w!=cur){la=j->s;break;}}
		else{ins(j,j->s+1,cur);return;}
		if(j==T) return;
	}
	A.push_back(la+k),B.push_back(la+k);
}
int main()
{	int n,m,k; cin>>n>>m>>k; S=new node(0,0); T=new node(0,0); S->nxt=T; T->pre=S;
	for(rint i=n;i>=1;i--) scanf("%1d",&a[i]);
	for(rint i=m;i>=1;i--) scanf("%1d",&b[i]);
	for(rint i=max(n,m);i>min(n,m);i--) if(a[i]||b[i]) ins(S,i,a[i]<<1|b[i]);
	for(rint i=min(n,m);i;i--)
	if(a[i]&b[i]) work(i,k);
	else if(a[i]||b[i]) ins(S,i,a[i]<<1|b[i]);
	for(node *i=S->nxt;i!=T;i=i->nxt)
	if(i->w==1) B.push_back(i->s); else A.push_back(i->s);
	sort(A.begin(),A.end(),greater<int>());
	for(rint i=0;i<A.size();i++)
	{	putchar('1');
		for(rint j=A[i]-1;j>(i+1<A.size()?A[i+1]:0);j--) putchar('0');
	}
	cout<<endl; sort(B.begin(),B.end(),greater<int>());
	for(rint i=0;i<B.size();i++)
	{	putchar('1');
		for(rint j=B[i]-1;j>(i+1<B.size()?B[i+1]:0);j--) putchar('0');
	}
	return 0;
}