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 Java8 (OpenJDK 1.8.0) (judge verdict: Time Limit Exceeded)

import java.util.*;

public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();
            int K = sc.nextInt();
            String S = sc.next();
            String T = sc.next();
            ExNum s = ExNum.of(S);
            ExNum t = ExNum.of(T);
            for ( int k = 0; k <K; k++ ) {
            	ExNum z = s.bitwiseAnd(t);
            	s = s.add(z);
            	t = t.add(z);
            }
            System.out.println(s);
            System.out.println(t);
        }
    }
    
    
    private static void debug(String msg) {
//    	System.out.println(msg);
    }
    
    private static class ExNum {
    	private final String s;
    	
    	private ExNum(String s) {
    		this.s = s;
    	}
    	
    	public static ExNum of(String A) {
    		return new ExNum(A);
    	}
    	
    	public String toString() {
    		return s;
    	}
    
    	public ExNum bitwiseAnd(ExNum other) {
	        int nA = s.length();
	        String B = other.s;
	        int nB = B.length();
	        String big = null;
	        String small = null;
	        if ( nA > nB ) {
	            big = s;
	            small = B;
	        }
	        else {
	            big = B;
	            small = s;
	        }
	        char[] bigChar = big.toCharArray();
	        char[] smallChar = small.toCharArray();
	        int N = big.length();
	        int n = small.length();
	        String ret = "";
	        for ( int i = 0; i < n; i++ ) {
	            char d1 = bigChar[i+(N-n)];
	            char d2 = smallChar[i];
	            if ( d1 == '1' && d2 == '1' ) {
	            	ret += '1';
	            }
	            else {
	            	ret += '0';
	            }
	        }
	        debug(s + " & " + B + " = " + ret);
	        return ExNum.of(ret);
    	}
    
    	public ExNum add(ExNum other) {
	        int nA = s.length();
	        String B = other.s;
	        int nB = B.length();
	        String big = null;
	        String small = null;
	        if ( nA > nB ) {
	            big = s;
	            small = B;
	        }
	        else {
	            big = B;
	            small = s;
	        }
	        char[] bigChar = big.toCharArray();
	        char[] smallChar = small.toCharArray();
	        int N = big.length();
	        int n = small.length();
	        char[] adjustedSmallChar = new char[N];
	        for ( int i = 0; i < N-n; i++ ) {
	            adjustedSmallChar[i] = '0';
	        }
	        for ( int i = N-n; i < N; i++ ) {
	            adjustedSmallChar[i] = smallChar[i-(N-n)];
	        }
	        debug("bigChar = " + Arrays.toString(bigChar) + ", smallChar = " + Arrays.toString(adjustedSmallChar));
	        String ret = "";
	        boolean blnKuriagari = false;
	        for ( int i = 0; i < N; i++ ) {
	            char d1 = bigChar[N-1-i];
	            char d2 = adjustedSmallChar[N-1-i];
	            ExBit sum = ExBit.of(d1).add(ExBit.of(d2));
	            debug(d1 + " + " + d2 + " = " + sum);
	            if ( blnKuriagari ) {
	            	sum = sum.add(ExBit.ONE);
	            }
	            ret = sum.c + ret;
	            blnKuriagari = sum.isKuriagari();
	        }
	        if ( blnKuriagari ) {
	        	ret = '1' + ret;
	        }
	        debug(s + " + " + B + " = " + ret);
	        return ExNum.of(ret);
    	}
    }

    private static class ExBit {
    	
    	private final static ExBit ZERO = ExBit.of('0');
    	private final static ExBit ONE = ExBit.of('1');
    	
        private final boolean blnKuriagari;
        private final char c;

        private ExBit(boolean blnKuriagari, char c) {
            this.blnKuriagari = blnKuriagari;
            this.c = c;
        }

        public static ExBit of(char c) {
            return new ExBit(false, c);
        }

        public boolean isKuriagari() {
             return blnKuriagari;
        }
        
        @Override
        public String toString() {
        	StringBuilder sb = new StringBuilder();
        	if ( isKuriagari() ) {
        		sb.append('1');
        	}
        	sb.append(c);
        	return sb.toString();
        }

        public ExBit add(ExBit other) {
            if ( isKuriagari() || other.isKuriagari() ) {
               throw new UnsupportedOperationException();
            }
            char d1 = this.c;
            char d2 = other.c;
            char d;
            boolean b = false;
            if ( d1 == '0' ) {
                d = d2;
            }
            else if ( d2 == '0' ) {
                d = d1;
            }
            else {
                d = '0';
                b = true;
            }
            return new ExBit(b, d);
        }
    }
}