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

// Version 1.0 Stable

public class TestsGen {

	static int done = 0;

	static final Random rand = new Random(556668949239L);

	static final int MAX_SIZE1 = 100;
	static final int MAX_SIZE2 = 10000;
	static final int MAX_SIZE3 = 100000;
	static final int MAX_VALUE = (int) 1e9;

	static ArrayList<Integer> data = new ArrayList<Integer>();

	static void print(int k) throws IOException {
		done++;
		System.err.println(done);
		PrintWriter out;
		if (done < 10)
			out = new PrintWriter("../tests/0" + String.valueOf(done));
		else
			out = new PrintWriter("../tests/" + String.valueOf(done));
		Collections.shuffle(data, rand);
		out.println(k);
		for (int i = 0; i < 2 * k - 1; i++)
			out.print(data.get(i) + " ");
		out.println(data.get(2 * k - 1));
		data.clear();
		out.close();
	}

	static void genSimple() throws IOException {
		PrintWriter out;
		out = new PrintWriter("../preliminary/01");
		out.println("2");
		out.println("1 2 4 8");
		out.close();
		out = new PrintWriter("../preliminary/02");
		out.println("3");
		out.println("23 42 42 23 1 2");
		out.close(); 
	}

	static void genRand(int cnt, int maxValue) throws IOException {
		for (int i = 0; i < 2 * cnt; i++) {
			data.add(rand.nextInt(maxValue) + 1);
		}
	}

	static void genEquals(int cnt, int maxValue) throws IOException {
		int tmp = rand.nextInt(maxValue) + 1;
		for (int i = 0; i < 2 * cnt; i++) {
			data.add(tmp);
		}
	}

	static void genStep(int cnt, int step) throws IOException {
		int cur = 1;
		for (int i = 0; i < 2 * cnt; i++) {
			data.add(cur);
			cur += step;
		}
	}

	static void genUp(int cnt) throws IOException {
		int cur = rand.nextInt(1000) + 1;
		int step = 0;
		for (int i = 0; i < 2 * cnt; i++) {
			data.add(cur);
			cur += ++step;
			if (cur > MAX_VALUE)
				cur = MAX_VALUE;
		}
	}

	static void genUp(int cnt, int base) throws IOException {
		int cur = base;
		int step = 0;
		for (int i = 0; i < 2 * cnt; i++) {
			data.add(cur);
			cur += ++step;
			if (cur > MAX_VALUE)
				cur = MAX_VALUE;
		}
	}

	static void genPair(int cnt, int maxValue) throws IOException {
		for (int i = 0; i < cnt; i++) {
			int t = rand.nextInt(maxValue) + 1;
			data.add(t);
			data.add(t);
		}
	}

	static void genDown(int cnt) throws IOException {
		int cur = MAX_VALUE - (rand.nextInt(1000) + 1);
		int step = 0;
		for (int i = 0; i < 2 * cnt; i++) {
			data.add(cur);
			cur -= ++step;
			if (cur < 1)
				cur = 1;
		}
	}

	static void genUpDown(int cnt) throws IOException {
		int cur1 = MAX_VALUE / 2;
		int cur2 = MAX_VALUE / 2;
		int step = 0;
		for (int i = 0; i < 2 * cnt; i++) {
			data.add(cur1);
			data.add(cur2);
			cur1 += step;
			cur2 -= ++step;
			if (cur1 > MAX_VALUE || cur2 < 1) {
				cur2 = MAX_VALUE;
				cur1 = 1;
			}
		}
	}

	static void genSpecial(int base) throws IOException {
		for (int i = 0; i < 10; i++) {
			data.add(base + (1 << i));
			data.add(base);
		}
	}

	static void genSpecial2(int cnt, int base) throws IOException {
		for (int i = 0; i < cnt; i++) {
			data.add(base);
			data.add(base + i);
		}
	}

	public static void main(String[] args) throws IOException {
		boolean f = (new File("../preliminary")).mkdir();
		f = new File("../tests").mkdir();

		genSimple();

		done = 0;
		// Test small n <= 100
		// Test #1
		genRand(1, 100);
		print(1);

		// Test #2
		genRand(2, 100);
		print(2);

		// Test #3
		for (int i = 0; i < MAX_SIZE1 / 10; i++) {
			genSpecial(i * 10000 + 1);
		}
		print(MAX_SIZE1);

		// Test #4
		genSpecial2(MAX_SIZE1, rand.nextInt(1000));
		print(MAX_SIZE1);

		// Test #5
		genEquals(MAX_SIZE1, rand.nextInt(1000));
		print(MAX_SIZE1);

		// Test #6
		genStep(97, 23);
		print(97);

		// Test #7
		genPair(56, 10000);
		print(56);

		// Test #8
		genDown(MAX_SIZE1);
		print(MAX_SIZE1);

		// Test #9
		genUp(MAX_SIZE1);
		print(MAX_SIZE1);

		// Test #10
		genUpDown(MAX_SIZE1);
		print(MAX_SIZE1);

		// Test middle n <= 10000

		// Test #11-12
		for (int i = 0; i < 2; i++) {
			genRand(MAX_SIZE2, MAX_VALUE);
			print(MAX_SIZE2);
		}

		// Test #13
		for (int i = 0; i < MAX_SIZE2 / 10; i++) {
			genSpecial(i * 10000 + 1);
		}
		print(MAX_SIZE2);

		// Test #14
		genSpecial2(MAX_SIZE2, rand.nextInt(MAX_VALUE / 1000));
		print(MAX_SIZE2);

		// Test #15
		genEquals(MAX_SIZE2, rand.nextInt(MAX_VALUE / 1000));
		print(MAX_SIZE2);

		// Test #16
		genStep(9700, 23917);
		print(9700);

		// Test #17
		genPair(5600, MAX_VALUE);
		print(5600);

		// Test #18
		genDown(MAX_SIZE2);
		print(MAX_SIZE2);

		// Test #19
		genUp(MAX_SIZE2);
		print(MAX_SIZE2);

		// Test #20
		genUpDown(MAX_SIZE2);
		print(MAX_SIZE2);

		// Test large n <= 100000

		// Test #21-31
		for (int i = 0; i < 11; i++) {
			int size = MAX_SIZE3 * 2 / 3 + rand.nextInt(MAX_SIZE3 / 3);
			genRand(size, MAX_VALUE);
			print(size);
		}
		// Test #32
		for (int i = 0; i < 33; i++) {
			genUp(3003, 12345678);			
		}
		print(99099);

		// Test #33
		for (int i = 0; i < MAX_SIZE3 / 10; i++) {
			genSpecial(i * 10000 + 1);
		}
		print(MAX_SIZE3);

		// Test #34
		genSpecial2(MAX_SIZE3, rand.nextInt(MAX_VALUE / 1000));
		print(MAX_SIZE3);

		// Test #35
		genEquals(MAX_SIZE3, rand.nextInt(MAX_VALUE / 1000));
		print(MAX_SIZE3);

		// Test #36
		genStep(94223, 42);
		print(94223);

		// Test #37
		genPair(56239, MAX_VALUE);
		print(56239);

		// Test #38
		genDown(MAX_SIZE3);
		print(MAX_SIZE3);

		// Test #39
		genUp(MAX_SIZE3);
		print(MAX_SIZE3);

		// Test #40
		genUpDown(MAX_SIZE3);
		print(MAX_SIZE3);

		return;
	}
}
