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

public class generate {
    Random random;

    void doTest(String id, int[][] widths) throws FileNotFoundException  {
        PrintWriter writer = new PrintWriter(new FileOutputStream(id));
        writer.println(widths.length);
        for (int[] line : widths) {
            writer.print(line.length);
            for (int cellWidth : line)
                writer.print(" " + cellWidth);
            writer.println();
        }
        writer.close();
    }

    void doGrid(String id, int lines, int cells, int cellWidth) throws FileNotFoundException {
        int[] cellWidths = new int[cells];
        Arrays.fill(cellWidths, cellWidth);
        doGrid(id, lines, cellWidths);
    }

    void doGrid(String id, int lines, int[] cellWidths) throws FileNotFoundException {
        int[][] widths = new int[lines][];
        for (int i = 0; i < lines; ++i) {
            widths[i] = cellWidths.clone();
        }
        doTest(id, widths);
    }

    void doRandomGrid(String id, int lines, int cells, int minWidth, int maxWidth) throws FileNotFoundException {
        int[] cellWidths = new int[cells];
        for (int i = 0; i < cells; ++i)
            cellWidths[i] = random.nextInt(maxWidth - minWidth + 1) + minWidth;
        doGrid(id, lines, cellWidths);
    }

    void doRandom(String id, int lines, int minCells, int maxCells, int minWidth, int maxWidth) throws FileNotFoundException {
        int[][] widths = new int[lines][];
        for (int i = 0; i < lines; ++i) {
            widths[i] = new int[random.nextInt(maxCells - minCells + 1) + minCells];

            for (int j = 0; j < widths[i].length; ++j)
                widths[i][j] = random.nextInt(maxWidth - minWidth + 1) + minWidth;
        }
        doTest(id, widths);
    }

    void doManyPluses(String id, int lines, int cells) throws FileNotFoundException {
        int[][] widths = new int[lines][];
        int cur = random.nextInt(2);
        for (int i = 0; i < lines; ++i) {
            widths[i] = new int[cells];
            int k = 0;
            if (cur == 0)
                widths[i][k++] = 2;
            for (int j = 0; j < cells - 1; ++j)
                widths[i][k++] = 1;
            if (cur > 0)
                widths[i][k++] = 2;
            cur = 1 - cur;
        }
        doTest(id, widths);
    }

    generate() {
        random = new Random(594010111);
    }

    public static void main(String[] args) throws FileNotFoundException {
        generate item = new generate();

        item.doGrid("02", 1, 1, 1);
        item.doGrid("03", 1, 2, 1);
        item.doGrid("04", 2, 1, 1);
        item.doGrid("05", 2, 2, 1);
        item.doGrid("06", 1, 1, 20);
        item.doGrid("07", 1, 10, 20);
        item.doGrid("08", 100, 1, 20);
        item.doRandomGrid("09", 5, 5, 1, 20);
        item.doRandomGrid("10", 2, 10, 19, 20);
        item.doRandomGrid("11", 100, 4, 3, 5);
        item.doRandomGrid("12", 99, 9, 1, 20);
        item.doRandomGrid("13", 98, 10, 10, 20);
        item.doRandom("14", 3, 2, 4, 1, 3);
        item.doRandom("15", 3, 8, 10, 1, 20);
        item.doRandom("16", 8, 3, 4, 10, 20);
        item.doRandom("17", 5, 1, 10, 1, 20);
        item.doRandom("18", 10, 5, 10, 1, 2);
        item.doRandom("19", 100, 1, 10, 1, 20);
        item.doRandom("20", 99, 1, 10, 1, 20);
        item.doRandom("21", 97, 10, 10, 1, 2);
        item.doRandom("22", 95, 1, 10, 19, 20);
        item.doRandom("23", 99, 9, 10, 19, 20);
        item.doRandom("24", 100, 10, 10, 3, 5);
        item.doRandom("25", 100, 1, 10, 1, 1);
        item.doRandom("26", 99, 1, 10, 20, 20);
        item.doRandom("27", 30, 1, 10, 1, 20);
        item.doRandom("28", 40, 1, 10, 1, 20);
        item.doRandom("29", 50, 1, 10, 1, 20);
        item.doRandom("30", 60, 1, 10, 1, 20);
        item.doRandom("31", 70, 1, 10, 1, 20);
        item.doRandom("32", 80, 1, 10, 1, 20);
        item.doRandom("33", 1, 10, 10, 1, 20);
        item.doRandom("34", 2, 10, 10, 1, 20);
        item.doRandom("35", 3, 1, 10, 1, 20);
        item.doRandom("36", 4, 1, 10, 1, 20);
        item.doRandom("37", 5, 1, 10, 1, 20);
        item.doRandom("38", 6, 1, 10, 1, 20);
        item.doManyPluses("39", 2, 2);
        item.doManyPluses("40", 2, 10);
        item.doManyPluses("41", 10, 2);
        item.doManyPluses("42", 99, 10);
    }

}
