#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

const int MAXN = 2e5+5;
int a[MAXN],b[MAXN],idb;///help masiv
mt19937 mt(40583);

int reand(int m)///better random???
{
    return mt()%(mt()%m + 1) + 1;
}

int used[MAXN];


struct Test
{
    string name;

    void makeDiff(int n) {
        map<int, int> used;

        for (int i = 1; i <= n; i++) {
            int current = a[i];
            //if (used[a[i]] != 0) a[i] = 1;
            while (used[a[i]] != 0) a[i]++;
            used[a[i]] = 1;
        }

    }

     void randomass(int MODN, int MODA, int i)
    {
        bool f = false;
        if(MODA == -1)
        {
            MODA = 1e6;
            f = true;
        }

        ofstream fout(name);
        int n;
        if(i%2 == 0) n = reand(MODN);
        else n = mt()%MODN + 1;

        for(int i = 1; i <= n; i++) a[i] = reand(MODA) + 1;

        if(f)
        {
            set<int>s;
            vector<int>res;
            for(int i = 1; i <= n; i++)
            {
                if(s.find(a[i]) == s.end())
                {
                    s.insert(a[i]);
                    res.push_back(a[i]);
                }
            }
            fout << res.size() << endl;
            for(int x : res) fout << x << " ";
            fout << endl;
            return;
        }

        if (f) {
            makeDiff(n);
        }

        fout << n << endl;
        for(int i = 1; i <= n; i++) fout << a[i] << " ";
        fout << endl;
    }

    void quality(int MODN, int MODA, int i)
    {
        bool f = false;
        if(MODA == -1)
        {
            MODA = 1e6;
            f = true;
        }

        ofstream fout(name);

        int k = mt()%(MODN/2 + 1) + 1;
        for(int i = 1; i <= k; i++)
        {
            if(i%3 == 0) b[i] = mt()%2;
            else b[i] = b[i-1];
        }

        int n;
        if(i%2 == 0) n = reand(MODN);
        else n = mt()%MODN + 1;


        vector<int>val;
        for(int i = 0; i <= k; i++) val.push_back(reand(MODA));
        sort(val.begin(),val.end());
        reverse(val.begin(),val.end());

        vector<int>pos;
        pos.push_back(mt()%n + 1);

        int MINM = 75;
        int MAXM = 100000;

        int st = mt()%2000;
        int minpos = 1e9;
        for(int i = 1; i <= k; i++)
        {
            if(i < k && b[i] == b[i+1])
            {
                if(b[i]) pos.push_back(pos.back() + mt()%MINM + 1);
                else pos.push_back(pos.back() - mt()%MINM - 1);
            }
            else
            {
                if(b[i]) pos.push_back(pos.back() + mt()%MAXM + 1);
                else pos.push_back(pos.back() - mt()%MAXM - 1);
            }
        }

        for(int i = 0; i <= k; i++) minpos = min(minpos,pos[i]);
        minpos = st - minpos;

        for(int i = 1; i <= n; i++) a[i] = 0;
        for(int i = 0; i <= k; i++) a[(pos[i] + minpos)%n + 1] = val[i];
        for(int i = 1; i <= n; i++) if(!a[i]) a[i] = reand(MODA);

        if(f)
        {
            set<int>s;
            vector<int>res;
            for(int i = 1; i <= n; i++)
            {
                if(s.find(a[i]) == s.end())
                {
                    s.insert(a[i]);
                    res.push_back(a[i]);
                }
            }
            fout << res.size() << endl;
            for(int x : res) fout << x << " ";
            fout << endl;
            return;
        }

        if (f) {
            makeDiff(n);
        }

        fout << n << endl;
        for(int i = 1; i <= n; i++) fout << a[i] << " ";
        fout << endl;
    }

    void almostsort(int MODN, int MODA, int i)
    {
        bool f = false;
        MODN = min(MODN,(int)2e4);
        if(MODA == -1)
        {
            MODA = 1e6;
            f = true;
        }

        ofstream fout(name);
        int n = reand(MODN);

        bool f8 = false;
        if(i == 8) f8 = true;

        for(int i = 1; i <= n; i++)
        {
            a[i] = i;
        }
        if(i % 2) reverse(a+1,a+n+1);
        if(i == 9)
        {
            int k = n/2 + 1;
            reverse(a+1,a+k+1);
        }


        for(int q = 1; q <= 8; q++)
        {
            int l = reand(n);
            int r = reand(n);
            if(l > r) swap(l,r);
            reverse(a+l,a+r+1);
        }

        if (f) {
            makeDiff(n);
        }

        fout << n << endl;
        for(int i = 1; i <= n; i++) fout << a[i] << " ";
        fout << endl;
    }

