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

public class TestsGen {
	static int testcount = 0;

	static int MAXN = 100000;
	static int MAX = 1000000000;

	static Random random = new Random(93485234);

	static void write(int[] a, int k) throws IOException {
		PrintWriter out = new PrintWriter(String.format("%02d", ++testcount));
		System.out.println("Writing 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 max) throws IOException {
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = random.nextInt(max) + 1;
		}
		write(a, random.nextInt(max) + 1);
	}

	static int randInt(int l, int r) {
		return random.nextInt(r - l + 1) + l;
	}

	static int[] gen0(int l, long maxv) {
		int[] ans = new int[l];
		long sum = 0;
		maxv = Math.min(maxv, MAX - (1 << 29));
		for (int i = 0; i < l; i++) {
			int min = (int) Math.max(-maxv, -sum - maxv * (l - i - 1));
			int max = (int) Math.min(maxv, -sum + maxv * (l - i - 1));
			ans[i] = randInt(min, max);
			sum += ans[i];
		}
		return ans;
	}

	static int[] gen1(int l, long maxv, int k) {
		int[] ans = new int[l];
		long sum = 0;
		int shift = random.nextInt(2) * 8;
		Arrays.fill(ans, 1 << 29);
		maxv = Math.min(maxv, MAX - (1 << 29) - 2);
		for (int i = 0; i < l - 8; i++) {
			int min = (int) Math.max(-maxv, -sum - maxv * (l - 8 - i - 1));
			int max = (int) Math.min(maxv, -sum + maxv * (l - 8 - i - 1));
			ans[i + shift] = randInt(min, max);
			sum += ans[i + shift];
		}
		return ans;
	}
	
	static void genGood(int n, int max, int l) throws IOException {
		int[] goodpart = gen0(l, max / 2 - 2);
		if (1l * n * max > Integer.MAX_VALUE) {
			goodpart = gen1(l, max / 2 - 2, max / 2);
		}
		int minv = Integer.MAX_VALUE;
		int maxv = Integer.MIN_VALUE;
		for (int x : goodpart) {
//			if (x != (1 << 29) && x != -(1 << 29)) {
				minv = Math.min(minv, x);
				maxv = Math.max(maxv, x);
//			}
		}
//		System.out.println(minv + " " + maxv);
		minv = -minv + 1;
		maxv = max - maxv;
//		System.out.println(minv + " " + maxv);
		int k = randInt(minv, maxv);
		long sum = 0;
		for (int i = 0; i < goodpart.length - 8; i++) {
			sum += goodpart[i];
		}
//		System.out.println(sum);
		int[] a = new int[n];
		int pos = randInt(0, n - l);
		for (int i = 0; i < n; i++) {
			a[i] = randInt(1, max);
		}
		for (int i = 0; i < l; i++) {
			a[pos + i] = goodpart[i] + k;
		}
		write(a, k);
	}

	static void genGood2(int n, int max) throws IOException {
		ArrayList<Integer> len = new ArrayList<Integer>();
		int s = 0;
		while (s < n / 2) {
			int t = randInt(1, Math.min(n / 10, n / 2 - s));
			len.add(t);
			s += t;
		}
		ArrayList<int[]> good = new ArrayList<int[]>();
		for (int i = 0; i < len.size(); i++) {
			if (1l * n * max <= Integer.MAX_VALUE || len.get(i) <= 8) {
				good.add(gen0(len.get(i), max / 2 - 2));
			} else {
				good.add(gen1(len.get(i), max / 2 - 2, max / 2 - 2));
			}
		}
		Collections.shuffle(good, random);
		int minv = Integer.MAX_VALUE;
		int maxv = Integer.MIN_VALUE;
		for (int[] ar : good) {
			for (int x : ar) {
//				if (x != (1 << 29) && (x != -(1 << 29))) {
					minv = Math.min(minv, x);
					maxv = Math.max(maxv, x);
//				}
			}
		}
		minv = -minv + 1;
		maxv = max - maxv;
//		System.out.println(minv + " " + maxv);
		int k = randInt(minv, maxv);
		int[] ss = new int[good.size()];
		for (int i = 0; i < ss.length; i++) {
			ss[i] = good.get(i).length;
		}
		for (int i = ss.length - 2; i >= 0; i--) {
			ss[i] = ss[i] + ss[i + 1];
		}
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = randInt(1, max);
		}
		int pos = 0;
		for (int i = 0; i < good.size(); i++) {
			int t = randInt(0, n - pos - ss[i]);
			pos += t;
			for (int j = 0; j < good.get(i).length; j++) {
				a[pos++] = good.get(i)[j] + k;
			}
		}
		write(a, k);
	}
	
	static void writeEq(int n, int k) throws IOException {
		int[] a = new int[n];
		Arrays.fill(a, k);
		write(a, k);
	}

	public static void main(String[] args) throws IOException {
		while (new File(String.format("%02d.t", testcount + 1)).exists()) {
			testcount++;
		}
		//2

		genGood(10, 100, 5);
		genGood(20, 1000, 19);
		genGood(100, 10000000, 100);
		writeRand(100, 1000000);
		genGood2(100, 100);
		writeEq(100, 23917);
		genGood2(57, 100000);
		genGood2(97, 1000);
		
		genGood2(99, MAX);
		genGood(50, MAX, 13);
		genGood(9, MAX, 9);
		genGood2(50, MAX);
		genGood(87, MAX, 57);
		//15
		genGood(999, 20, 36);
		genGood(1000, 1000, 566);
		genGood(1000, 1000000, 1000);
		genGood(954, 100, 512);
		writeRand(1000, 100000);
		genGood2(1000, 1000000);
		genGood2(876, 10000);
		genGood2(937, 100000);
		genGood2(666, 66666);
		genGood2(786, 54345);
		
		genGood2(1000, MAX);
		genGood2(599, MAX);
		writeRand(1000, MAX);
		genGood(999, MAX, 328);
		genGood(999, MAX, 15);
		//30
		genGood(100000, 1000, 1);
		writeEq(100000, 1);
		genGood(100000, 100, 10234);
		genGood(99999, 566, 30293);
		genGood2(100000, 10000);
		
		genGood(50000, 4298, 3242);
		genGood(80000, 1500, 3);
		genGood(66666, 6666, 666);
		writeRand(56656, 2390);
		genGood2(56656, 2390);
		
		genGood2(87945, 234);
		genGood2(53453, 50);
		genGood2(98765, 1234);
		genGood(78901, 9876, 2345);
		genGood2(66395, 12000);
		
		genGood(100000, MAX, 100000);
		genGood(100000, MAX, 23948);
		genGood2(100000, MAX);
		writeRand(100000, MAX);
		writeEq(100000, MAX);
		
		//50
	}

}
