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

// Version 1.0 Stable

public class Gen {

	static int done = 0;

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

	static final int MAX_LENGTH = 500;
	static final int MAX_NUMBER = (int) 1e9;

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

	static void print() 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));

		out.println(data.size());
		for (int i = 0; i < data.size() - 1; i++)
			out.print(data.get(i) + " ");
		out.println(data.get(data.size() - 1));
		data.clear();
		out.close();
	}

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

		out = new PrintWriter("../preliminary/02");
		out.println("3");
		out.println("1 1 1");
		out.close();

		out = new PrintWriter("../preliminary/03");
		out.println("4");
		out.println("1 2 2 1");
		out.close();
	}

	static void genEqual(int n, int k) {
		int t = rand.nextInt(k) + 1;
		for (int i = 0; i < n; i++)
			data.add(t);
	}

	static void genEqual(int n, int k, int st) {
		int t = rand.nextInt(k) + 1 + st;
		for (int i = 0; i < n; i++)
			data.add(t);
	}

	static void genRandom(int n, int k) {
		for (int i = 0; i < n; i++)
			data.add(rand.nextInt(k) + 1);
	}

	static void genRandom(int n, int k, int st) {
		for (int i = 0; i < n; i++)
			data.add(rand.nextInt(k) + 1 + st);
	}

	static void genInto(int n, int k) {
		ArrayList<Integer> tmp = new ArrayList<Integer>();
		for (int i = 0; i < n / 2; i++) {
			tmp.add(rand.nextInt(k) + 1);
			data.add(tmp.get(i));
		}
		for (int i = 0; i < n / 2; i++)
			data.add(tmp.get(n / 2 - i - 1));
	}

	static void genInto(int n, int k, int st) {
		ArrayList<Integer> tmp = new ArrayList<Integer>();
		for (int i = 0; i < n / 2; i++) {
			tmp.add(rand.nextInt(k) + 1 + st);
			data.add(tmp.get(i));
		}
		for (int i = 0; i < n / 2; i++)
			data.add(tmp.get(n / 2 - i - 1));
	}

	static void genDiff(int n, int k) {
		ArrayList<Integer> tmp = new ArrayList<Integer>();
		int t = 1;
		for (int i = 0; i < n; i++) {
			tmp.add(t);
			t += rand.nextInt(Math.max(n / k, 1)) + 1;
		}
		Collections.shuffle(tmp, rand);
		for (int i = 0; i < n; i++)
			data.add(tmp.get(i));
	}

	static void genDiff(int n, int k, int st) {
		ArrayList<Integer> tmp = new ArrayList<Integer>();
		int t = 1 + st;
		for (int i = 0; i < n; i++) {
			tmp.add(t);
			t += rand.nextInt(Math.max(n / k, 1)) + 1;
		}
		Collections.shuffle(tmp, rand);
		for (int i = 0; i < n; i++)
			data.add(tmp.get(i));
	}

	static void genShift(int n, int k, int cnt) {
		ArrayList<Integer> tmp = new ArrayList<Integer>();
		for (int i = 0; i < cnt; i++)
			tmp.add(rand.nextInt(k) + 1);
		int cur = 0;
		while (cur < n) {
			for (int i = 0; i < cnt; i++) {
				data.add(tmp.get(i));
				cur++;
				if (cur == n)
					break;
			}
		}
	}

	static void genShift(int n, int k, int cnt, int st) {
		ArrayList<Integer> tmp = new ArrayList<Integer>();
		for (int i = 0; i < cnt; i++)
			tmp.add(rand.nextInt(k) + 1 + st);
		int cur = 0;
		while (cur < n) {
			for (int i = 0; i < cnt; i++) {
				data.add(tmp.get(i));
				cur++;
				if (cur == n)
					break;
			}
		}
	}

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

		genSimple();

		done = 0;

		// First test case (length <= 10, number <= 10)
		genEqual(10, 10);
		print();

		genRandom(10, 10);
		print();

		genInto(10, 10);
		print();

		genDiff(10, 10);
		print();

		genInto(5, 5);
		genRandom(5, 5);
		print();

		// Second test case (length <= 50, number <= 1000)
		genEqual(50, 1000);
		print();

		genDiff(50, 1000);
		print();

		genInto(50, 1000);
		print();

		for (int i = 0; i < 2; i++) {
			genRandom(50, 10 + i * 10, 100 * (i + 2));
			print();

			genInto(24, 6 + i * 20, 100 * (i + 2));
			genRandom(26, 4 + i * 10, 100 * (i + 2));
			print();
		}

		genShift(50, 1000, 2);
		print();

		genShift(50, 1000, 3);
		print();

		genShift(50, 1000, 5);
		print();

		genShift(50, 1000, 7);
		print();

		genRandom(10, 10, 900);
		genInto(10, 10, 900);
		genEqual(10, 10, 900);
		genDiff(10, 10, 900);
		genRandom(10, 10, 900);
		print();

		genDiff(49, 1000);
		data.add(data.get(0));
		print();

		genRandom(50, 4, 666);
		print();

		genInto(10, 10, 422);
		genEqual(10, 10, 422);
		genInto(20, 10, 422);
		genRandom(10, 5, 422);
		print();

		// Third test case (length <= 500, number <= 1e9)

		genRandom(MAX_LENGTH, 2, MAX_NUMBER - 3);
		print();

		for (int i = 4; i < 11; i += 2) {
			genRandom(MAX_LENGTH, i,
					MAX_NUMBER / 2 + rand.nextInt(MAX_NUMBER / 4));
			print();
		}

		genEqual(MAX_LENGTH, MAX_NUMBER);
		print();

		genDiff(MAX_LENGTH, MAX_NUMBER);
		print();

		genInto(MAX_LENGTH, 1000, MAX_NUMBER - 2000);
		print();

		ArrayList<Integer> size = new ArrayList<Integer>();
		size.add(360);
		size.add(420);
		size.add(500);

		ArrayList<Integer> partSize = new ArrayList<Integer>();
		partSize.add(5);
		partSize.add(10);
		partSize.add(20);
		partSize.add(50);

		for (int si : size) {
			for (int p : partSize) {
				for (int i = 0; i * 5 * p < si; i++) {
					int st = MAX_NUMBER / 2 + rand.nextInt(MAX_NUMBER / 4);
					genDiff(p - 1, p, st);
					genInto(p, p, st);
					genEqual(p, p, st);
					genRandom(p, p, st);
					genShift(p, p, 2, st);
					data.add(data.get(0));
				}
				print();
			}
		}
		int si = 480;
		for (int p : partSize) {
			for (int i = 0; i * 5 * p < si; i++) {
				int st = MAX_NUMBER / 2 + rand.nextInt(MAX_NUMBER / 4);
				genDiff(p - 1, p, st);
				genInto(p, p, st);
				genEqual(p, p, st);
				genRandom(p, p, st);
				genShift(p, p, 2, st);
				data.add(data.get(0));
			}
			Collections.shuffle(data, rand);
			print();
		}
		
		genInto(MAX_LENGTH / 2, 5, MAX_NUMBER - 10);
		genInto(MAX_LENGTH / 2, 5, MAX_NUMBER - 10);
		print();
		
		genInto(200, 10, MAX_NUMBER -  100);
		genEqual(100, 10, MAX_NUMBER - 100);
		genInto(200, 10, MAX_NUMBER - 100);
		print();
		
		genInto(200, 10, MAX_NUMBER -  100);
		genRandom(100, 10, MAX_NUMBER - 100);
		genInto(200, 10, MAX_NUMBER - 100);
		print();
		
		genInto(200, 10, MAX_NUMBER -  2000);
		genDiff(100, 10, MAX_NUMBER - 2000);
		genInto(200, 10, MAX_NUMBER - 2000);
		print();
		
		genShift(200, 10, 3, MAX_NUMBER - 2000);
		genDiff(100, 10, MAX_NUMBER - 2000);
		genShift(200, 10, 10, MAX_NUMBER - 2000);
		print();
		
		genShift(100, 10, 3, MAX_NUMBER -  1000);
		genDiff(100, 10, MAX_NUMBER - 1000);
		genEqual(100, 10, MAX_NUMBER - 999);
		genRandom(100, 10, MAX_NUMBER - 1001);
		genShift(100, 10, 10, MAX_NUMBER - 1000);
		print();
		return;
	}
}
