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

public class TestGen {
	static int done = 0;
	static final Random rnd = new Random(556668949239L);

	static int rand(int n) {
		if (n == 0)
			return 1;
		return rnd.nextInt(n);
	}

	static final int MAXN0 = 100;
	static final int MAXN1 = 100_000;
	static final int MAXX0 = 3;
	static final int MAXX1 = 100;
	static final int MAXC = 10_000;
	static ArrayList<Integer> pasha = new ArrayList<Integer>();
	static ArrayList<Integer> grinya = new ArrayList<Integer>();

	static void print() throws IOException {
		done++;
		System.err.println("Generation test #" + done);
		PrintWriter out;
		if (done < 10)
			out = new PrintWriter("../tests/0" + String.valueOf(done));
		else
			out = new PrintWriter("../tests/" + String.valueOf(done));
		out.println(pasha.size() + " " + grinya.size());
		for (int i = 0; i < pasha.size() - 1; i++) {
			out.print(pasha.get(i) + " ");
		}
		out.println(pasha.get(pasha.size() - 1));
		for (int i = 0; i < grinya.size() - 1; i++) {
			out.print(grinya.get(i) + " ");
		}
		out.println(grinya.get(grinya.size() - 1));
		pasha.clear();
		grinya.clear();
		out.close();
	}

	// START GENS

	static void gen_sample() throws IOException {
		PrintWriter out;
		out = new PrintWriter("../preliminary/01");
		out.println("3 2");
		out.println("1 2 3");
		out.println("3 2");
		out.close();
		out = new PrintWriter("../preliminary/02");
		out.println("2 2");
		out.println("1 101");
		out.println("100 1");
		out.close();
	}

	static void gen_rand(int n, int x, int maxc) throws IOException {
		for (int i = 0; i < n; i++) {
			pasha.add(rand(maxc) + 1);
		}
		for (int i = 0; i < x; i++) {
			grinya.add(rand(maxc) + 1);
		}
		print();
	}

	static void gen_right(int n, int x, int maxc) throws IOException {
		for (int i = 0; i < n; i++) {
			pasha.add(rand(maxc) + 1);
		}
		int a[] = new int[x];
		n -= x;
		for (int i = 0; i < x - 1; i++) {
			a[i] = 1;
			if (n <= 0) {
				n = 1;
			}
			int k = rand(n);
			n -= k;
			a[i] += k;
		}
		a[x - 1] = n;
		int sum[] = new int[x];
		int k = 0;
		for (int i = 0; i < x; i++) {
			sum[i] = 0;
			for (int j = 0; j < a[i]; j++) {
				sum[i] += pasha.get(k);
				k++;
			}
		}
		for (int i = 0; i < x; i++) {
			grinya.add(rand(sum[i]) + 1);
		}
		print();
	}
	
	static void gen_hand0() throws IOException {
		pasha.add(1);
		grinya.add(2);
		grinya.add(3);
		print();
	}
	
	static void gen_hand1() throws IOException {
		pasha.add(1);
		pasha.add(3);
		pasha.add(100);
		grinya.add(100);
		grinya.add(3);
		print();
	}

	// FINISH GENS
	
	static int min(int a, int b) {
		if(a > b)
			return b;
		return a;
	}

	public static void main(String[] args) throws IOException {
		new File("../preliminary").mkdir();
		new File("../tests").mkdir();
		done = 0;
		gen_sample();
		gen_hand0();
		gen_hand1();
		gen_rand(MAXX0, MAXX0, MAXC);
		gen_rand(MAXX0, MAXX0, MAXC);
		for (int i = 1; i <= 1; i++) {
			gen_rand(i * 20 - 9 + rand(20), 1, 1000);
			gen_right(i * 20 - 9 + rand(20), 1, 1000);
		}
		for (int i = 1; i <= 3; i++) {
			gen_rand(i * 20 - 9 + rand(20), 2, MAXC);
			gen_right(i * 20 - 9 + rand(20), 2, MAXC);
		}
		for (int i = 1; i <= 4; i++) {
			gen_rand(i * 20 - 9 + rand(20), 3, MAXC);
			gen_right(i * 20 - 9 + rand(20), 3, MAXC);
		}
		gen_hand0();
		gen_hand1();
		gen_rand(MAXX1, MAXX1, MAXC);
		gen_rand(MAXX1, MAXX1, MAXC);
		for(int i = 1; i <= 13; i++) {
			int x = rand(50) + 51;
			int q = i * 600 - 20 + rand(40);
			gen_rand(q, min(q, x), MAXC);
			q = i * 600 - 20 + rand(40);
			gen_right(q, min(q, x), MAXC);
		}
		return;
	}
}
