Problem: cf1365_g
Difficulty: medium
Categories: bit, math
Time limit: 2000 ms, memory limit: 256 MB

This is an interactive problem.

Ayush devised yet another scheme to set the password of his lock. The lock has $n$ slots where each slot can hold any non-negative integer. The password $P$ is a sequence of $n$ integers, $i$-th element of which goes into the $i$-th slot of the lock.

To set the password, Ayush comes up with an array $A$ of $n$ integers each in the range $[0, 2^{63}-1]$. He then sets the $i$-th element of $P$ as the bitwise OR of all integers in the array except $A_i$.

You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the bitwise OR all elements of the array with index in this subset. You can ask no more than 13 queries.

Input

The first line of input contains one integer $n$ $(2 \le n \le 1000)$ — the number of slots in the lock.

Interaction

To ask a query print a single line:

* In the beginning print "? c " (without quotes) where $c$ $(1 \leq c \leq n)$ denotes the size of the subset of indices being queried, followed by $c$ distinct space-separated integers in the range $[1, n]$.

For each query, you will receive an integer $x$ — the bitwise OR of values in the array among all the indices queried. If the subset of indices queried is invalid or you exceeded the number of queries then you will get $x = -1$. In this case, you should terminate the program immediately.

When you have guessed the password, print a single line "! " (without quotes), followed by $n$ space-separated integers  — the password sequence.

Guessing the password does not count towards the number of queries asked.

The interactor is not adaptive. The array $A$ does not change with queries.

After printing a query do not forget to output the end of the 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

```
3

1

2

4
```

Output

```? 1 1? 1 2? 1 3! 6 5 3
```

Note

The array $A$ in the example is $\{{1, 2, 4\}}$. The first element of the password is bitwise OR of $A_2$ and $A_3$, the second element is bitwise OR of $A_1$ and $A_3$ and the third element is bitwise OR of $A_1$ and $A_2$. Hence the password sequence is $\{{6, 5, 3\}}$.

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 parseLongLongToken(const string& s, long long& out) {
    if (s.empty()) return false;
    int i = 0;
    bool neg = false;
    if (s[i] == '-') {
        neg = true;
        i++;
        if (i == (int)s.size()) return false;
    }
    if (s[i] < '0' || s[i] > '9') return false;
    __int128 val = 0;
    for (; i < (int)s.size(); i++) {
        char c = s[i];
        if (c < '0' || c > '9') return false;
        val = val * 10 + (c - '0');
        if (!neg && val > (__int128)LLONG_MAX) return false;
        if (neg && -val < (__int128)LLONG_MIN) return false;
    }
    out = neg ? (long long)(-val) : (long long)val;
    return true;
}

static long long readLLFromCinOrDie(const string& what) {
    string tok;
    if (!(cin >> tok)) finish(_pe, "Unexpected EOF while reading " + what);
    long long v;
    if (!parseLongLongToken(tok, v)) finish(_pe, "Malformed integer token for " + what);
    return v;
}

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

    try {
        int n = inf.readInt(2, 1000, "n");
        vector<unsigned long long> a(n);
        for (int i = 0; i < n; i++) {
            long long x = inf.readLong(0LL, LLONG_MAX, "a[i]");
            a[i] = (unsigned long long)x;
        }

        
        query_limit = 13;

        
        log_metrics();

        
        cout << n << endl;

        
        vector<unsigned long long> pref(n + 1, 0), suff(n + 1, 0);
        for (int i = 0; i < n; i++) pref[i + 1] = pref[i] | a[i];
        for (int i = n - 1; i >= 0; i--) suff[i] = suff[i + 1] | a[i];
        vector<unsigned long long> expected(n);
        for (int i = 0; i < n; i++) expected[i] = pref[i] | suff[i + 1];

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

        vector<int> seen(n, 0);
        int stamp = 0;

        while (true) {
            string cmd;
            if (!(cin >> cmd)) finish(_pe, "Unexpected EOF (no final answer)");

            if (cmd == "?") {
                long long c_ll = readLLFromCinOrDie("c");
                if (c_ll < 1 || c_ll > n) {
                    cout << -1 << endl;
                    finish(_pe, "Invalid subset size c");
                }
                int c = (int)c_ll;

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

                stamp++;
                unsigned long long res = 0;

                for (int j = 0; j < c; j++) {
                    long long idx_ll = readLLFromCinOrDie("index");
                    if (idx_ll < 1 || idx_ll > n) {
                        cout << -1 << endl;
                        finish(_pe, "Index out of range");
                    }
                    int idx = (int)idx_ll - 1;
                    if (seen[idx] == stamp) {
                        cout << -1 << endl;
                        finish(_pe, "Duplicate index in subset");
                    }
                    seen[idx] = stamp;
                    res |= a[idx];
                }

                cout << (unsigned long long)res << endl;
            } else if (cmd == "!") {
                vector<unsigned long long> got(n);
                for (int i = 0; i < n; i++) {
                    long long v = readLLFromCinOrDie("answer[i]");
                    if (v < 0) finish(_wa, "Negative value in final answer");
                    got[i] = (unsigned long long)v;
                }

                for (int i = 0; i < n; i++) {
                    if (got[i] != expected[i]) {
                        finish(_wa, "Wrong answer");
                    }
                }
                finish(_ok, "OK");
            } else {
                finish(_pe, "Unknown command token");
            }
        }
    } catch (const std::exception& e) {
        finish(_pe, string("Exception: ") + e.what());
    } catch (...) {
        finish(_pe, "Unknown exception");
    }
    return 0;
}


Adaptive interactor (C++):

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

