import java.io.*;
import java.util.*;

public class TestGen {

    static PrintWriter out;
    static Random rnd = new Random(0);
    static int tNumber = 1;
    static PrintWriter testDescr;
    static int sb = 0;
    static final int sMaxK = 999999999;


    static void printTest(int n, int m, ArrayList<Integer> a, ArrayList<Integer> b, String comment) throws IOException {
        System.out.println(String.format("Generating test %d", tNumber));
        if (tNumber < 10)
            out = new PrintWriter("../tests/0" + tNumber);
        else
            out = new PrintWriter("../tests/" + tNumber);
        m = a.size();
        n = b.size();
        out.println(n + " " + m);
        for (int i = 0; i < n; i++) {
        	out.print(b.get(i));
        	if (i != n - 1)
        		out.print(" ");

        }
        out.println();
        for (int i = 0; i < m; i++) {
            out.print(a.get(i));
        	if (i != m - 1)
        		out.print(" ");
        }
        out.println();
        out.close();
        testDescr.println("../tests/" + ((tNumber > 9) ? tNumber : ("0" + tNumber)) + ", folder=tests, subtask=subtask" + sb + ", points=0, comment=\"" + comment + "\"");
        tNumber++;        
    }
    
    static void genSample() throws FileNotFoundException {
        out = new PrintWriter("../preliminary/01");        
        out.println("8 6");         
        out.println("0 2 3 4 5 6 8 13");
        out.println("1 3 5 6 9 12");
        out.close();                
        testDescr.println("../preliminary/01, folder=preliminary, subtask=subtask0, points=0, comment=\"sample 1\"");
    }
    
    static int randFromTo(int l, int r) {
        return rnd.nextInt(r - l + 1) + l;      
    }

	static ArrayList<Integer> genArray(int n, int l, int r) {
    	ArrayList<Integer> ans = new ArrayList<Integer>();
   		for (int i = 0; i < n; i++) {
       		int a = randFromTo(l, r);
       		ans.add(a);        		
       	}
       	Collections.sort(ans);
        norm(ans);
        return ans;       
    }

    static void norm(ArrayList<Integer> ans) {
        for (int i = ans.size() - 1; i > 0; --i) {
            if (ans.get(i).equals(ans.get(i - 1))) {
                ans.remove(i);
            }
            
        }        
    }
        
