Problem: cf1854_d
Difficulty: hard
Categories: graph, search
Time limit: 2000 ms, memory limit: 256 MB

Michael and Brian are stuck in a hotel with $n$ rooms, numbered from $1$ to $n$, and need to find each other. But this hotel's doors are all locked and the only way of getting around is by using the teleporters in each room. Room $i$ has a teleporter that will take you to room $a_i$ (it might be that $a_i = i$). But they don't know the values of $a_1,a_2, \dots, a_n$.

Instead, they can call up the front desk to ask queries. In one query, they give a room $u$, a positive integer $k$, and a set of rooms $S$. The hotel concierge answers whether a person starting in room $u$, and using the teleporters $k$ times, ends up in a room in $S$.

Brian is in room $1$. Michael wants to know the set $A$ of rooms so that if he starts in one of those rooms they can use the teleporters to meet up. He can ask at most $2000$ queries.

The values $a_1, a_2, \dots, a_n$ are fixed before the start of the interaction and do not depend on your queries. In other words, the interactor is not adaptive.

Input

The input contains a single integer $n$ ($2 \leq n \leq 500$).

Interaction

To ask a query, print a line in the format "? u k |S| S\_1 S\_2 ... S\_|S|" with $1 \leq u, S_1, \ldots, S_{|S|} \leq n$, all the $S_i$ distinct, and $1 \leq k \leq 10^9$.

As a response to the query you will get "1" if the answer is yes, and "0" if the answer is no.

To output an answer, you should print "! |A| A\_1 A\_2 ... A\_|A|" with $1 \leq A_1, \ldots, A_{|A|} \leq n$ all distinct. Printing the answer doesn't count as a query.

See the interaction example for more clarity.

If you ask too many queries or you ask a malformed query, you will get Wrong answer.

After printing a query do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

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

Example

Input

```
5

0

1
```

Output

```
? 3 5 2 2 3

? 2 5 2 2 3

! 3 1 3 4
```

Note

In the sample test, there are $n=5$ rooms and the (hidden) array describing the behavior of the teleporters is $[1, 2, 1, 3, 2]$.

* The first query asks whether starting from room number $a=3$, and using the teleporters $5$ times, one ends up in one of the two rooms $S=\{2, 3\}$. This action results in ending up in the room $1$, so the answer is $0$.
* The second query asks whether starting from room number $a=2$, and using the teleporters $5$ times, one ends up in one of the two rooms $S=\{2, 3\}$. This action results in ending up in the room $2$, so the answer is $1$.

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


static int queries = 0;
static int query_limit = 2000;
static const int HARD_CAP = 20005; 

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

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


int n;
vector<int> a;           
int up[505][32];         
set<int> true_answer;    


int get_dest(int u, long long k) {
    for (int j = 0; j < 30; j++) {
        if ((k >> j) & 1) {
            u = up[u][j];
        }
    }
    return u;
}

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

    
    n = inf.readInt();
    a.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        a[i] = inf.readInt();
    }
    
    
    query_limit = 2000;
    
    
    log_metrics();

    
    for (int i = 1; i <= n; i++) {
        up[i][0] = a[i];
    }
    for (int j = 1; j < 30; j++) {
        for (int i = 1; i <= n; i++) {
            up[i][j] = up[up[i][j-1]][j-1];
        }
    }

    
    
    
    
    
    vector<int> vis(n + 1, 0);
    int curr = 1;
    while (!vis[curr]) {
        vis[curr] = 1;
        curr = a[curr];
    }
    
    set<int> cycle_nodes;
    int start_cycle = curr;
    while (true) {
        cycle_nodes.insert(curr);
        curr = a[curr];
        if (curr == start_cycle) break;
    }

    
    vector<vector<int>> rev_adj(n + 1);
    for (int i = 1; i <= n; i++) {
        rev_adj[a[i]].push_back(i);
    }

    queue<int> q;
    vector<bool> in_component(n + 1, false);
    for (int x : cycle_nodes) {
        in_component[x] = true;
        true_answer.insert(x);
        q.push(x);
    }

    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int v : rev_adj[u]) {
            if (!in_component[v]) {
                in_component[v] = true;
                true_answer.insert(v);
                q.push(v);
            }
        }
    }

    
    cout << n << endl;

    
    while (true) {
        
        if (queries > 0 && queries % 10 == 0) log_metrics();

        
        if (queries > HARD_CAP) {
            finish(_pe, "Hard query limit exceeded");
        }

        string token;
        if (!(cin >> token)) {
            finish(_wa, "Unexpected EOF: failed to read query/answer token");
        }

        if (token == "!") {
            
            int sz;
            if (!(cin >> sz)) finish(_wa, "Failed to read answer size");
            
            vector<int> user_ans;
            for (int i = 0; i < sz; i++) {
                int val;
                if (!(cin >> val)) finish(_wa, "Failed to read answer element");
                user_ans.push_back(val);
            }

            
            sort(user_ans.begin(), user_ans.end());
            if (unique(user_ans.begin(), user_ans.end()) != user_ans.end()) {
                finish(_wa, "Duplicate elements in answer set");
            }

            if ((int)user_ans.size() != (int)true_answer.size()) {
                finish(_wa, "Answer set size mismatch");
            }

            int idx = 0;
            for (int x : true_answer) {
                if (idx >= (int)user_ans.size() || user_ans[idx] != x) {
                    finish(_wa, "Answer set content mismatch");
                }
                idx++;
            }

            finish(_ok, "Correct answer");
        } else {
            
            int u;
            if (token == "?") {
                if (!(cin >> u)) finish(_wa, "Failed to read u after '?'");
            } else {
                try {
                    u = stoi(token);
                } catch (...) {
                    finish(_wa, "Invalid format for u: " + token);
                }
            }

            long long k;
            if (!(cin >> k)) finish(_wa, "Failed to read k");

            int s_len;
            if (!(cin >> s_len)) finish(_wa, "Failed to read |S|");

            
            if (u < 1 || u > n) finish(_wa, "u out of range [1, n]");
            if (k < 1 || k > 1000000000LL) finish(_wa, "k out of range [1, 10^9]");
            if (s_len < 1 || s_len > n) finish(_wa, "|S| out of range [1, n]");

            set<int> S;
            for (int i = 0; i < s_len; i++) {
                int val;
                if (!(cin >> val)) finish(_wa, "Failed to read element of S");
                if (val < 1 || val > n) finish(_wa, "Element of S out of range");
                if (S.count(val)) finish(_wa, "Duplicate element in S");
                S.insert(val);
            }

            queries++;

            
            int dest = get_dest(u, k);
            int response = (S.count(dest) ? 1 : 0);
            
            cout << response << endl;
        }
    }

    return 0;
}


