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

public class TestGen {

    static PrintWriter out;
    static Random rnd = new Random(0);
    static int tNumber = 1;
    static PrintWriter testDescr;
    static int sb = 0;


    static void printTest(int n, int k, int[] arr, String comment) throws IOException {
        System.out.println(String.format("Generating test %d", tNumber));
        if (tNumber < 10)
            out = new PrintWriter("../tests/0" + tNumber);
        else
            out = new PrintWriter("../tests/" + tNumber);
        out.println(n + " " + k);
        for (int i = 0; i < n; ++i)
            out.print(arr[i] + (i != n - 1 ? " " : ""));
        out.println();                
        out.close();
        testDescr.println("../tests/" + ((tNumber > 9) ? tNumber : ("0" + tNumber)) + ", folder=tests, subtask=subtask" + sb + ", points=0, comment=\"" + comment + "\"");
        tNumber++;        
    }
    
    static void genSample() throws FileNotFoundException {
        out = new PrintWriter("../preliminary/01");
        
        out.println("6 5\r\n1 5 3 2 1 4");
            
        out.close();                
        testDescr.println("../preliminary/01, folder=preliminary, subtask=subtask0, points=0, comment=\"sample 1\"");
    }
    
    static int randFromTo(int l, int r) {
        return rnd.nextInt(r - l + 1) + l;      
    }
    
    static int[] genArray(int n, int mx) {
        int[] ans = new int[n];
        for (int i = 0; i < n; ++i)
            ans[i] = randFromTo(1, mx);
        return ans;
    }
        
    public static void main(String[] args) throws IOException {
        new File("../preliminary").mkdir();
        new File("../tests").mkdir();        
        testDescr = new PrintWriter("../tests.desc");
        genSample();
        {
            sb = 1;
            for (int i = 0; i < 10; ++i) {
                int[] arr = genArray(randFromTo(1, 7), randFromTo(1, 10));
                printTest(arr.length, randFromTo(1, 5), arr, "random test");
            }
            int[] arr = genArray(10, 1000000000);
            printTest(10, 1, arr, "max test");
            
            arr = genArray(10, 1000000000);
            printTest(10, 5, arr, "max test");
            
            arr = genArray(10, 10);
            printTest(10, 5, arr, "test");

            arr = genArray(10, 5);
            printTest(10, 5, arr, "test");
            
            arr = genArray(10, 1);
            printTest(10, 5, arr, "test");
                    
            arr = genArray(10, 1);          
            for (int i = 0; i < 10; ++i)    
                arr[i] = 1000000000;
            printTest(10, 5, arr, "test");
                                                                           
            testDescr.println("comment_subtask1=\"n &lt;= 10, k &lt;= 10\"\nbonus_subtask1=20");
        }
        {
            sb = 2;
            for (int i = 0; i < 15; ++i) {
                int[] arr = genArray(randFromTo(50, 100), randFromTo(1, 100));
                printTest(arr.length, randFromTo(1, 100), arr, "random test");
            }
            int[] arr = genArray(100, 1000000000);
            printTest(10, 100, arr, "max test");
            
            arr = genArray(100, 100);
            printTest(100, 100, arr, "test");

            arr = genArray(100, 50);
            printTest(100, 100, arr, "test");           

            arr = genArray(100, 1);
            printTest(100, 100, arr, "test");

            arr = genArray(100, 1);         
            for (int i = 0; i < 100; ++i)   
                arr[i] = 1000000000;
            printTest(100, 100, arr, "test");
            
            arr = new int[100];
            for (int i = 0; i < arr.length; i++)
                arr[i] = (i % 2) * 999999999 + 1;
            printTest(100, 100, arr, "test");
                                               
            testDescr.println("comment_subtask2=\"n &lt;= 100, k &lt;= 100\"\nbonus_subtask2=30");
        }
        {
            sb = 3;
            for (int i = 0; i < 10; ++i) {
                int[] arr = genArray(randFromTo(50, 100), 1000000000);
                printTest(arr.length, randFromTo(1000, 1000000000), arr, "random test");
            }
            int[] arr = genArray(100, 1000000000);
            printTest(100, 1000000000, arr, "max test");
            
            arr = genArray(100, 1);         
            for (int i = 0; i < 100; ++i)   
                arr[i] = 1000000000;
            printTest(100, 100, arr, "test");
            
            arr = new int[100];
            for (int i = 0; i < arr.length; i++)
                arr[i] = (i % 2) * 999999999 + 1;
            printTest(100, 1000000000, arr, "test");
                                               
            testDescr.println("comment_subtask3=\"n &lt;= 100, k &lt;= 1000000000\"\nbonus_subtask3=30");
        }
        {
            sb = 4;
            for (int i = 0; i < 20; ++i) {
                int[] arr = genArray(randFromTo(1000, 2000), 1000000000);
                printTest(arr.length, randFromTo(1, 1000000000), arr, "random test");
            }
            int[] arr = genArray(2000, 1000000000);
            printTest(2000, 1000000000, arr, "max test");
            
            arr = genArray(2000, 1000000000);
            printTest(2000, 1000000000, arr, "test");

            arr = genArray(2000, 1000);
            printTest(2000, 1000, arr, "test");                                                                                                         
            
            arr = genArray(2000, 1);            
            printTest(2000, 2000, arr, "test");


            arr = genArray(2000, 1);            
            for (int i = 0; i < 2000; ++i)  
                arr[i] = 1000000000;
            printTest(2000, 2000, arr, "test");

            arr = new int[2000];
            for (int i = 0; i < arr.length; i++)
                arr[i] = (i % 2) * 999999999 + 1;
            printTest(2000, 1000000000, arr, "test");
            printTest(2000, 2000, arr, "test");

            testDescr.println("comment_subtask4=\"n &lt;= 2000, k &lt;= 10^9\"\nbonus_subtask4=20");
        }

        testDescr.close();
    }                 
}
