import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class TestsGen implements Runnable {
	public static void main(String[] args) {
		if (args.length < 1) {
			for (I = 1; (new File(getName(I) + ".t")).exists(); I++)
				;
		} else {
			I = Integer.parseInt(args[0]);
		}
		new Thread(new TestsGen()).start();
	}

	PrintWriter out;

	Random rand = new Random(6439586L);

	static int I;

	static String getName(int i) {
		return ((i < 10) ? "0" : "") + i;
	}

	void open() {
		try {
			System.out.println("Generating test " + I);
			out = new PrintWriter(getName(I));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	void close() {
		out.close();
		I++;
	}

	String randString(int len, String alpha) {
		StringBuilder ans = new StringBuilder();
		int k = alpha.length();
		for (int i = 0; i < len; i++) {
			ans.append(alpha.charAt(rand.nextInt(k)));
		}
		return ans.toString();
	}

	final String ALPHA = "abcdefghijklmnopqrstuvwxyz";

	long rand(long l, long r) {
		return l + (rand.nextLong() >>> 1) % (r - l + 1);
	}

	int rand(int l, int r) {
		return l + rand.nextInt(r - l + 1);
	}

	
	final int MAX_N = 20000;
	final int MAX_SUM = (int)1e9;
	
	void genRand(int n, int MAX_SUM) {
		open();
		out.println(n);
		for (int i = 0; i < n; ++i) {
			out.print(rand(1, MAX_SUM));
			if (i < n - 1) {
				out.print(" ");
			} else {
				out.println();
			}
		}
		close();
	}
	
	void genSpecSum_f(int[] a, int f, int n, int sum) {
		if (n == 1) {
			a[f] = sum + 1;
		} else {
			int ts = rand(0, sum);
			genSpecSum_f(a, f, n / 2, ts);
			genSpecSum_f(a, f + n / 2, n - n / 2, sum - ts);
		}
		
	}
	
	void genSpecSum(int n, int sum, int heaps) {
//		System.err.println(n + " " + sum + " " + heaps);
		open();
		out.println(n);
		int[] a = new int[heaps];
		genSpecSum_f(a, 0, heaps, n - heaps);
//		System.err.println(Arrays.toString(a));
		int[] ans = new int[n];
		int sz = 0;
		for (int i = 0; i < heaps; ++i) {
			genSpecSum_f(ans, sz, a[i], sum - a[i]);
			sz += a[i];
		}
		int s = rand(0, n - 1);
		for (int j = 0; j < ans.length; ++j) {
			out.print(ans[(j + s) % n]);
			if (j != ans.length - 1) {
				out.print(" ");
			}
		}

		out.println();
		close();
	}
	
	
	void genBigDiv(int n) {
		long sum = 1;
		while (true) {
			int k = rand(2, 30);
			if (sum * k > MAX_SUM) break;
			sum = sum * k;
		}
		int heaps = rand(1, n);
		for (int i = 0; i < 100; ++i) {
			if (sum % heaps != 0) heaps = rand(1, n);
		}
//		System.err.println(heaps);
		genSpecSum(n, (int)sum / heaps, heaps);
	}
	
	
	public void solve() throws IOException {
//		genBigDiv(10);
		for (int i = 0; i < 5; ++i) {
			genRand(rand(3, 7), 3);
		}
		for (int i = 0; i < 5; ++i) {
			genBigDiv(rand(3, 10));
		}
		for (int i = 0; i < 5; ++i) {
			genRand(rand(10, 60), rand(1, 10));
			genBigDiv(rand(10, 60));
		}
		for (int i = 0; i < 3; ++i) {
			genRand(rand(80, 100), rand(1000, MAX_SUM / 100));
		}
		for (int i = 0; i < 5; ++i) {
			genBigDiv(rand(80, 100));
		}
		genSpecSum(100, 8923714, 100);
		genSpecSum(100, 89237148, 10);
		
		for (int i = 0; i < 3; ++i) {
			genRand(1000 / 3 * (1 + i), rand(1000, MAX_SUM / 1000));
		}
		for (int i = 0; i < 6; ++i) {
			genBigDiv(1000 / 6 * (1 + i));
		}
		genSpecSum(1000, 892371480 / 40, 40);
		
		for (int i = 0; i < 3; ++i) {
			genRand(20000 / 3 * (1 + i), rand(1000, MAX_SUM / 20000));
		}
		for (int i = 0; i < 6; ++i) {
			genBigDiv(20000 / 6 * (1 + i));
		}
		genSpecSum(20000, 892371480 / 2, 2);    
	}

	public void run() {
		try {
			solve();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}
}