Adaptive interactor (C++):

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

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

    
    string mode = opt<string>("mode", "non");
    
    int n_opt = opt<int>("n", -1);

    
    int seed_val = 0;
    if (argc > 1) seed_val = atoi(argv[1]);

    int n = n_opt;
    vector<int> a;

    
    if (seed_val == 1) {
        n = 2;
        a.resize(n + 1);
        a[1] = 2; a[2] = 1; 
    } 
    else if (seed_val == 2) {
        
        if (n == -1) n = 500;
        a.resize(n + 1);
        vector<int> p = rnd.perm(n, 1);
        for (int i = 0; i < n; ++i) {
            a[p[i]] = p[(i + 1) % n];
        }
    } 
    else if (seed_val == 3) {
        
        if (n == -1) n = 500;
        a.resize(n + 1);
        for (int i = 1; i <= n; ++i) a[i] = i;
    } 
    else {
        
        if (n == -1) {
            
            if (rnd.next(3) == 0) n = rnd.next(2, 500);
            else n = 500;
        }
        a.resize(n + 1);

        int type = rnd.next(5);
        
        if (type == 0) {
            
            for (int i = 1; i <= n; ++i) a[i] = rnd.next(1, n);
        } 
        else if (type == 1) {
            
            vector<int> p = rnd.perm(n, 1);
            
            
            
            
            
            for (int i = 1; i <= n; ++i) a[i] = p[i - 1];
        } 
        else if (type == 2) {
            
            
            vector<int> p = rnd.perm(n, 1);
            int cycle_len = rnd.next(1, n);
            
            
            for (int i = 0; i < cycle_len; ++i) {
                a[p[i]] = p[(i + 1) % cycle_len];
            }
            
            
            for (int i = cycle_len; i < n; ++i) {
                
                int target_idx = rnd.next(0, i - 1);
                
                if (rnd.next(3) == 0) target_idx = rnd.next(max(0, i - 20), i - 1);
                a[p[i]] = p[target_idx];
            }
        } 
        else if (type == 3) {
            
            
            int comp_size = rnd.next(1, min(n, 50));
            vector<int> p = rnd.perm(n, 1);
            
            
            for (int i = 0; i < n; ++i) {
                if (p[i] == 1) {
                    swap(p[0], p[i]);
                    break;
                }
            }
            
            
            for (int i = 0; i < comp_size; ++i) {
                a[p[i]] = p[rnd.next(0, comp_size - 1)];
            }
            
            
            for (int i = comp_size; i < n; ++i) {
                if (comp_size < n)
                    a[p[i]] = p[rnd.next(comp_size, n - 1)]; 
                else
                    a[p[i]] = p[rnd.next(0, n - 1)];
            }
        } 
        else {
            
            
            int cycle_len = rnd.next(1, max(1, n / 10)); 
            int tail_len = n - cycle_len; 
            
            vector<int> p = rnd.perm(n, 1);
            
            
            
            
            for(int i=0; i<tail_len; ++i) {
                a[p[i]] = p[i+1];
            }
            
            if (tail_len > 0)
                a[p[tail_len-1]] = p[tail_len + rnd.next(0, cycle_len-1)];
            
            
            for(int i=tail_len; i<n; ++i) {
                int nxt = i + 1;
                if (nxt == n) nxt = tail_len;
                a[p[i]] = p[nxt];
            }
        }
    }

    if (mode == "non") {
        
        
        cout << n << endl;
        for (int i = 1; i <= n; ++i) {
            cout << a[i] << (i == n ? "" : " ");
        }
        cout << endl;
    } else {
        
        
        cout << n << endl;
    }

    return 0;
}