#define _GLIBCXX_FILESYSTEM
#include <bits/stdc++.h>
using namespace std;

string format(int t) {
    if (t < 10) return "0" + to_string(t);
    return to_string(t);
}

mt19937 rng;

void write(int test, string cmd) {
    system((cmd + " < input.in > ../tests/legos." + format(test) + ".in").c_str());
    
    ofstream os("../tests/legos." + format(test) + ".sol");
    os.close();

    cout << "Test " << test << " finished.\n";
}

int main() {

    for (int test = 1; test <= 5; test++) {
        ofstream os("input.in");
        os << test + 1 << '\n';
        os.close();
        
        write(test, "gen_bf.exe");
    }

    for (int test = 6; test <= 20; test++) {
        int MAXVAL = 2e5;

        ofstream os("input.in");
        if (rng() % 5) os << MAXVAL << '\n';
        else os << rng() % MAXVAL + 1 << '\n';
        
        os.close();
        if (test <= 10) write(test, "gen_one_special.exe");
        else write(test, "gen_one.exe");
    }

    for (int test = 21; test <= 35; test++) {
        int MAXVAL = 2e5;

        ofstream os("input.in");
        if (rng() % 5) os << MAXVAL << '\n';
        else os << rng() % MAXVAL + 1 << '\n';
        
        os.close();
        write(test, "gen_pow2.exe");
    }

    for (int test = 36; test <= 50; test++) {
        int MAXVAL = 2e3;

        ofstream os("input.in");
        if (rng() % 5) os << MAXVAL << '\n';
        else os << rng() % MAXVAL + 1 << '\n';
        
        os.close();
        if (test == 40 || test == 45) write(test, "gen_pow2.exe");
        else write(test, "gen_random.exe");
    }

    for (int test = 51; test <= 70; test++) {
        int MAXVAL = 4e4;

        ofstream os("input.in");
        if (rng() % 5) os << MAXVAL << '\n';
        else os << rng() % MAXVAL + 1 << '\n';
        
        os.close();
        if (test == 56 || test == 57) write(test, "gen_pow2.exe");
        else write(test, "gen_random.exe");
    }

    for (int test = 71; test <= 90; test++) {
        int MAXVAL = 2e5;

        ofstream os("input.in");
        if (rng() % 5) os << MAXVAL << '\n';
        else os << rng() % MAXVAL + 1 << '\n';
        
        os.close();
        write(test, "gen_random.exe");
    }


    return 0;

}