    public static void main(String[] args) throws IOException {
        new File("../preliminary").mkdir();
        new File("../tests").mkdir();        
        testDescr = new PrintWriter("../tests.desc");
        genSample();
        {
            sb = 1;
            for (int i = 0; i < 5; ++i) {
                int n = randFromTo(50, 100);
                int m = randFromTo(50, 100);
                printTest(n, m, genArray(n, 0, 1000), genArray(m, 0, 1000), "n=" + n + ", m="+m);
            }
            for (int i = 0; i < 5; ++i) {
                int n = randFromTo(500, 1000);
                int m = randFromTo(500, 1000);
                printTest(n, m, genArray(n, 0, 1000), genArray(m, 0, 1000), "n=" + n + ", m="+m);
            }
            for (int i = 0; i < 5; ++i) {
                int n = randFromTo(500, 1000);
                int m = randFromTo(500, 1000);
                printTest(n, m, genArray(n, 0, sMaxK), genArray(m, 0, sMaxK), "n=" + n + ", m="+m);
            }
            {
                int n = 1000;
                int m = 1000;
                printTest(n, m, genArray(n, 0, sMaxK), genArray(m, 0, sMaxK), "n=" + n + ", m="+m);
            }
            {
                int n = 1000;
                int m = 1000;
                ArrayList<Integer> a = genArray (n / 2, 0, (sMaxK / 4));
                ArrayList<Integer> b = genArray (m / 2, (sMaxK / 4), 2 * (sMaxK / 4));
                ArrayList<Integer> c = genArray (n / 2, 2 * sMaxK / 4, 3 * (sMaxK / 4));
                ArrayList<Integer> d = genArray (m / 2, 3 * (sMaxK / 4), 4 * (sMaxK / 4));
                a.addAll(c);
                b.addAll(d);
                norm(a);
                norm(b);
                printTest(a.size(), b.size(), a, b, "n=" + n + ", m="+m);
            }
            {
                int n = 1000;
                int m = 1000;
                ArrayList<Integer> a = genArray (n, 0, 3 * (sMaxK / 4));
                ArrayList<Integer> b = genArray (m, (sMaxK / 4), 4 * (sMaxK / 4));
                printTest(n, m, a, b, "n=" + n + ", m="+m);    
            }
            for (int it = 0; it < 5; ++it) {
                int k1 = randFromTo(10, 100);
                int k2 = randFromTo(10, 100);
                int k3 = randFromTo(10, 100);

                int n = 1000;
                int m = 1000;
                int nmba = n / k1;
                int nmbb = m / k2;
                int t = sMaxK / Math.max(Math.max(k1, k2), k3);
                ArrayList<Integer> a = new ArrayList<Integer>();
                ArrayList<Integer> b = new ArrayList<Integer>();
                int y = 0;
                for (int i = 0; i < k1; ++i) {
                    a.addAll(genArray(nmba, y, y + t));
                    y += t;
                }
                y = 0;
                for (int i = 0; i < k2; ++i) {
                    b.addAll(genArray(nmbb, y, y + t));
                    y += t;
                }
                printTest(a.size(), b.size(), a, b, "n="+a.size()+", m="+b.size());
            }
            testDescr.println("comment_subtask1=\"n &lt;= 1000, m &lt;= 1000, a_i &lt;= 10^9, b_i &lt;= 10^9\"\nbonus_subtask1=50");
        }
        {
            sb = 2;
            for (int i = 0; i < 5; ++i) {
                int n = randFromTo(5000, 100000);
                int m = randFromTo(5000, 100000);
                printTest(n, m, genArray(n, 0, 1000), genArray(m, 0, 1000), "n=" + n + ", m="+m);
            }
            for (int i = 0; i < 5; ++i) {
                int n = randFromTo(50000, 100000);
                int m = randFromTo(50000, 100000);
                printTest(n, m, genArray(n, 0, sMaxK), genArray(m, 0, sMaxK), "n=" + n + ", m="+m);
            }
            for (int i = 0; i < 5; ++i) {
                int n = randFromTo(500, 1000);
                int m = randFromTo(500, 1000);
                printTest(n, m, genArray(n, 0, sMaxK), genArray(m, 0, sMaxK), "n=" + n + ", m="+m);
            }
            {
                int n = 100000;
                int m = 100000;
                printTest(n, m, genArray(n, 0, sMaxK), genArray(m, 0, sMaxK), "n=" + n + ", m="+m);
            }
            {
                int n = 100000;
                int m = 100000;
                ArrayList<Integer> a = genArray (n / 2, 0, (sMaxK / 4));
                ArrayList<Integer> b = genArray (m / 2, (sMaxK / 4), 2 * (sMaxK / 4));
                ArrayList<Integer> c = genArray (n / 2, 2 * sMaxK / 4, 3 * (sMaxK / 4));
                ArrayList<Integer> d = genArray (m / 2, 3 * (sMaxK / 4), 4 * (sMaxK / 4));
                a.addAll(c);
                b.addAll(d);
                norm(a);
                norm(b);
                printTest(n, m, a, b, "n=" + n + ", m="+m);
            }
            {
                int n = 100000;
                int m = 100000;
                ArrayList<Integer> a = genArray (n, 0, 3 * (sMaxK / 4));
                ArrayList<Integer> b = genArray (m, (sMaxK / 4), 4 * (sMaxK / 4));
                printTest(n, m, a, b, "n=" + n + ", m="+m);    
            }
            for (int it = 0; it < 5; ++it) {
                int k1 = randFromTo(10, 100);
                int k2 = randFromTo(10, 100);
                int k3 = randFromTo(10, 100);
                int n = 100000;
                int m = 100000;
                int nmba = n / k1;
                int nmbb = m / k2;
                int t = sMaxK / Math.max(Math.max(k1, k2), k3);
                ArrayList<Integer> a = new ArrayList<Integer>();
                ArrayList<Integer> b = new ArrayList<Integer>();
                int y = 0;
                for (int i = 0; i < k1; ++i) {
                    a.addAll(genArray(nmba, y, y + t));
                    y += t;
                }
                y = 0;
                for (int i = 0; i < k2; ++i) {
                    b.addAll(genArray(nmbb, y, y + t));
                    y += t;
                }
                printTest(a.size(), b.size(), a, b, "n="+a.size()+", m="+b.size());
            }

            testDescr.println("comment_subtask2=\"n &lt;= 100000, m &lt;= 100000, a_i &lt;= 10^9, b_i &lt;= 10^9\"\nbonus_subtask2=50");
        }
        testDescr.close();
    }                 
    
}
