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

/**
 * Created with IntelliJ IDEA.
 * User: niyaz
 * Date: 11/16/13
 * Time: 12:07 AM
 * To change this template use File | Settings | File Templates.
 */
public class TestsGen {
    static class Test {
        int[] a;
        Query[] q;

        Test(int[] a, Query[] q) {
            this.a = a;
            this.q = q;
        }
    }

    static interface Query {
        String makeString();
    }

    static class AssignQuery implements Query {
        int index;
        int val;

        AssignQuery(int index, int val) {
            this.index = index;
            this.val = val;
        }

        @Override
        public String makeString() {
            return "assign " + (index + 1) + " " + val;
        }
    }

    static class TortureQuery implements Query {
        int left;
        int right;
        int val;

        TortureQuery(int left, int right, int val) {
            this.left = left;
            this.right = right;
            this.val = val;
        }

        @Override
        public String makeString() {
            return "torture " + (left + 1) + " " + (right + 1) + " " + val;
        }
    }

    static final Random RNG = new Random(1029384756);

    static int printedTests;

    static void printTest(Test test) {
        System.err.println("[" + ++printedTests + "]");
        try {
            PrintWriter out = new PrintWriter("../tests/" + String.format("%02d", printedTests));
            int n = test.a.length;
            out.println(n);
            for (int i = 0; i < n; i++) {
                if (i > 0) out.print(' ');
                out.print(test.a[i]);
            }
            out.println();
            out.println(test.q.length);
            for (Query e : test.q) {
                out.println(e.makeString());
            }
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    static int random(int n) {
        return RNG.nextInt(n);
    }

    static int random(int l, int r) {
        return random(r - l + 1) + l;
    }

    static Query[] genRandomQueries(int n, int m, int maxx) {
        Query[] ret = new Query[m];
        for (int i = 0; i < m; i++) {
            if (RNG.nextBoolean()) {
                ret[i] = new AssignQuery(random(n), random(-maxx, maxx));
            } else {
                int l = random(n);
                int r = random(l, n - 1);
                ret[i] = new TortureQuery(l, r, random(-maxx, maxx));
            }
        }
        return ret;
    }

    static Query[] genManyAssignmentsQueries(int n, int m, int maxx) {
        Query[] ret = new Query[m];
        for (int i = 0; i < m; i++) {
            if (random(100) == 0) {
                int l = random(n);
                int r = random(l, n - 1);
                ret[i] = new TortureQuery(l, r, random(-maxx, maxx));
            } else {
                ret[i] = new AssignQuery(random(n), random(-maxx, maxx));
            }
        }
        return ret;
    }

    static Query[] genManyQueryQueries(int n, int m, int maxx) {
        Query[] ret = new Query[m];
        for (int i = 0; i < m; i++) {
            if (random(100) == 0) {
                ret[i] = new AssignQuery(random(n), random(-maxx, maxx));
            } else {
                int l = random(n);
                int r = random(l, n - 1);
                ret[i] = new TortureQuery(l, r, random(-maxx, maxx));
            }
        }
        return ret;
    }

    static int[] genRandomArray(int n, int maxx) {
        int[] ret = new int[n];
        for (int i = 0; i < n; i++) {
            ret[i] = random(-maxx, maxx);
        }
        return ret;
    }

    static final int MAXN = 300000;
    static final int MAXM = 300000;
    static final int MAXX = 100000000;

    public static void main(String[] args) {
        printTest(new Test(new int[]{1, 2, 3}, new Query[]{new AssignQuery(1, 4), new TortureQuery(1, 2, 3)}));
        printTest(new Test(genRandomArray(6, 7), genRandomQueries(6, 9, 9)));
        printTest(new Test(genRandomArray(30, 40), genRandomQueries(30, MAXM / 10, 40)));
        printTest(new Test(genRandomArray(30, 140), genRandomQueries(30, MAXM / 10, 240)));
        printTest(new Test(genRandomArray(10, 140), genRandomQueries(10, MAXM / 10, 240)));

        printTest(new Test(genRandomArray(MAXN, MAXX), genManyQueryQueries(MAXN, MAXM, MAXX)));
        printTest(new Test(genRandomArray(MAXN, MAXX), genManyAssignmentsQueries(MAXN, MAXM, MAXX)));
        printTest(new Test(genRandomArray(MAXN, MAXX), genRandomQueries(MAXN, MAXM, MAXX)));

        printTest(new Test(genRandomArray(100, MAXX), genRandomQueries(100, MAXM / 7, MAXX)));
        printTest(new Test(genRandomArray(MAXN / 4, 100), genRandomQueries(MAXN / 4, MAXM / 2, 100)));

        printTest(new Test(genRandomArray(100, MAXX), genManyAssignmentsQueries(100, MAXM / 7, MAXX)));
        printTest(new Test(genRandomArray(MAXN / 4, 100), genManyAssignmentsQueries(MAXN / 4, MAXM / 2, 100)));

        printTest(new Test(genRandomArray(100, MAXX), genManyQueryQueries(100, MAXM / 7, MAXX)));
        printTest(new Test(genRandomArray(MAXN / 4, 100), genManyQueryQueries(MAXN / 4, MAXM / 2, 100)));


        printTest(new Test(genRandomArray(MAXN / 3, 10000), genRandomQueries(MAXN / 3, MAXM / 3, 10000)));
        printTest(new Test(genRandomArray(MAXN / 3, 10000), genManyAssignmentsQueries(MAXN / 3, MAXM / 3, 10000)));
        printTest(new Test(genRandomArray(MAXN / 3, 10000), genManyQueryQueries(MAXN / 3, MAXM / 3, 10000)));
    }
}
