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

public class Gen {

	static int done = 0;
	static ArrayList<String> data = new ArrayList<String>();

	static final Random rand = new Random(556668949239L);
	static final int MAX_COUNT = (int) 1e4;
	static final int MAX_LENGHT = 20;
	static final int MAX_ALPHA = 26;

	static void print() throws IOException {
		done++;
		System.err.println(done);
		PrintWriter out;
		if (done < 10)
			out = new PrintWriter("../tests/0" + String.valueOf(done));
		else
			out = new PrintWriter("../tests/" + String.valueOf(done));

		out.println(data.size());
		for (int i = 0; i < data.size(); i++) {
			out.println(data.get(i));
		}
		data.clear();
		out.close();
	}

	static void genSimple() throws IOException {
		data.add("dinamom");
		data.add("amkar");
		data.add("dinamok");
		print();
	}

    static void genAnti() throws IOException {
        data.add("baaa");
        data.add("aabbb");
        data.add("aaab");
        data.add("aa");
        data.add("aba");
        data.add("ab");
        print();
    }

	static void genWord(int len, int alpha) throws IOException {
		String s = "";
		for (int j = 0; j < len; j++)
			s += (char) (rand.nextInt(alpha) + 'a');
		data.add(s);
	}

	static void genRandWords(int cnt, int len, int alpha) throws IOException {
		int n = rand.nextInt(cnt) + 1;
		for (int i = 0; i < n; i++) {
			String s = "";
			int t = rand.nextInt(len) + 1;
			for (int j = 0; j < t; j++)
				s += (char) (rand.nextInt(alpha) + 'a');
			data.add(s);
		}
	}

	static void genMaxTest(int cnt, int len, int alpha) throws IOException {
		for (int i = 0; i < cnt; i++)
			genWord(len, alpha);
		print();
	}

	static void genMaxTest2(int cnt, int len, int alpha) throws IOException {
		genRandWords(cnt, len, alpha);
		print();
	}

	static void genRand(int cnt, int len, int alpha) throws IOException {
		int cur = 0;
		while (cur < cnt) {
			int t = rand.nextInt(cnt / 10) + 1;
			if (cur + t > cnt)
				continue;
			genRandWords(t, len, rand.nextInt(alpha - 1) + 2);
			cur += t;
		}
		print();
	}

	static void genPref(int cnt, int cnt2, int len, int alpha)
			throws IOException {
		for (int i = 0; i < cnt2; i++)
			genWord(len / 2, alpha);
		for (int i = cnt2; i < cnt; i++) {
			int t = rand.nextInt(cnt2);
			String s = data.get(t);
			t = rand.nextInt(len / 2);
			for (int j = 0; j < t; j++)
				s += (char) (rand.nextInt(alpha) + 'a');
			data.add(s);
		}
		print();
	}

	public static void main(String[] args) throws IOException {
		File dir = new File("../tests");
		if (!dir.exists())
			dir.mkdir();
		done = 0;
		genSimple();
        genAnti();
        genPref(5, 1, MAX_LENGHT, 2);
		genPref(5, 2, MAX_LENGHT, 2);
		genPref(5, 2, MAX_LENGHT, 10);
		genPref(5, 2, MAX_LENGHT, MAX_ALPHA);
		genRand(10, MAX_LENGHT, MAX_ALPHA);
		genMaxTest(5, MAX_LENGHT, 2);
		genMaxTest2(5, MAX_LENGHT, MAX_ALPHA);
		for (int i = 1; i < 11; i += 3) {
			genPref(100 * i, i * 2, MAX_LENGHT, 2);
			genPref(100 * i, i * 3, MAX_LENGHT, 10);
			genPref(100 * i, i * 2, MAX_LENGHT, MAX_ALPHA);
			genRand(100 * i, MAX_LENGHT, MAX_ALPHA);
			genMaxTest(100 * i, MAX_LENGHT, 2);
			genMaxTest2(100 * i, MAX_LENGHT, MAX_ALPHA);
		}

		for (int i = 5; i <= 10; i++) {
			genPref(MAX_COUNT / 10 * i, i * 10, MAX_LENGHT, MAX_ALPHA);
			genPref(MAX_COUNT / 10 * i, i * 10, MAX_LENGHT, 2);
			genRand(MAX_COUNT / 10 * i, MAX_LENGHT, MAX_ALPHA);
			genRand(MAX_COUNT / 10 * i, MAX_LENGHT, 5);
		}
		genMaxTest(MAX_COUNT, MAX_LENGHT, MAX_ALPHA);
		genMaxTest(MAX_COUNT, MAX_LENGHT, 2);
		genMaxTest2(MAX_COUNT, MAX_LENGHT, MAX_ALPHA);
		genMaxTest2(MAX_COUNT, MAX_LENGHT, 2);
        return;
	}
}