static long long FULL63() {
    long long x = (1LL << 62) - 1;
    x |= (1LL << 62);
    return x;
}

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 minn = opt<int>("minn", 2);
    int maxn = opt<int>("maxn", 1000);
    int nOpt = opt<int>("n", -1);
    int hard = opt<int>("hard", 1);

    minn = max(minn, 2);
    maxn = min(maxn, 1000);
    if (minn > maxn) minn = maxn;

    int n = -1;
    if (nOpt != -1) {
        n = nOpt;
    } else {
        if (seed == 1) n = 2;
        else if (seed == 2) n = 1000;
        else if (seed == 3) n = 1000;
        else {
            if (hard) n = maxn;
            else n = rnd.next(minn, maxn);
        }
    }
    n = max(minn, min(maxn, n));

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

    
    const long long FULL = FULL63();
    vector<long long> a(n, 0);

    if (seed == 1) {
        n = 2;
        a.assign(n, 0);
        a[0] = 0;
        a[1] = FULL;
        cout << n << "\n" << a[0] << " " << a[1] << "\n";
        return 0;
    }
    if (seed == 2) {
        n = 1000;
        a.assign(n, 0);
        cout << n << "\n";
        for (int i = 0; i < n; i++) {
            if (i) cout << ' ';
            cout << 0;
        }
        cout << "\n";
        return 0;
    }
    if (seed == 3) {
        n = 1000;
        a.assign(n, 0);
        int m = min(63, n);
        for (int i = 0; i < m; i++) a[i] = (1LL << i);
        cout << n << "\n";
        for (int i = 0; i < n; i++) {
            if (i) cout << ' ';
            cout << a[i];
        }
        cout << "\n";
        return 0;
    }

    vector<int> bits(63);
    iota(bits.begin(), bits.end(), 0);
    for (int i = 0; i < 63; i++) {
        int j = rnd.next(i, 62);
        swap(bits[i], bits[j]);
    }

    int commonLo = hard ? 45 : 30;
    int commonHi = hard ? 58 : 50;
    commonLo = max(0, min(63, commonLo));
    commonHi = max(0, min(63, commonHi));
    if (commonLo > commonHi) swap(commonLo, commonHi);
    int commonCnt = rnd.next(commonLo, commonHi);

    long long commonMask = 0;
    for (int i = 0; i < commonCnt; i++) commonMask |= (1LL << bits[i]);

    int rem = 63 - commonCnt;
    int rareCnt = 0;
    if (rem > 0) {
        int rareLo = hard ? 6 : 3;
        int rareHi = hard ? min(14, rem) : min(10, rem);
        rareLo = max(0, min(rem, rareLo));
        rareHi = max(0, min(rem, rareHi));
        if (rareLo > rareHi) swap(rareLo, rareHi);
        rareCnt = rnd.next(rareLo, rareHi);
    }

    vector<int> rareBits;
    for (int i = 0; i < rareCnt; i++) rareBits.push_back(bits[commonCnt + i]);

    vector<int> patternBits;
    for (int i = commonCnt + rareCnt; i < 63; i++) patternBits.push_back(bits[i]);

    vector<long long> extra(n, 0);

    
    for (int b : rareBits) {
        int pos1 = rnd.next(0, n - 1);
        extra[pos1] |= (1LL << b);
        if (n >= 2 && rnd.next(0, 9) < 3) {
            int pos2 = rnd.next(0, n - 1);
            while (pos2 == pos1) pos2 = rnd.next(0, n - 1);
            extra[pos2] |= (1LL << b);
        }
    }

    
    int usePattern = 0;
    if (!patternBits.empty()) {
        int lo = hard ? 10 : 6;
        int hi = hard ? 16 : 12;
        lo = min(lo, (int)patternBits.size());
        hi = min(hi, (int)patternBits.size());
        if (lo > hi) lo = hi;
        usePattern = (hi == 0 ? 0 : rnd.next(lo, hi));
    }
    for (int t = 0; t < usePattern; t++) {
        int b = patternBits[t];
        int maxP = min(n, hard ? 200 : 80);
        int p = rnd.next(2, maxP);
        int r = rnd.next(0, p - 1);
        for (int i = 0; i < n; i++) {
            int idx = i + 1;
            if (idx % p == r) extra[i] |= (1LL << b);
        }
    }

    
    a.assign(n, 0);
    for (int i = 0; i < n; i++) {
        long long v = commonMask | extra[i];

        int clearMax = hard ? 3 : 2;
        int kclear = rnd.next(0, clearMax);
        for (int t = 0; t < kclear && commonCnt > 0; t++) {
            int b = bits[rnd.next(0, commonCnt - 1)];
            v &= ~(1LL << b);
        }

        int addMax = hard ? 3 : 2;
        int kadd = rnd.next(0, addMax);
        for (int t = 0; t < kadd; t++) {
            int b = bits[rnd.next(0, 62)];
            v |= (1LL << b);
        }

        v &= FULL;
        if (v < 0) v = 0;
        a[i] = v;
    }

    auto pickDistinct = [&](int cnt) -> vector<int> {
        vector<int> chosen;
        vector<char> used(n, 0);
        while ((int)chosen.size() < cnt) {
            int x = rnd.next(0, n - 1);
            if (!used[x]) {
                used[x] = 1;
                chosen.push_back(x);
            }
        }
        return chosen;
    };

    
    vector<int> sp = pickDistinct(min(4, n));
    a[sp[0]] = FULL;
    if ((int)sp.size() >= 2) a[sp[1]] = 0;

    long long alt = 0;
    for (int b = 0; b <= 62; b++) if (b % 2 == 0) alt |= (1LL << b);
    alt &= FULL;
    if ((int)sp.size() >= 3) a[sp[2]] = alt;

    if ((int)sp.size() >= 4) {
        int b = rnd.next(0, 62);
        a[sp[3]] = (FULL ^ (1LL << b)) & FULL;
    }

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