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

public class ReagentsTestGen {

	static class RandomUtils {
		static int randRange(int from, int to) {
			return rng.nextInt(to - from + 1) + from;
		}

		static int[] shuffleArray(int[] a) {
			int n = a.length;
			int[] res = a.clone();
			for (int i = 1; i < n; i++) {
				int id = rng.nextInt(i + 1);
				int tmp = res[id];
				res[id] = res[i];
				res[i] = tmp;
			}
			return res;
		}
	}

	final static Random rng = new Random(577215664);
	final int MAX_A = 1_000_000_000;
	final int MAX_N = 200_000;

	public static void main(String[] args) throws Exception {
		new ReagentsTestGen().generate();
	}

	PrintWriter out;
	boolean isPreliminary;
	int countTests = 0;

	void generate() throws Exception {
		generatePreliminary();
		generateTests();
	}

	void generatePreliminary() {
		isPreliminary = true;
		printTest(new int[] { 3, 5 });
		printTest(new int[] { 4, 6, 6 });
	}

	void generateTests() {
		countTests = 0;
		isPreliminary = false;

		generateSmall();
		generateMedium();
		generateMax();
	}

	int[] randomArray(int size, int min, int max) {
		int[] a = new int[size];
		for (int i = 0; i < size; i++) {
			a[i] = RandomUtils.randRange(min, max);
		}
		return a;
	}

	private void generateSmall() {
		for (int n = 1; n <= 5; n++) {
			printTest(randomArray(n, 1, 10));
		}

		printTest(new int[] { 1, 1, 1, 1, 1, 1, 1, 1 });
		printTest(new int[] { 1, 2, 3, 4, 5, 6, 7, 8 });
		printTest(new int[] { 5, 5, 4, 4, 3, 3, 2, 2 });
		printTest(randomArray(8, 1000, 1003));
		printTest(randomArray(8, MAX_A - 1000, MAX_A));
	}

	private void generateMedium() {
		int[] ns = randomArray(5, 100, 1000);
		int[] mins = randomArray(5, 100, 1000000);
		int[] lens = randomArray(5, 10, 1000000);
		for (int i = 0; i < ns.length; i++) {
			printTest(randomArray(ns[i], mins[i], mins[i] + lens[i]));
		}
		
		int n = 1000;
		int tmp = rng.nextInt(100) + 1;
		printTest(randomArray(n, tmp, tmp));
		printTest(kDifferent(n, 3, 1, 1000));
		printTest(kDifferent(n, 20, 1, 10000));
		printTest(randomArray(n, 1, MAX_A));
		printTest(randomArray(n, MAX_A - 10000, MAX_A));
	}

	private int[] kDifferent(int n, int k, int min, int max) {
		int[] vals = randomArray(k, min, max);
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = vals[rng.nextInt(k)];
		}
		return a;
	}

	private void generateMax() {
		int[] ns = randomArray(10, 20_000, 200_000);
		int[] mins = randomArray(10, 1, MAX_A / 2);
		int[] lens = randomArray(10, 1, MAX_A / 2);
		for (int i = 0; i < ns.length; i++) {
			printTest(randomArray(ns[i], mins[i], mins[i] + lens[i]));
		}
		
		int n = MAX_N;
		printTest(kDifferent(n, 1, 1, MAX_A));
		printTest(kDifferent(n, 3, 1, 1000));
		printTest(kDifferent(n, 10, 1, 10000));
		printTest(kDifferent(n, 100, 1, 100000));
		printTest(kDifferent(n, 2000, 1, 1000000));
		
		for (int i = 0; i < 5; i++) {
			int min = RandomUtils.randRange(MAX_A - 2_000_000, MAX_A - 1_000_000);
			int len = rng.nextInt(1_000_000) + 1;
			printTest(randomArray(n, min, min + len));
		}
	}

	void printTest(int[] a) {
		try {
			countTests++;
			String fileName = (isPreliminary) ? ("../preliminary/")
					: ("../tests/");
			fileName += String.format("%02d", countTests);
			out = new PrintWriter(fileName);

			out.println(a.length);
			for (int i = 0; i < a.length; i++) {
				out.print(a[i]);
				if (i + 1 == a.length) {
					out.println();
				} else {
					out.print(' ');
				}
			}

			System.out.println("Done printing test #" + countTests);
			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
}