Problem: cf2159_a
Difficulty: medium
Categories: greedy, data structures
Time limit: 2000 ms, memory limit: 256 MB

This is an interactive problem.

There is a secret sequence $a_1, a_2, \ldots, a_{2n-1},a_{2n}$, which contains each integer from $1$ to $n$ exactly twice.

Your task is to guess the sequence by using queries of the following type:

* "? $k\;j_1\;j_2\;\ldots\;j_k$" — select the integer $k$ ($1 \le k \le 2n$) and $k$ distinct indices $j_1, j_2, \ldots, j_k$ ($1 \le j_1 , j_2 , \ldots , j_k \le 2n$). In response to the query, the jury will return $\text{MAD}([a_{j_1}, a_{j_2}, \ldots, a_{j_k}])$.

We define the $\operatorname{MAD}$ (Maximum Appearing Duplicate) of an integer sequence as the largest integer that appears at least twice. Specifically, if there is no number that appears at least twice, the $\operatorname{MAD}$ value is $0$. Some examples are as follows:

* $\operatorname{MAD}([1, 2, 1]) = 1$;
* $\operatorname{MAD}([2, 2, 3, 3]) = 3$;
* $\operatorname{MAD}([1, 2, 3, 4]) = 0$.

Please identify the secret sequence using at most $3n$ queries.

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 3000$). The description of the test cases follows.

The first line of each test case contains one integer $n$ ($2 \le n \le 300$).

It is guaranteed that the sum of $n^2$ over all test cases does not exceed $10^5$.

After you read this line of input, the interaction begins with your first query.

Interaction

To make a query, output a line (without quotes) in the following format:

* "? $k\;j_1\;j_2\;\ldots\;j_k$" ($1 \le k \le 2n$, $1 \le j_1 , j_2 , \ldots , j_k \le 2n$)

Here, the indices $j_1 , j_2 , \ldots , j_k$ which you selected must be pairwise distinct.

Then, after each query, read a single integer — the answer to your query.

You can make at most $3n$ queries of this type.

If your program has found the sequence $a$, print the line (without quotes) in the following format:

* "! $a_1\;a_2\;\ldots\;a_{2n-1}\;a_{2n}$" ($1 \le a_i \le n$)

Note that this does not count towards the query limit.

After this, proceed to the next test case, or exit if this is the last test case.

The interactor in this task is not adaptive. In other words, the sequence $a$ does not change during the interaction.

If you make more than $3n$ queries during an interaction, your program must terminate immediately, and you will receive the Wrong Answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.

After printing each line, do not forget to output the end of line and flush the output buffer. Otherwise, you will receive the Idleness Limit Exceeded verdict. To flush, use:

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

Example

Input

```
2
2

2

0

1

2

0

1

1
```

Output

```
? 2 2 1

? 2 1 3

? 3 1 3 4

! 2 2 1 1

? 2 1 2

? 2 1 3

? 3 1 3 4

! 1 2 1 2
```

Note

In the first test case, the hidden sequence is $a=[2,2,1,1]$.

For the query "? 2 2 1", the jury returns $2$ because $\operatorname{MAD}([a_2, a_1]) = \operatorname{MAD}([2, 2]) = 2$.

For the query "? 2 1 3", the jury returns $0$ because $\operatorname{MAD}([a_1, a_3]) = \operatorname{MAD}([2, 1]) = 0$.

For the query "? 3 1 3 4", the jury returns $1$ because $\operatorname{MAD}([a_1, a_3, a_4]) = \operatorname{MAD}([2 ,1, 1]) = 1$.

Note that the example interaction is only for understanding statements and does not guarantee finding a unique sequence $a$.

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());
}

static bool readLongLongFromCin(long long& x) {
    if (!(cin >> x)) return false;
    return true;
}

int main(int argc, char** argv) {
    registerInteraction(argc, argv);
    atexit(log_metrics);

    try {
        int t = inf.readInt(1, 3000, "t");

        struct TestCase {
            int n;
            vector<int> a; 
        };

        vector<TestCase> tests;
        tests.reserve(t);

        long long totalLimit = 0;
        for (int tc = 0; tc < t; ++tc) {
            int n = inf.readInt(2, 300, "n");
            vector<int> a(2 * n);
            for (int i = 0; i < 2 * n; ++i) {
                a[i] = inf.readInt(1, n, "a[i]");
            }
            tests.push_back(TestCase{n, std::move(a)});
            totalLimit += 3LL * n;
        }

        query_limit = totalLimit;
        log_metrics(); 

        long long hard_cap = max(200000LL, 10LL * query_limit);

        cout << t << '\n';
        cout.flush();
        for (int tc = 0; tc < t; ++tc) {
            cout << tests[tc].n << '\n';
            cout.flush();
        }

        for (int tc = 0; tc < t; ++tc) {
            const int n = tests[tc].n;
            const vector<int>& a = tests[tc].a;
            const int m = 2 * n;

            while (true) {
                string kind;
                if (!(cin >> kind)) {
                    finish(_pe, "Unexpected EOF from participant");
                }

                if (kind == "?") {
                    long long kll;
                    if (!readLongLongFromCin(kll)) finish(_pe, "Malformed query: missing k");
                    if (kll < 1 || kll > m) finish(_pe, "Query k out of range");
                    int k = (int)kll;

                    vector<int> idx;
                    idx.reserve(k);
                    vector<char> seen(m + 1, 0);
                    for (int i = 0; i < k; ++i) {
                        long long jll;
                        if (!readLongLongFromCin(jll)) finish(_pe, "Malformed query: missing index");
                        if (jll < 1 || jll > m) finish(_pe, "Query index out of range");
                        int j = (int)jll;
                        if (seen[j]) finish(_pe, "Query indices are not distinct");
                        seen[j] = 1;
                        idx.push_back(j);
                    }

                    ++queries;
                    if (queries > hard_cap) finish(_pe, "Hard cap exceeded");

                    vector<int> freq(n + 1, 0);
                    int mad = 0;
                    for (int j : idx) {
                        int v = a[j - 1];
                        int c = ++freq[v];
                        if (c == 2) mad = max(mad, v);
                    }

                    cout << mad << '\n';
                    cout.flush();
                } else if (kind == "!") {
                    vector<int> ans(m);
                    vector<int> freq(n + 1, 0);

                    for (int i = 0; i < m; ++i) {
                        long long xll;
                        if (!readLongLongFromCin(xll)) finish(_pe, "Malformed answer: not enough numbers");
                        if (xll < 1 || xll > n) finish(_wa, "Answer value out of range");
                        ans[i] = (int)xll;
                        freq[ans[i]]++;
                    }

                    for (int v = 1; v <= n; ++v) {
                        if (freq[v] != 2) finish(_wa, "Answer does not contain each number exactly twice");
                    }

                    if (ans != a) finish(_wa, "Answer sequence is incorrect");

                    break; 
                } else {
                    finish(_pe, "Unexpected token (expected '?' or '!')");
                }
            }
        }

        finish(_ok, "OK");
    } catch (const std::exception& e) {
        finish(_pe, string("Exception: ") + e.what());
    } catch (...) {
        finish(_pe, "Unknown exception");
    }
}


