package tests;
//by Sergey Melnikov

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;

public class TestGen extends Thread {
	class Test {
		int[] a, b;

		public Test(int[] c) {
			a = new int[3];
			b = new int[3];
			for (int i = 0; i < a.length; i++) {
				a[i] = c[i];
			}
			for (int i = 0; i < b.length; i++) {
				b[i] = c[3 + i];
			}
		}

	}

	private int testCount = 0;

	private void write(Test t) {
		try {
			++testCount;
			String filename = testCount / 10 + "" + testCount % 10;
			PrintWriter out = new PrintWriter(filename);
			System.err.println(testCount);
			out.println(t.a[0] + " " + t.a[1] + " " + t.a[2]);
			out.println(t.b[0] + " " + t.b[1] + " " + t.b[2]);
			out.flush();
			out.close();
		} catch (IOException ex) {
			throw new RuntimeException(ex);
		}
	}

	void myAssert(boolean b) {
		if (!b)
			throw new AssertionError();
	}

	static Random rand = new Random(1);
	final int MAXN = 100;
	final int[][] example = { { 3, 4, 6, 2, 3, 8 }, { 3, 4, 6, 2, 11, 0 } };

	public void run() {
		for (int i = 0; i < example.length; i++) {
			write(new Test(example[i]));
		}
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				write(genO(i, j, MAXN));
			}
		}
		for (int i = 0; i < 6; i++) {
			write(genZ(i, 5));
			write(genZ(i, 10));
			write(genZ(i, MAXN));
		}
		write(new Test(new int[] { MAXN, MAXN, MAXN, MAXN, MAXN, MAXN }));
		write(new Test(new int[] { 1, 1, 1, 1, 1, 1 }));
		write(new Test(new int[] { 0, 0, 0, 0, 0, 0 }));
		write(genZ(-1, 5));
		write(genZ(-1, 10));
		write(genZ(-1, MAXN));
		for (int i = 0; i < 3; i++) {
			write(genA(2));
			write(genA(5));
		}
		for (int i = 0; i < 4; i++) {
			write(genA(MAXN));
		}
	}

	private Test genO(int i, int j, int T) {
		int[] a = new int[6];
		a[i] = a[3 + j] = T;
		return new Test(a);
	}

	int[] getIntWithSum(int T, int sum) {
		int[] a = new int[3];
		while (true) {
			int s = 0;
			for (int i = 0; i < a.length; i++) {
				a[i] = rand.nextInt(T + 1);
				s += a[i];
			}
			if (s == sum) {
				return a;
			}
		}
	}

	private Test genZ(int i, int T) {
		int[] a = new int[6];
		for (int j = 0; j < a.length; j++) {
			if (i == j) {
				continue;
			}
			a[j] = rand.nextInt(T) + 1;
		}
		int s1 = a[0] + a[1] + a[2];
		int s2 = a[3] + a[4] + a[5];
		if (i < 3) {
			int[] b = getIntWithSum(T, s1);
			for (int j = 0; j < b.length; j++) {
				a[j + 3] = b[j];
			}
		} else {
			int[] b = getIntWithSum(T, s2);
			for (int j = 0; j < b.length; j++) {
				a[j] = b[j];
			}
		}
		return new Test(a);
	}

	private Test genA(int T) {
		int[] a = new int[6];
		int sum = 0;
		for (int j = 0; j < 3; j++) {
			a[j] = rand.nextInt(T + 1);
			sum += a[j];
		}
		int[] b = getIntWithSum(T, sum);
		for (int i = 0; i < b.length; i++) {
			a[i + 3] = b[i];
		}
		return new Test(a);
	}

	public static void main(String[] args) {
		new TestGen().start();
	}
}
