import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.File;
import java.util.Arrays;
import java.util.Random;

public class Tests {
    static int[] MAXN = {100, 5000, 100000};
    static int MAX = 1_000_000_000;
    int group;

    Random rnd = new Random(3289214075201L);

    String folder;

    PrintWriter desc;

    public static void main(String[] args) throws FileNotFoundException {
        new Tests().gen();
    }

    public int random(int l, int r) {
        if (r < l)
            return l;

        return l + rnd.nextInt(r - l + 1);
    }

    static int tests = 1;

    public void writeTest(int[] a, String description) {
        try {
            PrintWriter out = new PrintWriter(String.format(folder + "%02d", tests++));

            System.err.println("Writing test " + (tests - 1));

            desc.println(String.format(folder + "%02d", tests - 1) + "\t" + description + " n = " + a.length);

            out.println(a.length);

            for (int i = 0; i < a.length; i++) {
                out.print(a[i]);
                if (i < a.length - 1) {
                    out.print(" ");
                }
            }
            out.println();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void genRandom(int n) {
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = random(1, MAX);
        }

        writeTest(a, "Random test with");
    }


    public void genMax(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = MAX;
        }

        writeTest(a, "Maximal test with");
    }

    public void genProgression(int n) {
        int[] a = new int[n];
        int prev = 1;
        for (int i = 0; i < n; i++) {
            a[i] = random(prev, MAX);
        }

        writeTest(a, "Progression test with");
    }

    public void genRegression(int n) {
        int[] a = new int[n];
        int prev = MAX;
        for (int i = 0; i < n; i++) {
            a[i] = random(1, prev);
        }

        writeTest(a, "Regression test with");
    }

    public void genMaxFirstPosition(int n) {
        int[] a = new int[n];
        a[0] = random(1, MAX);
        for (int i = 0; i < n; i++) {
            a[i] = random(1, a[0]);
        }

        writeTest(a, "Max at first position test with");
    }

    public void genTwoMaxes(int n) {
        int[] a = new int[n];
        int maximal = random(2, MAX);
        for (int i = 0; i < n; i++) {
            a[i] = random(1, maximal - 1);
        }
        int x = random(0, n - 1);
        int y = random(0, n - 1);
        while (x == y) {
            y = random(0, n - 1);
        }
        //System.err.println(x + " " + y);
        a[x] = maximal;
        a[y] = maximal;

        writeTest(a, String.format("Test with maximals at %d and %d positions and", x, y));
    }

    public void genSmallRandom(int n) {
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = random(1, 10);
        }

        writeTest(a, "Random test with all numbers less than 11 and");
    }



    public void gen() {
        try{
            desc = new PrintWriter("../tests.desc");
        } catch (IOException e) {
//
        }

        tests = 1;
        folder = "../preliminary/";
        if (!new File(folder).exists())
            new File(folder).mkdir();
        writeTest(new int[]{1, 3, 4, 2, 5}, "Sample test");

        tests = 1;
        folder = "../tests/";
        if (!new File(folder).exists())
            new File(folder).mkdir();

        for (group = 0; group < MAXN.length; group++) {
            folder = String.format("../tests/subtask%d/", (group + 1));
            if (!new File(folder).exists())
                new File(folder).mkdir();

            int l = 1;
            if (group > 1) {
                l = MAXN[group - 1];
            }

            genRandom(random(l, MAXN[group]));
            genSmallRandom(random(l, MAXN[group]));
            genMaxFirstPosition(random(l, MAXN[group]));
            genProgression(random(l, MAXN[group]));
            genRegression(random(l, MAXN[group]));
            genTwoMaxes(random(l, MAXN[group]));

            genRandom(MAXN[group]);
            //genSmallRandom(MAXN[group]);
            //genMaxFirstPosition(MAXN[group]);
            genProgression(MAXN[group]);
            //genRegression(MAXN[group]);
            genTwoMaxes(MAXN[group]);
            genMax(MAXN[group]);


        }

        desc.close();
    }
}
