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

public class Gen {

	static int done = 0;

	static final Random rand = new Random(6856785);

	static final int maxN = 1000;
	static final int maxX = 10000;

	class Point {
		long x, y;

		public Point(long x, long y) {
			super();
			this.x = x;
			this.y = y;
		}
	}

	static ArrayList<Integer> data;

	static void print() throws IOException {
		done++;
		System.err.println(done);
		PrintWriter out = new PrintWriter(String.format("../tests/%02d", done));

		out.println(data.get(0) + " " + data.get(1) + " " + data.get(2) + " "
				+ data.get(3));
		out.println(data.size() - 4);
		for (int i = 4; i < data.size(); i++) {
			out.print(data.get(i));
			if (i != data.size() - 1)
				out.print(" ");
		}
		out.println();

		data.clear();

		out.close();
	}

	void genSample1() {
		data.add(0);
		data.add(0);
		data.add(6);
		data.add(0);
		data.add(5);
		data.add(5);

	}

	void addPoints(int[] len) {
		for (int i = 0; i < len.length; i++)
			data.add(len[i]);
	}

	void genTest1_NO() {
		data.add(123);
		data.add(456);
		data.add(321);
		data.add(345);
		int[] len = { 1000, 17 };
		randomShuffle(len);
		addPoints(len);
	}
	
	void genTest_21() {
		data.add(0);
		data.add(0);
		data.add(9);
		data.add(0);
		int[] len = { 3, 10, 3 };
		addPoints(len);
	}
	
	void genTest_22(int sumN) {
		int maxX2 = 100;
		int x = rand.nextInt(maxX2 * 2) - maxX2;
		int y = rand.nextInt(maxX2 * 2) - maxX2;
		data.add(x);
		data.add(y);
		int x2 = rand.nextInt(maxX2 * 2) - maxX2;
		int y2 = rand.nextInt(maxX2 * 2) - maxX2;
		data.add(x2);
		data.add(y2);
		int dx = x - x2;
		int dy = y - y2;
		double dist = Math.sqrt(dx * dx + dy * dy);
		int[] len = new int[sumN];
		for (int i = 0; i < sumN; i++)
			len[i] = 1;
			len[sumN / 2] = 1000;
		addPoints(len);
	}

	void genTest2_NO() {
		data.add(123);
		data.add(456);
		data.add(321);
		data.add(345);
		int[] len = new int[100];
		len[0] = 1000;
		for (int i = 1; i < 100; i++)
			len[i] = 1 + rand.nextInt(5);
		randomShuffle(len);
		addPoints(len);
	}

	void genTestType1(int sumN) {
		int maxX2 = 1000;
		int x = rand.nextInt(maxX2 * 2) - maxX2;
		int y = rand.nextInt(maxX2 * 2) - maxX2;
		data.add(x);
		data.add(y);
		int x2 = rand.nextInt(maxX2 * 2) - maxX2;
		int y2 = rand.nextInt(maxX2 * 2) - maxX2;
		data.add(x2);
		data.add(y2);
		int dx = x - x2;
		int dy = y - y2;
		double dist = Math.sqrt(dx * dx + dy * dy);
		int ll = 10 + (int) (5 * dist / sumN);
		int[] len = new int[sumN];
		for (int i = 0; i < sumN; i++)
			len[i] = 1 + rand.nextInt(ll);
		randomShuffle(len);
		addPoints(len);
	}

	void genTestType2(int sumN) {
		int x = rand.nextInt(maxX * 2) - maxX;
		int y = rand.nextInt(maxX * 2) - maxX;
		data.add(x);
		data.add(y);
		int x2 = rand.nextInt(maxX * 2) - maxX;
		int y2 = rand.nextInt(maxX * 2) - maxX;
		data.add(x2);
		data.add(y2);
		int[] len = new int[sumN];
		for (int i = 0; i < sumN; i++)
			len[i] = 5 + (rand.nextDouble() < 0.1 ? 1 : 0) * 1000;
		randomShuffle(len);
		addPoints(len);
	}

