1
2 2
1 1
1 2
 1
1 3
3
1 2 3
 1
1 1
1000
1000
 1
2 2
2 2
2 2
 5
4 5
10 8 6 4
1 2 3 4 5
1 1
3
3
1 1
3
2
5 3
1000 2 2 2 3
3 1 5
5 5
1 2 3 4 5
1 2 3 4 5
 1
4 4
1 1 1 1
1 2 3 4
 1
2 3
1 1
1 2 3

YES
1 1
 YES
1 3
 YES
1 1000
 YES
1 2
 YES
1 4
YES
1 3
NO
YES
1 3
YES
1 1
 YES
1 1
 YES
1 1

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class June28Comp {
	
	public static void main(String[] args) {
		System.out.println(addBinary("0", "0"));
	}
	
	public static String addBinary(String a, String b) {
        return addBinaryH(a, b, 0);
    }
    
    public static String addBinaryH(String a, String b, int carry) {
        if (a.length()==0 || b.length()==0) {
        	System.out.println("1:");
            if (carry==0) {
            	System.out.println("2:");
            	//System.out.println(a+b);
                return a+b;
            }
            if (a.length()==0) {
            	//System.out.println(addBinaryH(b, "1", 0));
                return addBinaryH(b, "1", 0);
            }
            //System.out.println(addBinaryH(a, "1", 0));
            return addBinaryH(a, "1", 0);
        }
        int sum=carry;
        if (a.charAt(a.length()-1)=='1') sum++;
        if (b.charAt(b.length()-1)=='1') sum++;
        System.out.println("SUM " + sum);
        if (sum==0) {
        	System.out.println("A:");
            return addBinaryH(a.substring(0, a.length()-1), b.substring(0, b.length()-1), 0) + "0";
        }
        if (sum==1) {
        	System.out.println("A:");
            return addBinaryH(a.substring(0, a.length()-1), b.substring(0, b.length()-1), 0) + "1";
        }
        if (sum==2) {
        	System.out.println("A:");
            return addBinaryH(a.substring(0, a.length()-1), b.substring(0, b.length()-1), 1) + "0";
        }
        return addBinaryH(a.substring(0, a.length()-1), b.substring(0, b.length()-1), 1) + "1";
    }
}
