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

public class TestGen {

    static int done = 0;

    static final Random rnd = new Random(556668949238L);

    static int rand(int n) {
        if (n < 1)
            return 0;
        return rnd.nextInt(n);
    }

    static int sand(int n) {
        return rand(2 * n) - n;
    }

    static final int MAX1 = 1_000;
    static final int MAX2 = 1_000_000_000;

    static int xa, xb, ya, yb, a, b;

    static PrintWriter desc;

    static void print() throws IOException {
        done++;
        System.err.println("Generation test #" + done);
        PrintWriter out;
        if (done < 10)
            out = new PrintWriter("../tests/0" + String.valueOf(done));
        else
            out = new PrintWriter("../tests/" + String.valueOf(done));
        out.println(xa + " " + ya);
        out.println(xb + " " + yb);
        if (a > b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        out.println(a + " " + b);
        out.close();
    }

    static String getPath() {
        if (done < 10)
            return "../tests/0" + String.valueOf(done);
        return "../tests/" + String.valueOf(done);
    }


    static void gen_sample() throws IOException {
        PrintWriter out;
        String path = "../preliminary/01";
        out = new PrintWriter(path);
        out.println("-4 -3");
        out.println("8 3");
        out.println("2 2");
        out.close();
        print_desc(path, "preliminary", "subtask0", 0, "sample 1");
        path = "../preliminary/02";
        out = new PrintWriter(path);
        out.println("3 3");
        out.println("1 1");
        out.println("3 3");
        out.close();
        print_desc(path, "preliminary", "subtask0", 0, "sample 2");
    }

    static void print_desc(String path, String folder, String subtask, int points, String comment) throws IOException {
        desc.println(String.format("%s, folder=%s, subtask=%s, points=%d, comment=\"%s\"", path, folder, subtask, points, comment));
    }

    static String subtask;

    static void print_desc_t(String comment) throws IOException {
        print_desc(getPath(), "tests", subtask, 0, comment);
    }

    //begin gens

    static void genRand(int maxx) throws IOException {
        xa = sand(maxx);
        ya = sand(maxx);
        xb = sand(maxx);
        yb = sand(maxx);
        while (xa == xb)
            xb = sand(maxx);
        while (ya == yb)
            yb = sand(maxx);
        a = rand(maxx) + 1;
        b = rand(maxx) + 1;
        print();
        print_desc_t("Random test, |numbers| &lt;= " + maxx);
    }

    static int randSign() {
        if (rand(2) == 0)
            return 1;
        return -1;
    }

    static void genIncorrect(int maxx) throws IOException {
        int w, h;
        maxx = maxx / 2;
        a = rand(maxx) + 1;
        b = rand(maxx) + 1;
        w = rand(maxx) + 1;
        h = rand(maxx - w * b / a) + w * b / a;
        xa = sand(maxx);
        ya = sand(maxx);
        xb = xa + w * randSign();
        yb = ya + h * randSign();
        while(xb < -maxx || xb > maxx) {
            xa = sand(maxx);
            xb = xa + w * randSign();
        }
        while(yb < -maxx || yb > maxx) {
            ya = sand(maxx);
            yb = ya + h * randSign();
        }
        print();
        print_desc_t("answer = -1, |numbers| &lt;= " + maxx);
    }

    static void genCorrect(int maxx) throws IOException {
        int w, h;
        maxx = maxx / 2;
        a = rand(maxx) + 1;
        b = rand(maxx) + 1;
        w = rand(maxx) + 1;
        h = rand(w * b / a) + 1;
        xa = sand(maxx);
        ya = sand(maxx);
        xb = xa + w * randSign();
        yb = ya + h * randSign();
        while(xb < -maxx || xb > maxx) {
            xa = sand(maxx);
            xb = xa + w * randSign();
        }
        while(yb < -maxx || yb > maxx) {
            ya = sand(maxx);
            yb = ya + h * randSign();
        }
        print();
        print_desc_t("answer exists, |numbers| &lt;= " + maxx);
    }

    static void genSpecial1(int maxx) throws IOException {
        int w, h;
        maxx = maxx / 2;
        a = rand(maxx / 100) + 1;
        b = rand(maxx / 100) + 1;
        w = rand(maxx) + 1;
        h = rand(w * b / a) + 1;
        xa = sand(maxx);
        ya = sand(maxx);
        xb = xa + w * randSign();
        yb = ya + h * randSign();
        while(xb < -maxx || xb > maxx) {
            xa = sand(maxx);
            xb = xa + w * randSign();
        }
        while(yb < -maxx || yb > maxx) {
            ya = sand(maxx);
            yb = ya + h * randSign();
        }
        print();
        print_desc_t("answer exists, a and b are small, |numbers| &lt;= " + maxx);
    }                                                      

    static void genSpecial2(int maxx) throws IOException {
        int w, h;
        maxx = maxx / 2;
        a = rand(10) + 1;
        b = rand(10) + 1;
        w = rand(maxx) + 1;
        h = rand(w * b / a) + 1;
        xa = sand(maxx);
        ya = sand(maxx);
        xb = xa + w * randSign();
        yb = ya + h * randSign();
        while(xb < -maxx || xb > maxx) {
            xa = sand(maxx);
            xb = xa + w * randSign();
        }
        while(yb < -maxx || yb > maxx) {
            ya = sand(maxx);
            yb = ya + h * randSign();
        }
        print();
        print_desc_t("answer exists, a and b are very small, |numbers| &lt;= " + maxx);
    }


    static void genMAX1(int maxx) throws IOException {
        a = 1;
        b = 1;
        xa = maxx;
        ya = -maxx;
        xb = -maxx;
        yb = maxx;
        print();
        print_desc_t("max test 1, |numbers| &lt;= " + maxx);
    }

    static void genMAX2(int maxx) throws IOException {
        a = maxx;
        b = maxx;
        xa = -maxx;
        ya = maxx;
        xb = maxx;
        yb = -maxx;
        print();
        print_desc_t("max test 2, |numbers| &lt;= " + maxx);
    }

    //end gens

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

        done = 0;
        gen_sample();

        subtask = "subtask1";

        for (int i = 10; i <= 30; i += 10) {
            genRand(rand(i) + i / 2);
            genCorrect(rand(i) + i / 2);
            genIncorrect(rand(i) + i / 2);
        }

        genRand(rand(MAX1 / 2) + MAX1 / 2);
        genCorrect(rand(MAX1 / 2) + MAX1 / 2);
        genIncorrect(rand(MAX1 / 2) + MAX1 / 2);

        genSpecial2(rand(MAX1 / 2) + MAX1 / 2);
        genSpecial2(rand(MAX1 / 2) + MAX1 / 2);
        genSpecial2(rand(MAX1 / 2) + MAX1 / 2);


        genRand(MAX1);
        genIncorrect(MAX1);
        genCorrect(MAX1);

        genMAX1(MAX1);
        genMAX2(MAX1);

        desc.println(String.format("comment_subtask%d=\"n &lt;= %d\"", 1, MAX1));
        desc.println(String.format("bonus_subtask%d=%d", 1, 40));
//----------------------------------------------

        subtask = "subtask2";

        for (int i = 0; i < 5; i++) {
            genRand(rand(MAX2 / 2) + MAX2 / 2);
            genCorrect(rand(MAX2 / 2) + MAX2 / 2);
            genSpecial1(rand(MAX2 / 2) + MAX2 / 2);
            genSpecial2(rand(MAX2 / 2) + MAX2 / 2);
        }


        genSpecial1(MAX2);
        genSpecial2(MAX2);
        genRand(MAX2);
        genIncorrect(MAX2);
        genCorrect(MAX2);
        genSpecial1(MAX2);
        genSpecial2(MAX2);
        genCorrect(MAX2);
        genMAX1(MAX2);
        genMAX2(MAX2);

        desc.println(String.format("comment_subtask%d=\"n &lt;= %d\"", 2, MAX2));
        desc.println(String.format("bonus_subtask%d=%d", 2, 60));

        desc.close();
    }
}
