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

public class Gen {

    static int done = 0;

    static final Random rand = new Random(556668949239L);

    static final int MAX_LENGTH = 100;
    static final int MAX_COUNT = 1000;

    final static String ALPHA = "abcdefghijklmnopqrstuvwxyz";
    final static String DIGIT = "0123456789";
    final static String ALL = ALPHA + ALPHA.toUpperCase() + "        ";
    final static int LEN = ALL.length();

    static ArrayList<String> data = new ArrayList<>();

    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());
	Collections.shuffle(data, rand);
	for (int i = 0; i < data.size(); i++)
	    out.println(data.get(i));
	data.clear();
	out.close();
    }

    static void genSimple() throws IOException {
	PrintWriter out;
	out = new PrintWriter("../preliminary/01");
	out.println(9);
	out.println("Physics and Mathematics School 18");
	out.println("9ya shkola imeni Pushkina");
	out.println("Lyceum 9");
	out.println("PaMS 18");
	out.println("Gymnasium 42");
	out.println("School 9");
	out.println("Shkola nomer 9");
	out.println("High school 9");
	out.println("School N 9");
	out.close();
    }

    static String genNumber(int maxValue) {
	return Integer.toString(rand.nextInt(maxValue - 1) + 1);
    }

    static String genNumber(int minValue, int maxValue) {
	return Integer.toString(rand.nextInt(maxValue - minValue)
		+ minValue);
    }

    static String genBigNumber(int len) {
	StringBuilder s = new StringBuilder();
	s.append(DIGIT.charAt(rand.nextInt(9) + 1));
	for (int i = 1; i < len; i++)
	    s.append(DIGIT.charAt(rand.nextInt(10)));
	return s.toString();
    }

    static String obfuscation(String number, int len) {
	StringBuilder ans = new StringBuilder();
	int n = len - number.length();
	int pos = rand.nextInt(n + 1);

	for (int i = 0; i < len - number.length(); i++) {
	    if (pos == i)
		ans.append(number);
	    ans.append(ALL.charAt(rand.nextInt(LEN)));
	}
	if (pos == n)
	    ans.append(number);

	return ans.toString();
    }

    public static void main(String[] args) throws IOException {
	boolean f = (new File("../preliminary")).mkdir();
	f = new File("../tests").mkdir();

	genSimple();

	done = 0;
	// Small test 1-6
	// 1
	data.add(obfuscation("1", 5));
	print();

	// 2
	for (int i = 1; i < 10; i++) {
	    int t = rand.nextInt(7) + 2;
	    for (int j = 0; j < t; j++)
		data.add(obfuscation(Integer.toString(i), rand.nextInt(20) + 5));
	}
	print();

	// 3
	for (int i = 0; i < MAX_COUNT; i++)
	    data.add(obfuscation(genNumber(9), MAX_LENGTH));
	print();

	// 4
	{
	    int t = 3;
	    for (int i = 1; i < 10; i++) {
		if (i == t) {
		    for (int j = 0; j < MAX_COUNT - 100; j++)
			data.add(obfuscation(Integer.toString(t),
				rand.nextInt(MAX_LENGTH) + 1));
		}
		int k = rand.nextInt(7) + 2;
		for (int j = 0; j < k; j++)
		    data.add(obfuscation(Integer.toString(i),
			    rand.nextInt(MAX_LENGTH) + 1));
	    }
	    print();
	}

	// 5
	{
	    String num = genNumber(9);
	    for (int i = 0; i < MAX_COUNT; i++)
		data.add(obfuscation(num,
			MAX_LENGTH / 2 + rand.nextInt(MAX_LENGTH / 2)));
	    print();
	}

	// 6
	for (int i = 0; i < 6; i++) {
	    String num = genNumber(9);
	    int t = rand.nextInt(5) + 1;
	    for (int j = 0; j < t; j++)
		data.add(obfuscation(num,
			MAX_LENGTH / 3 + rand.nextInt(MAX_LENGTH / 2)));
	}
	for (int i = 0; i < 3; i++) {
	    String num = genNumber(9);
	    int t = rand.nextInt(230) + 100;
	    for (int j = 0; j < t; j++)
		data.add(obfuscation(num,
			MAX_LENGTH / 3 + rand.nextInt(MAX_LENGTH / 2)));
	}
	print();

	// Middle test
	// 7
	for (int i = 1; i < 1000; i++)
	    data.add(obfuscation(Integer.toString(i), MAX_LENGTH));
	print();

	// 8
	for (int i = 1; i < MAX_COUNT / 4; i++)
	    data.add(obfuscation(genNumber(10, 1000),
		    MAX_LENGTH / 2 + rand.nextInt(MAX_LENGTH / 2)));
	print();

	// 9
	for (int i = 1; i < MAX_COUNT / 10; i++) {
	    String num = genNumber(500, 1000);
	    int t = rand.nextInt(8) + 3;
	    for (int j = 0; j < t; j++)
		data.add(obfuscation(num,
			MAX_LENGTH / 3 + rand.nextInt(MAX_LENGTH / 2)));
	}
	print();

	// 10
	for (int i = 0; i < 239; i++)
	    data.add(obfuscation("999", MAX_LENGTH));
	print();

	// Big test
	// 11
	for (int i = 0; i < 10; i++)
	    data.add(obfuscation(genNumber((int) 1e8, (int) 1e9),
		    rand.nextInt(MAX_LENGTH / 2) + MAX_LENGTH / 2));
	print();

	// 12
	for (int i = 0; i < MAX_COUNT; i++)
	    data.add(obfuscation(genNumber((int) 1e8, (int) 1e9),
		    rand.nextInt(MAX_LENGTH / 2) + MAX_LENGTH / 2));
	print();

	// 13
	for (int i = 0; i < MAX_COUNT; i++)
	    data.add(obfuscation(genNumber((int) 1e9 - 100, (int) 1e9),
		    rand.nextInt(MAX_LENGTH / 2) + MAX_LENGTH / 2));
	print();
	// 14
	for (int i = 0; i < MAX_COUNT; i++)
	    data.add(obfuscation(genNumber((int) 1e9 - 10, (int) 1e9),
		    rand.nextInt(MAX_LENGTH / 2) + MAX_LENGTH / 2));
	print();

	// 15
	for (int i = 0; i < MAX_COUNT / 4; i++)
	    data.add(obfuscation(genNumber((int) 10000, (int) 1e9), MAX_LENGTH));
	print();

	// 16
	for (int i = 0; i < 5; i++)
	    data.add(obfuscation("666666", MAX_LENGTH));
	for (int i = 0; i < 5; i++)
	    data.add(obfuscation("777777", MAX_LENGTH));
	for (int i = 0; i < 5; i++)
	    data.add(obfuscation("999999", MAX_LENGTH));
	for (int i = 0; i < 300; i++)
	    data.add(obfuscation(genNumber((int) 1e9), 23));
	print();

	// Biggest test
	// 17
	for (int i = 0; i < MAX_COUNT; i++)
	    data.add(obfuscation(genBigNumber(rand.nextInt(MAX_LENGTH / 3 * 2)
		    + MAX_LENGTH / 3), MAX_LENGTH));
	print();
	
	// 18
	{
	    ArrayList<String> num = new ArrayList<>();
	    for (int i = 0; i < 100; i++)
		num.add(genBigNumber(MAX_LENGTH));
	    for (int i = 0; i < MAX_COUNT; i++)
		data.add(num.get(rand.nextInt(100)));
	    print();
	}

	// 19
	{
	    ArrayList<String> num = new ArrayList<>();
	    for (int i = 0; i < 200; i++)
		num.add(genBigNumber(MAX_LENGTH));
	    for (int i = 0; i < MAX_COUNT; i++)
		data.add(num.get(rand.nextInt(200)));
	    print();
	}

	// 20
	{
	    ArrayList<String> num = new ArrayList<>();
	    for (int i = 0; i < 30; i++)
		num.add(genBigNumber(MAX_LENGTH / 2));
	    for (int i = 0; i < MAX_COUNT / 3; i++)
		data.add(obfuscation(num.get(rand.nextInt(30)), MAX_LENGTH));
	    print();
	}

	return;
    }
}

