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

public class TestsGen {

    static PrintWriter out;
    static Random rnd = new Random(0);
    static int tNumber = 1;         
    static final int MAX_N = 100000;
    static final int MAX_K = 100000;
    static final int MAX_X = 10000;
    
    static void printTest(int n, int k, int[] x) throws IOException {
        System.out.println(String.format("Generating test %d", tNumber));
        out = new PrintWriter(String.format("../tests/%02d", tNumber++));
        out.println(n + " " + k);
        for (int i = 0; i < n; ++i) {
            out.print(x[i]);
            if (i != n-1) out.print(" ");
        }
        out.println();
        out.close();
    }

    
    static void genSample() throws IOException {
        printTest(4, 1, new int[] {1, 2, -1, -3});
        printTest(7, 2, new int[] {5, -3, 7, 9, -2, -8, -1});
    }
    
    static int randFromTo(int l, int r) {
        return rnd.nextInt(r - l + 1) + l;      
    }

    static int randSign(int a, int b) {
        int x = randFromTo(0, a + b - 1);
        if (x < a)
            return 1;
        return -1;
    }

    static int pow(int x, int y) {
        int ans = 1;
        while (y > 0) {
            ans *= x;
            y--;
        }
        return x;
    }

    public static void main(String[] args) throws IOException {
        new File("../tests").mkdir();        
        genSample();                       
        printTest(1, 1, new int[] {-1000});
        printTest(1, 1, new int[] {1000});
        
        for (int it = 0; it < 5; ++it) {
            int n = randFromTo(10, 100);
            int k = randFromTo(3, n/2);
            int[] x = new int[n];
            for (int i = 0; i < n; ++i)
                x[i] = randFromTo(1, 1000) * randSign(1, 1);
            printTest(n, k, x); 
        }
        
        {
            int n = MAX_N;
            int k = MAX_N/2;
            int[] x = new int[n];
            for (int i = 0; i < n; ++i)
                x[i] = randFromTo(1, MAX_X) * randSign(1, 1);
            printTest(n, k, x);
            printTest(n, 1, x);
            printTest(n, n, x);
        }
        
        {
            int n = MAX_N;
            int k = randFromTo(1000, n);
            int[] x = new int[n];
            for (int i = 0; i < n; ++i)
                x[i] = randFromTo(1, MAX_X) * randSign(3, 1);
            printTest(n, k, x);
        }

        {
            int n = MAX_N;
            int k = randFromTo(1000, n);
            int[] x = new int[n];
            for (int i = 0; i < n; ++i)
                x[i] = randFromTo(1, MAX_X) * randSign(1, 3);
            printTest(n, k, x);
        }

        {
            int n = MAX_N;
            int k = n;
            int[] x = new int[n];
            for (int i = 0; i < n; ++i)
                x[i] = randFromTo(1, MAX_X) * randSign(1, 1);
            printTest(n, k, x);
        }
        
        
        printTest(5, 1, new int[]{-100, -1, 1, 10, 10});

        for (int it = 0; it < 5; ++it) {
            int n = randFromTo(10000, MAX_N);
            int k = randFromTo(100, 1000);
            int[] x = new int[n];
            for (int i = 0; i < k*2; ++i) {
                x[i] = randFromTo(100, MAX_X) * randSign(randFromTo(1,2),randFromTo(1,2));
            }
            for (int i = 2*k; i < n; ++i) {
                x[i] = randFromTo(10, 100) * randSign(randFromTo(1,2),randFromTo(1,2));
            }
            printTest(n, k, x);          
        }


        for (int it = 0; it < 5; ++it) {
            int n = randFromTo(1000, MAX_N);
            int k = randFromTo(1000, n);
            int[] x = new int[n];
            for (int i = 0; i < n; ++i)
                x[i] = randFromTo(pow(3, i%(it+1)), pow(5, i%(it+1))) * randSign(randFromTo(1, 5), randFromTo(1, 5));
            printTest(n, k, x); 
        }

        for (int it = 0; it < 5; ++it) {
            int n = randFromTo(10000, MAX_N);
            int k = randFromTo(100, 1000);
            int[] x = new int[n];
            for (int i = 0; i < n; ++i)
                x[i] = randFromTo(10, 100) * randSign(randFromTo(1, 5), randFromTo(1, 5));
            printTest(n, k, x); 
        }

        for (int it = 0; it < 5; ++it) {
            int n = randFromTo(10000, MAX_N);
            int k = randFromTo(100, 1000);
            int[] x = new int[n];
            for (int i = 0; i < n; ++i)
                x[i] = randFromTo(10, 100) * (it % 2 == 0 ? 1 : -1);
            printTest(n, k, x); 
        }

        for (int it = 0; it < 5; ++it) {
            int n = randFromTo(10000, MAX_N);
            int k = randFromTo(100, 1000);
            int[] x = new int[n];
            for (int i = 0; i < n; ++i)
                x[i] = randFromTo(pow(5, i%(it+1)), MAX_X) * randSign(1, 5);
            printTest(n, k, x); 
        }
        
        for (int it = 0; it < 5; ++it) {
            int n = randFromTo(50000, MAX_N);
            int k = randFromTo(50000, n);
            int[] x = new int[n];
            for (int i = 0; i < n; ++i)
                x[i] = randFromTo(pow(5, i%(it+1)), MAX_X) * randSign(1, 1);
            printTest(n, k, x); 
        }

        for (int it = 0; it < 5; ++it) {
            int n = randFromTo(10000, MAX_N);
            int k = randFromTo(1000, n);
            int[] x = new int[n];
            for (int i = 0; i < n; ++i)
                x[i] = randFromTo(1000, MAX_X) * randSign(randFromTo(1, 5), randFromTo(1, 5));
            printTest(n, k, x); 
        }
        
        {
            int n = MAX_N;
            int k = MAX_K;
            int[] x = new int[n];
            for (int i = 0; i < n; ++i)
                x[i] = MAX_X * randSign(1, 1);
            printTest(n, k, x);
        }
        
        {
            int n = MAX_N;
            int k = MAX_K / 2;
            int[] x = new int[n];
            for (int i = 0; i < n/2; ++i)
                x[i] = randFromTo(10, 1000) * randSign(1, 1);

            for (int i = n/2; i < n; ++i)
                x[i] = 1 * randSign(1, 1);
            printTest(n, k, x);
        }

        {
            int n = MAX_N;
            int k = 1;
            int[] x = new int[n];
            for (int i = 0; i < n; ++i)
                x[i] = MAX_X * randSign(1, 1);
            printTest(n, k, x);
        }


    }                 
}