    void eq(int MODN, int MODA, int i, bool change)
    {
        bool makeDifferent = false;
        if(MODA == -1) {
            MODA = 1e6;
            makeDifferent = true;
        }

        cout << name << endl;
        ofstream fout(name);
        int n = MODN;

        int val = reand(n);

        for(int i = 1; i <= n; i++)
        {
            a[i] = val;
        }
        if (change) {
            a[reand(n)] = reand(n);
            a[reand(n)] = reand(n);
            a[reand(n)] = reand(n);
        }

        if (makeDifferent) {
            makeDiff(n);
        }

        fout << n << endl;
        for(int i = 1; i <= n; i++) fout << a[i] << " ";
        fout << endl;
    }

    void st(int MODN, int MODA, int i, bool change)
    {
        bool makeDifferent = false;
        if(MODA == -1) {
            MODA = 1e6;
            makeDifferent = true;
        }

        ofstream fout(name);
        int n = MODN;

        for(int i = 1; i <= n; i++)
        {
            a[i] = reand(MODA);
        }
        sort(a+1, a+n+1);

        if (change) {
            reverse(a+1, a+n+1);
            a[reand(n)] = reand(n);
            a[reand(n)] = reand(n);
            a[reand(n)] = reand(n);
        }

        //cout << i << endl;
        if (i == 8) {
            //cout << n << endl;
            //for (int i = 1; i <= n; i++) cout << a[i] << " ";
            //cout << endl;
        }

        if (makeDifferent) {
            makeDiff(n);
        }

        fout << n << endl;
        for(int i = 1; i <= n; i++) fout << a[i] << " ";
        fout << endl;
    }


    void gen1_n_do_20(int i)
    {
        if (i == 2) eq(20, 20, i, false);
        else if (i == 3) eq(20, 20, i, true);
        else if (i == 8) st(20, 20, i, false);
        else if (i == 9) st(20, 20, i, true);
        else if(i <= 3) randomass(20, 20,i);
        else if(i <= 6) quality(20, 20,i);
        else almostsort(20,20,i);
    }
    void gen2_n_do_5000(int i)
    {
        if (i == 2) eq(5000, 5000, i, false);
        else if (i == 3) eq(5000, 5000, i, true);
        else if (i == 8) st(5000, 5000, i, false);
        else if (i == 9) st(5000, 5000, i, true);
        else if(i <= 3) randomass(5000, 5000,i);
        else if(i <= 6) quality(5000, 5000,i);
        else almostsort(5000,5000,i);
    }
    void gen3_ai_different(int i)
    {
        if (i == 8) st(200000, -1, i, false);
        else if (i == 9) st(200000, -1, i, true);
        else if(i <= 3) randomass(200000,-1,i);
        else if(i <= 6) quality(200000,-1,i);
        else almostsort(200000,-1,i);
    }
    void gen4_ai_do_1e6(int i)
    {
        if (i == 2) eq(200000, 1e6, i, false);
        else if (i == 3) eq(200000, 1e6, i, true);
        else if (i == 8) st(200000, 1e6, i, false);
        else if (i == 9) st(200000, 1e6, i, true);
        else if(i <= 3) randomass(200000,1e6,i);
        else if(i <= 6) quality(200000,1e6,i);
        else almostsort(200000,1e6,i);
    }
    void gen5_ai_do_1e9(int i)
    {
        if (i == 2) eq(200000, 1e9, i, false);
        else if (i == 3) eq(200000, 1e9, i, true);
        else if (i == 8) st(200000, 1e9, i, false);
        else if (i == 9) st(200000, 1e9, i, true);
        else if(i <= 3) randomass(200000,1e9,i);
        else if(i <= 6) quality(200000,1e9,i);
        else almostsort(200000,1e9,i);
    }
};

string str(int i)
{
    string res = "";
    do
    {
        res += (char)(i%10+'0');
        i /= 10;
    }while(i != 0);
    reverse(res.begin(),res.end());
    if(res.size() == 1) res = "0" + res;
    return res;
}

int main()
{
    Test T;
    for(int i = 1; i <= 10; i++)
    {
        T.name = "test" + str(i) + ".in";
        cout << T.name << endl;
        T.gen1_n_do_20(i%10+1);
    }
    for(int i = 11; i <= 20; i++)
    {
        T.name = "test" + str(i) + ".in";
        cout << T.name << endl;
        T.gen2_n_do_5000(i%10+1);
    }
    for(int i = 21; i <= 30; i++)
    {
        T.name = "test" + str(i) + ".in";
        cout << T.name << endl;
        T.gen3_ai_different(i%10+1);
    }
    for(int i = 31; i <= 40; i++)
    {
        T.name = "test" + str(i) + ".in";
        cout << T.name << endl;
        T.gen4_ai_do_1e6(i%10+1);
    }
    for(int i = 41; i <= 50; i++)
    {
        T.name = "test" + str(i) + ".in";
        cout << T.name << endl;
        T.gen5_ai_do_1e9(i%10+1);
    }
return 0;
}
