Problem: cf1566_h
Difficulty: hard
Categories: game, bit, math
Time limit: 4000 ms, memory limit: 256 MB

This is an interactive problem.

You are given two integers $c$ and $n$. The jury has a randomly generated set $A$ of distinct positive integers not greater than $c$ (it is generated from all such possible sets with equal probability). The size of $A$ is equal to $n$.

Your task is to guess the set $A$. In order to guess it, you can ask at most $\lceil 0.65 \cdot c \rceil$ queries.

In each query, you choose a single integer $1 \le x \le c$. As the answer to this query you will be given the bitwise xor sum of all $y$, such that $y \in A$ and $gcd(x, y) = 1$ (i.e. $x$ and $y$ are coprime). If there is no such $y$ this xor sum is equal to $0$.

You can ask all queries at the beginning and you will receive the answers to all your queries. After that, you won't have the possibility to ask queries.

You should find any set $A'$, such that $|A'| = n$ and $A'$ and $A$ have the same answers for all $c$ possible queries.

Input

Firstly you are given two integers $c$ and $n$ ($100 \le c \le 10^6$, $0 \le n \le c$).

Interaction

In the first line you should print an integer $q$ $(0 \le q \le \lceil 0.65 \cdot c \rceil)$ — the number of queries you want to ask. After that in the same line print $q$ integers $x_1, x_2, \ldots, x_q$ $(1 \le x_i \le c)$ — the queries.

For these queries you should read $q$ integers, $i$-th of them is the answer to the described query for $x = x_i$.

After that you should print $n$ distinct integers $A'_1, A'_2, \ldots, A'_n$ — the set $A'$ you found.

If there are different sets $A'$ that have the same answers for all possible queries, print any of them.

If you will ask more than $\lceil 0.65 \cdot c \rceil$ queries or if the queries will be invalid, the interactor will terminate immediately and your program will receive verdict Wrong Answer.

After printing the queries and answers do not forget to output end of line and flush the output buffer. Otherwise, you will get the Idleness limit exceeded verdict. To do flush use:

* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* Read documentation for other languages.

Example

Input

```
10 6

1 4 2 11 4 4 4
```

Output

```
7 10 2 3 5 7 1 6

1 4 5 6 8 10
```

Note

The sample is made only for you to understand the interaction protocol. Your solution will not be tested on the sample.

In the sample $A = \{1, 4, 5, 6, 8, 10\}$. $7$ queries are made, $7 \le \lceil 0.65 \cdot 10 \rceil = 7$, so the query limit is not exceeded.

Answers for the queries:

* For $10$: $1$ is the only number in the set $A$ coprime with $10$, so the answer is $1$
* For $2$: $1_{10} \oplus 5_{10} = 001_2 \oplus 101_2 = 4_{10}$, where $\oplus$ is the bitwise xor
* For $3$: $1_{10} \oplus 4_{10} \oplus 5_{10} \oplus 8_{10} \oplus 10_{10} = 0001_2 \oplus 0100_2 \oplus 0101_2 \oplus 1000_2 \oplus 1010_2 = 2_{10}$
* For $5$: $1_{10} \oplus 4_{10} \oplus 6_{10} \oplus 8_{10} = 0001_2 \oplus 0100_2 \oplus 0110_2 \oplus 1000_2 = 11_{10}$
* For $7$: $1_{10} \oplus 4_{10} \oplus 5_{10} \oplus 6_{10} \oplus 8_{10} \oplus 10_{10} = 0001_2 \oplus 0100_2 \oplus 0101_2 \oplus 0110_2 \oplus 1000_2 \oplus 1010_2 = 4_{10}$
* For $1$: $1_{10} \oplus 4_{10} \oplus 5_{10} \oplus 6_{10} \oplus 8_{10} \oplus 10_{10} = 0001_2 \oplus 0100_2 \oplus 0101_2 \oplus 0110_2 \oplus 1000_2 \oplus 1010_2 = 4_{10}$
* For $6$: $1_{10} \oplus 5_{10} = 0001_2 \oplus 0101_2 = 4_{10}$

Non-adaptive interactor (C++):
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long queries = 0;
static long long query_limit = 0;