Adaptive interactor (C++):

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

static vector<int> randPerm(int n) {
    vector<int> p(n);
    iota(p.begin(), p.end(), 1);
    for (int i = n - 1; i >= 1; --i) {
        int j = rnd.next(0, i);
        swap(p[i], p[j]);
    }
    return p;
}

static vector<int> derangedFrom(const vector<int>& p) {
    int n = (int)p.size();
    vector<int> q = p;
    for (int i = n - 1; i >= 1; --i) {
        int j = rnd.next(0, i);
        swap(q[i], q[j]);
    }
    if (n == 2) {
        if (q[0] == p[0] && q[1] == p[1]) swap(q[0], q[1]);
        return q;
    }
    for (int pass = 0; pass < 5; ++pass) {
        bool ok = true;
        for (int i = 0; i < n; ++i) {
            if (q[i] == p[i]) {
                ok = false;
                int j = (i + 1) % n;
                swap(q[i], q[j]);
            }
        }
        if (ok) break;
    }
    for (int i = 0; i < n; ++i) {
        if (q[i] == p[i]) {
            int j = (i + 1) % n;
            swap(q[i], q[j]);
        }
    }
    return q;
}

static vector<int> buildSequence(int n, const string& layout, long long seed) {
    vector<int> a;
    a.reserve(2 * n);

    if (seed == 1) {
        n = 2;
        return vector<int>{1, 2, 1, 2};
    }
    if (seed == 2) {
        n = 3;
        return vector<int>{1, 2, 3, 1, 3, 2};
    }
    if (seed == 3) {
        n = 300;
        for (int i = 1; i <= n; ++i) a.push_back(i);
        for (int i = n; i >= 1; --i) a.push_back(i);
        return a;
    }

    string L = layout;
    if (L == "auto") {
        int pick = rnd.next(0, 2);
        L = (pick == 0 ? "block" : (pick == 1 ? "interleave" : "mirrorblock"));
    }

    if (L == "paired") {
        for (int x = 1; x <= n; ++x) {
            a.push_back(x);
            a.push_back(x);
        }
        return a;
    }

    if (L == "mirror") {
        for (int i = 1; i <= n; ++i) a.push_back(i);
        for (int i = n; i >= 1; --i) a.push_back(i);
        return a;
    }

    vector<int> p = randPerm(n);
    vector<int> q = derangedFrom(p);

    if (L == "mirrorblock") {
        a.insert(a.end(), p.begin(), p.end());
        for (int i = n - 1; i >= 0; --i) a.push_back(p[i]);
        return a;
    }

    if (L == "block") {
        a.insert(a.end(), p.begin(), p.end());
        a.insert(a.end(), q.begin(), q.end());
        return a;
    }

    if (L == "interleave") {
        for (int i = 0; i < n; ++i) {
            a.push_back(p[i]);
            a.push_back(q[i]);
        }
        return a;
    }

    a.insert(a.end(), p.begin(), p.end());
    a.insert(a.end(), q.begin(), q.end());
    return a;
}

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

    string mode = opt<string>("mode", "non");
    int nOpt = opt<int>("n", 300);
    string layout = opt<string>("layout", "auto");

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

    int n = nOpt;
    if (seed == 1) n = 2;
    if (seed == 2) n = 3;
    if (seed == 3) n = 300;
    n = max(2, min(300, n));

    cout << 1 << "\n";

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

    if (mode != "non") mode = "non";

    vector<int> a = buildSequence(n, layout, seed);
    if ((int)a.size() != 2 * n) {
        vector<int> fallback;
        fallback.reserve(2 * n);
        for (int i = 1; i <= n; ++i) fallback.push_back(i);
        for (int i = 1; i <= n; ++i) fallback.push_back(i);
        a.swap(fallback);
    }

    cout << n << "\n";
    for (int i = 0; i < 2 * n; ++i) {
        if (i) cout << ' ';
        cout << a[i];
    }
    cout << "\n";
    return 0;
}