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

public class TestsGen {
	static int testcount = 0;

	static Random random = new Random(36498732);
	
	static int MAXN = 1000;
	static int MAX = (int) 1e9;

	static void write(int[] a, int k) throws IOException {
		PrintWriter out = new PrintWriter(String.format("%02d", ++testcount));
		System.out.println("Generating test #" + testcount);
		out.println(a.length + " " + k);
		for (int i = 0; i < a.length; i++) {
			if (i > 0) out.print(" ");
			out.print(a[i]);
		}
		out.println();
		out.close();
	}
	
	static void writeRand(int n, int k, int MAX) throws IOException {
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = random.nextInt(MAX) + 1;
		}
		write(a, k);
	}

	static void writeEq(int n, int k, int v) throws IOException {
		int[] a = new int[n];
		Arrays.fill(a, v);
		write(a, k);
	}

	static void writeGood(int n, int k, int MAX) throws IOException {
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = random.nextInt(MAX) + 1;
		}
		Arrays.sort(a);
		for (int i = 0; i < n; i++) {
			int cnt = 0;
			int m = -1;
			for (int j = 0; j < i; j++) {
				if (a[i] % k == a[j] % k) {
					cnt++;
					if (random.nextInt(cnt) == 0) {
						m = j;
					}
				}
			}
			if (m != -1) {
				int t = a[m]; a[m] = a[i]; a[i] = t;
			}
		}
		write(a, k);
	}

	static void writeAlmost(int n, int k, int MAX) throws IOException {
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = random.nextInt(MAX) + 1;
		}
		Arrays.sort(a);
		for (int i = 0; i < n; i++) {
			int cnt = 0;
			int m = -1;
			for (int j = 0; j < i; j++) {
				if (a[i] % k == a[j] % k) {
					cnt++;
					if (random.nextInt(cnt) == 0) {
						m = j;
					}
				}
			}
			if (m != -1) {
				int t = a[m]; a[m] = a[i]; a[i] = t;
			}
		}
		{
			int i = random.nextInt(n);
			int j = random.nextInt(n);
			int t = a[i]; a[i] = a[j]; a[j] = t;
		}
		write(a, k);
	}

	public static void main(String[] args) throws IOException {
		while (new File(String.format("%02d.t", testcount + 1)).exists()) {
			testcount++;
		}
		writeGood(10, 2, 100);
		writeGood(65, 7, 60);
		writeGood(99, 13, 50);
		writeGood(999, 103, 300);
		writeEq(MAXN, 1, 1);
		writeEq(MAXN, 1, MAX);
		writeEq(MAXN, MAX, MAX);
		for (int k = 2; k <= 10; k++) {
			writeGood(MAXN, k, MAX);
			writeAlmost(MAXN, k, MAX);
		}
		writeGood(MAXN, random.nextInt(MAXN), MAX);
		writeGood(MAXN, random.nextInt(MAX), MAX);
		writeGood(MAXN, MAX, MAX);
		writeRand(10, 1, 100);
		writeRand(MAXN, 1, 10);
		writeRand(MAXN, 1, MAX);
		writeRand(MAXN, random.nextInt(MAX), MAX);
		writeGood(MAXN, random.nextInt(MAX), MAX);
		writeAlmost(MAXN, random.nextInt(MAX), MAX);
		writeRand(MAXN, MAX, MAX);
		writeAlmost(MAXN, MAX, MAX);
	}

}