static void log_metrics() {
    try {
        tout << "queries=" << queries << "\n";
        tout << "query_limit=" << query_limit << "\n";
        tout.flush();
    } catch (...) {
        
    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

int main(int argc, char* argv[]) {
    registerInteraction(argc, argv);
    atexit(log_metrics);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    const int c = inf.readInt(100, 1000000, "c");
    const int n = inf.readInt(0, c, "n");

    vector<char> inA(c + 1, 0);
    for (int i = 0; i < n; i++) {
        int v = inf.readInt(1, c, "A[i]");
        if (inA[v]) finish(_fail, "Invalid hidden set: duplicates");
        inA[v] = 1;
    }
    

    
    
    
    vector<int> G(c + 1, 0);
    for (int d = 1; d <= c; d++) {
        int acc = 0;
        for (int m = d; m <= c; m += d) {
            if (inA[m]) acc ^= m;
        }
        G[d] = acc;
    }

    vector<char> squarefree(c + 1, 1);
    for (long long p = 2; p * p <= c; p++) {
        long long sq = p * p;
        for (long long m = sq; m <= c; m += sq) {
            squarefree[(int)m] = 0;
        }
    }

    vector<int> ans_all(c + 1, 0);
    for (int d = 1; d <= c; d++) {
        if (!squarefree[d]) continue;
        int v = G[d];
        if (v == 0) continue;
        for (int m = d; m <= c; m += d) {
            ans_all[m] ^= v;
        }
    }

    query_limit = (65LL * c + 99) / 100; 

    log_metrics(); 

    
    cout << c << " " << n << "\n";
    cout.flush();

    long long q_ll = 0;
    if (!(cin >> q_ll)) finish(_pe, "Unexpected EOF reading q");
    if (q_ll < 0 || q_ll > query_limit) finish(_wa, "Query limit exceeded");
    int q = (int)q_ll;

    vector<int> xs(q);
    for (int i = 0; i < q; i++) {
        long long x_ll = 0;
        if (!(cin >> x_ll)) finish(_pe, "Unexpected EOF reading query x");
        if (x_ll < 1 || x_ll > c) finish(_wa, "Query x out of range");
        xs[i] = (int)x_ll;
    }
    queries = q;

    
    for (int i = 0; i < q; i++) {
        if (i) cout << ' ';
        cout << ans_all[xs[i]];
    }
    cout << "\n";
    cout.flush();

    
    vector<char> inB(c + 1, 0);
    for (int i = 0; i < n; i++) {
        long long v_ll = 0;
        if (!(cin >> v_ll)) finish(_pe, "Unexpected EOF reading final set");
        if (v_ll < 1 || v_ll > c) finish(_wa, "Final value out of range");
        int v = (int)v_ll;
        if (inB[v]) finish(_wa, "Final set contains duplicates");
        inB[v] = 1;
    }

    
    vector<int> G2(c + 1, 0);
    for (int d = 1; d <= c; d++) {
        int acc = 0;
        for (int m = d; m <= c; m += d) {
            if (inB[m]) acc ^= m;
        }
        G2[d] = acc;
    }
    vector<int> ans2(c + 1, 0);
    for (int d = 1; d <= c; d++) {
        if (!squarefree[d]) continue;
        int v = G2[d];
        if (v == 0) continue;
        for (int m = d; m <= c; m += d) {
            ans2[m] ^= v;
        }
    }

    for (int x = 1; x <= c; x++) {
        if (ans2[x] != ans_all[x]) finish(_wa, "Final set is not equivalent to hidden set");
    }

    finish(_ok, "OK");
}


Adaptive interactor (C++):

Test generator (C++):
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static void fyShuffle(vector<int> &v) {
    for (int i = (int)v.size() - 1; i > 0; --i) {
        int j = rnd.next(0, i);
        swap(v[i], v[j]);
    }
}

static vector<int> buildCaseNon(int c, int n, long long seed) {
    (void)seed;
    if (n == 0) return {};

    
    
    
    vector<int> pool(c);
    iota(pool.begin(), pool.end(), 1);
    fyShuffle(pool);
    pool.resize(n);
    return pool;
}

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");

    long long seed = 0;
    if (argc >= 2) {
        
        seed = atoll(argv[1]);
    }

    int cOpt = opt<int>("c", -1);
    int nOpt = opt<int>("n", -1);

    int c, n;

    if (cOpt != -1) c = cOpt;
    else {
        if (seed == 1) c = 100;
        else if (seed == 2) c = 1000000;
        else if (seed == 3) c = 1000000;
        else c = 1000000;
    }

    c = max(100, min(1000000, c));

    if (nOpt != -1) n = nOpt;
    else {
        if (seed == 1) n = 0;
        else n = min(c, 500000);
    }

    n = max(0, min(c, n));

    if (mode == "adp") {
        
        cout << c << " " << n << "\n";
        return 0;
    }

    
    vector<int> A = buildCaseNon(c, n, seed);
    if ((int)A.size() != n) {
        
        A.clear();
        for (int i = 1; i <= c && (int)A.size() < n; ++i) A.push_back(i);
    }

    cout << c << " " << n << "\n";
    if (n > 0) {
        for (int i = 0; i < n; ++i) {
            if (i) cout << ' ';
            cout << A[i];
        }
        cout << "\n";
    }
    return 0;
}