	void genTest2Segments() {
		int maxX2 = 300;
		int x = rand.nextInt(maxX2 * 2) - maxX2;
		int y = rand.nextInt(maxX2 * 2) - maxX2;
		data.add(x);
		data.add(y);
		int x2 = rand.nextInt(maxX2 * 2) - maxX2;
		int y2 = rand.nextInt(maxX2 * 2) - maxX2;
		data.add(x2);
		data.add(y2);
		int dx = x - x2;
		int dy = y - y2;
		int dist = (int) Math.sqrt(dx * dx + dy * dy);
		int l1 = dist / 2 + rand.nextInt(dist) + 1;
		int l2 = dist / 2 + rand.nextInt(dist) + 1;
		while (l1 + l2 < dist) {
			if (rand.nextBoolean())
				l1 += dist / 4;
			else
				l2 += dist / 4;
		}
		int[] len = { l1, l2 };
		randomShuffle(len);
		addPoints(len);
	}

	void genTestLessDist(int sumN) {
		int x = 123;
		int y = 123;
		data.add(x);
		data.add(y);
		int x2 = 123;
		int y2 = 1233 + rand.nextInt(maxX / 2);
		data.add(x2);
		data.add(y2);
		int dx = x - x2;
		int dy = y - y2;
		int dist = (int) Math.round(Math.sqrt(dx * dx + dy * dy));
		int[] len = new int[sumN];
		for (int i = 0; i < sumN; i++)
			len[i] = rand.nextInt(30) + 1;
		int s = 0;
		for (int i = 0; i < sumN; i++)
			s += len[i];
		int dd = 500;
		while (s != dist) {
			int it = 0;
			while (s - dd >= dist) {
				it++;
				if (it > 15)
					break;
				int id = rand.nextInt(sumN);
				if (len[id] <= dd) continue;
				len[id] -= dd;
				s -= dd;
			}
			it = 0;
			while (s + dd <= dist) {
				it++;
				if (it > 15)
					break;
				int id = rand.nextInt(sumN);
				if (len[id] + dd > 1000)
					continue;
				len[id] += dd;
				s += dd;
			}
			dd = Math.max(1, dd / 2);
		}
		randomShuffle(len);
		addPoints(len);
	}

	void randomShuffle(int[] data) {
		for (int i = 0; i < data.length; i++) {
			int ch = rand.nextInt(i + 1);
			int tmp = data[ch];
			data[ch] = data[i];
			data[i] = tmp;
			if (data[i] < 1)
				data[i] = 1;
			if (data[i] > 1000)
				data[i] = 1000;
		}
	}

	void genPreliminary() throws IOException {
		PrintWriter out = new PrintWriter(String.format("../preliminary/%02d",
				1));
		genSample1();
		out.println(data.get(0) + " " + data.get(1) + " " + data.get(2) + " "
				+ data.get(3));
		out.println(data.size() - 4);
		for (int i = 4; i < data.size(); i++) {
			out.print(data.get(i));
			if (i != data.size() - 1)
				out.print(" ");
		}

		data.clear();
		out.close();
	}

	public void run() throws IOException {
		data = new ArrayList<Integer>();

		new File("../preliminary").mkdir();
		new File("../tests").mkdir();

		genPreliminary();

		done = 0;

		genTest1_NO();
		print();

		genTest2_NO();
		print();


		for (int i = 0; i < 7; i++) {
			genTest2Segments();
			print();
		}
		
		for (int i = 0; i < 4; i++) {
			genTestLessDist(50 + rand.nextInt(maxN - 50));
			print();
		}
		
		for (int i = 0; i < 1; i++) {
			genTestType1(50 + rand.nextInt(maxN));
			print();
		}

		for (int i = 0; i < 1; i++) {
			genTestType2(50 + rand.nextInt(maxN));
			print();
		}

		for (int i = 0; i< 4; i++) {
			genTest_22(maxN);
			print();
		}
		
		genTest_21();
		print();
	}

	public static void main(String[] args) throws IOException {
		new Gen().run();
	}
}
