Problem: cf1534_e
Difficulty: easy
Categories: graph
Time limit: 1500 ms, memory limit: 256 MB

This is an interactive problem.

Note: the XOR-sum of an array $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) is defined as $a_1 \oplus a_2 \oplus \ldots \oplus a_n$, where $\oplus$ denotes the bitwise XOR operation.

Little Dormi received an array of $n$ integers $a_1, a_2, \ldots, a_n$ for Christmas. However, while playing with it over the winter break, he accidentally dropped it into his XOR machine, and the array got lost.

The XOR machine is currently configured with a query size of $k$ (which you cannot change), and allows you to perform the following type of query: by giving the machine $k$ distinct indices $x_1, x_2, \ldots, x_k$, it will output $a_{x_1} \oplus a_{x_2} \oplus \ldots \oplus a_{x_k}$.

As Little Dormi's older brother, you would like to help him recover the XOR-sum of his array $a_1, a_2, \ldots, a_n$ by querying the XOR machine.

Little Dormi isn't very patient, so to be as fast as possible, you must query the XOR machine the minimum number of times to find the XOR-sum of his array. Formally, let $d$ be the minimum number of queries needed to find the XOR-sum of any array of length $n$ with a query size of $k$. Your program will be accepted if you find the correct XOR-sum in at most $d$ queries.

Lastly, you also noticed that with certain configurations of the machine $k$ and values of $n$, it may not be possible to recover the XOR-sum of Little Dormi's lost array. If that is the case, you should report it as well.

The array $a_1, a_2, \ldots, a_n$ is fixed before you start querying the XOR machine and does not change with the queries.

Input

The only line of input contains the integers $n$ and $k$ ($1 \le n \le 500$, $1 \le k \le n$), the length of the lost array and the configured query size of the XOR machine.

Elements of the original array satisfy $1 \le a_i \le 10^9$.

It can be proven that that if it is possible to recover the XOR sum under the given constraints, it can be done in at most $500$ queries. That is, $d \le 500$.

After taking $n$ and $k$, begin interaction.

Output

If it is impossible to recover the XOR-sum of the array, output $-1$ immediately after taking $n$ and $k$. Do not begin interaction.

Otherwise, when your program finds the XOR-sum of the lost array $a_1, a_2, \ldots, a_n$, report the answer in the following format: "! x", where $x$ is the XOR sum of the array $a_1, a_2, \ldots, a_n$, and terminate your program normally immediately after flushing the output stream.

Note that answering does not count as a query.

Interaction

Each query is made in the format "? b", where $b$ is an array of exactly $k$ distinct integers from $1$ to $n$ denoting the indices of the elements in the lost array that you want to query the XOR sum of.

You will then receive an integer $x$, the XOR sum of the queried elements. It can be proven that $0 \le x \le 2 \cdot 10^9$ will always be true.

After printing a query do not forget to output 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 documentation for other languages.

If at any point you make an invalid query or try to make more than $500$ queries (which is the hard limit), the interaction will terminate immediately and give you a Wrong Answer verdict. Note that if you exceed $d$ queries, the interaction will continue normally unless you also exceed the $500$ query hard limit, though you will still receive a Wrong Answer verdict either way.

Examples

Input

```
5 3

4

0

1
```

Output

```? 1 2 3? 2 3 5? 4 1 5! 7
```

Input

```
3 2
```

Output

```
-1
```

Note

In the first example interaction, the array $a_1, a_2, \ldots, a_n$ is $2, 1, 7, 5, 6$ and its XOR-sum is $7$.

The first query made asks for indices $1,2,3$, so the response is $a_1 \oplus a_2 \oplus a_3 = 2 \oplus 1 \oplus 7 = 4$.

The second query made asks for indices $2,3,5$, so the response is $a_2 \oplus a_3 \oplus a_5 = 1 \oplus 7 \oplus 6 = 0$.

The third query made asks for indices $4,1,5$, so the response is $a_4 \oplus a_1 \oplus a_5 = 5 \oplus 2 \oplus 6 = 1$. Note that the indices may be output in any order.

Additionally, even though three queries were made in the example interaction, it is just meant to demonstrate the interaction format and does not necessarily represent an optimal strategy.

In the second example interaction, there is no way to recover the XOR-sum of Little Dormi's array no matter what is queried, so the program immediately outputs $-1$ and exits.

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 int compute_min_queries(int n, int k) {
    const int INF = 1e9;
    vector<int> dist(n + 1, INF);
    queue<int> q;
    dist[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        int d = dist[cur];
        int max_take_from_ones = min(cur, k);
        for (int take_from_ones = 0; take_from_ones <= max_take_from_ones; ++take_from_ones) {
            int take_from_zeros = k - take_from_ones;
            if (take_from_zeros > n - cur) continue;
            int nxt = cur + k - 2 * take_from_ones;
            if (nxt < 0 || nxt > n) continue;
            if (dist[nxt] > d + 1) {
                dist[nxt] = d + 1;
                q.push(nxt);
            }
        }
    }
    return dist[n] >= INF ? -1 : dist[n];
}

static void send_minus_one() {
    cout << -1 << "\n";
    cout.flush();
}

static bool read_long_long(long long& out) {
    return static_cast<bool>(cin >> out);
}

static bool parse_long_long_token(const string& token, long long& value) {
    try {
        size_t idx = 0;
        long long v = stoll(token, &idx, 10);
        if (idx != token.size()) return false;
        value = v;
        return true;
    } catch (...) {
        return false;
    }
}

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

    const int n = inf.readInt(1, 500, "n");
    const int k = inf.readInt(1, n, "k");
    vector<int> a(n + 1, 0);
    int xorsum = 0;
    for (int i = 1; i <= n; i++) {
        a[i] = inf.readInt(1, 1000000000, "a[i]");
        xorsum ^= a[i];
    }
    if (!inf.seekEof()) finish(_fail, "Unexpected extra tokens in input");

    const bool solvable = (k % 2 == 1) || (n % 2 == 0);
    const int d = solvable ? compute_min_queries(n, k) : -1;
    if (solvable && (d < 0 || d > 500)) finish(_fail, "Internal: invalid d computed");
    query_limit = solvable ? d : 0;
    const long long hard_limit = 500;

    log_metrics(); 

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

    while (true) {
        string tok;
        if (!(cin >> tok)) finish(_pe, "Unexpected EOF from contestant");

        if (!tok.empty() && tok[0] == '?') {
            if (!solvable) {
                send_minus_one();
                finish(_wa, "Queries are not allowed when the instance is impossible");
            }

            vector<int> idxs(k);
            for (int i = 0; i < k; i++) {
                long long v = 0;
                if (!read_long_long(v)) {
                    send_minus_one();
                    finish(_pe, "Malformed query: expected k indices");
                }
                idxs[i] = (int)v;
            }
            queries++;
            if (queries > hard_limit) {
                send_minus_one();
                finish(_wa, "Query hard limit exceeded (500)");
            }
            vector<char> seen(n + 1, 0);
            int res = 0;
            for (int pos = 0; pos < k; pos++) {
                int id = idxs[pos];
                if (id < 1 || id > n) {
                    send_minus_one();
                    finish(_wa, "Query index out of range");
                }
                if (seen[id]) {
                    send_minus_one();
                    finish(_wa, "Query indices must be distinct");
                }
                seen[id] = 1;
                res ^= a[id];
            }
            cout << res << "\n";
            cout.flush();
            continue;
        }

        long long answer = 0;
        if (tok == "-1") {
            answer = -1;
        } else if (!tok.empty() && tok[0] == '!') {
            if (tok.size() == 1) {
                if (!read_long_long(answer)) finish(_pe, "Malformed final answer: expected integer after '!'");
            } else {
                if (!parse_long_long_token(tok.substr(1), answer)) {
                    finish(_pe, "Malformed final answer token");
                }
            }
        } else {
            finish(_pe, "Unknown operation token (expected '?' or '!')");
        }

        if (answer == -1) {
            if (solvable) finish(_wa, "Reported -1 but the instance is solvable");
            finish(_ok, "Correctly reported impossible");
        }
        if (!solvable) finish(_wa, "Instance is impossible but contestant did not output -1");
        if ((int)answer != xorsum) finish(_wa, "Wrong XOR-sum");
        
        finish(_ok, "OK");
    }
}


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 uint64_t fnv1a64(const string& s) {
    uint64_t h = 14695981039346656037ULL;
    for (unsigned char c : s) {
        h ^= (uint64_t)c;
        h *= 1099511628211ULL;
    }
    return h;
}

static uint64_t splitmix64(uint64_t& x) {
    uint64_t z = (x += 0x9e3779b97f4a7c15ULL);
    z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL;
    z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL;
    return z ^ (z >> 31);
}

static int compute_min_queries(int n, int k) {
    const int INF = 1e9;
    vector<int> dist(n + 1, INF);
    queue<int> q;
    dist[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        int d = dist[cur];
        int max_take_from_ones = min(cur, k);
        for (int take_from_ones = 0; take_from_ones <= max_take_from_ones; ++take_from_ones) {
            int take_from_zeros = k - take_from_ones;
            if (take_from_zeros > n - cur) continue;
            int nxt = cur + k - 2 * take_from_ones;
            if (nxt < 0 || nxt > n) continue;
            if (dist[nxt] > d + 1) {
                dist[nxt] = d + 1;
                q.push(nxt);
            }
        }
    }
    return dist[n] >= INF ? -1 : dist[n];
}

static void send_minus_one() {
    cout << -1 << "\n";
    cout.flush();
}

static bool read_long_long(long long& out) {
    return static_cast<bool>(cin >> out);
}

static bool parse_long_long_token(const string& token, long long& value) {
    try {
        size_t idx = 0;
        long long v = stoll(token, &idx, 10);
        if (idx != token.size()) return false;
        value = v;
        return true;
    } catch (...) {
        return false;
    }
}

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

    const int n = inf.readInt(1, 500, "n");
    const int k = inf.readInt(1, n, "k");
    if (!inf.seekEof()) finish(_fail, "Unexpected extra tokens in adaptive input");

    const bool solvable = (k % 2 == 1) || (n % 2 == 0);
    const int d = solvable ? compute_min_queries(n, k) : -1;
    if (solvable && (d < 0 || d > 500)) finish(_fail, "Internal: invalid d computed");
    query_limit = solvable ? d : 0;
    const long long hard_limit = 500;

    uint64_t seed = fnv1a64((argc >= 2) ? string(argv[1]) : string("cf1534E"));
    seed ^= (uint64_t)n * 0x9e3779b97f4a7c15ULL;
    seed ^= (uint64_t)k * 0xbf58476d1ce4e5b9ULL;
    vector<int> a(n + 1, 0);
    int xorsum = 0;
    for (int i = 1; i <= n; i++) {
        int v = (int)(splitmix64(seed) % 1000000000ULL) + 1; 
        a[i] = v;
        xorsum ^= v;
    }

    log_metrics(); 

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

    while (true) {
        string tok;
        if (!(cin >> tok)) finish(_pe, "Unexpected EOF from contestant");

        if (!tok.empty() && tok[0] == '?') {
            if (!solvable) {
                send_minus_one();
                finish(_wa, "Queries are not allowed when the instance is impossible");
            }

            vector<int> idxs(k);
            for (int i = 0; i < k; i++) {
                long long v = 0;
                if (!read_long_long(v)) {
                    send_minus_one();
                    finish(_pe, "Malformed query: expected k indices");
                }
                idxs[i] = (int)v;
            }
            queries++;
            if (queries > hard_limit) {
                send_minus_one();
                finish(_wa, "Query hard limit exceeded (500)");
            }
            vector<char> seen(n + 1, 0);
            int res = 0;
            for (int pos = 0; pos < k; pos++) {
                int id = idxs[pos];
                if (id < 1 || id > n) {
                    send_minus_one();
                    finish(_wa, "Query index out of range");
                }
                if (seen[id]) {
                    send_minus_one();
                    finish(_wa, "Query indices must be distinct");
                }
                seen[id] = 1;
                res ^= a[id];
            }
            cout << res << "\n";
            cout.flush();
            continue;
        }

        long long answer = 0;
        if (tok == "-1") {
            answer = -1;
        } else if (!tok.empty() && tok[0] == '!') {
            if (tok.size() == 1) {
                if (!read_long_long(answer)) finish(_pe, "Malformed final answer: expected integer after '!'");
            } else {
                if (!parse_long_long_token(tok.substr(1), answer)) {
                    finish(_pe, "Malformed final answer token");
                }
            }
        } else {
            finish(_pe, "Unknown operation token (expected '?' or '!')");
        }

        if (answer == -1) {
            if (solvable) finish(_wa, "Reported -1 but the instance is solvable");
            finish(_ok, "Correctly reported impossible");
        }
        if (!solvable) finish(_wa, "Instance is impossible but contestant did not output -1");
        if ((int)answer != xorsum) finish(_wa, "Wrong XOR-sum");
        
        finish(_ok, "OK");
    }
}



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

static long long readSeed(int argc, char* argv[]) {
    if (argc <= 1) return 1;
    string s = argv[1];
    
    long long x = 1;
    try {
        x = stoll(s);
    } catch (...) {
        x = 1;
    }
    return x;
}

static void shuffleVec(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> genArray(int n, long long seed) {
    vector<int> a(n + 1, 1);

    if (n == 1) {
        a[1] = (seed == 1 ? 1000000000 : rnd.next(1, 1000000000));
        return a;
    }

    vector<int> base = {
        1, 2, 3, 5, 8, 13, 21, 34, 55, 89,
        127, 255, 1023, 4095, 65535,
        (int)((1LL << 28) - 1), (int)(1LL << 28),
        (int)((1LL << 29) - 1), (int)(1LL << 29),
        123456789, 234567891, 345678912, 456789123,
        424242424, 700000000, 777777777, 900000001,
        987654321, 999999937, 1000000000
    };

    shuffleVec(base);

    int m = min(n, (int)base.size());
    for (int i = 1; i <= m; ++i) a[i] = base[i - 1];

    for (int i = m + 1; i <= n; ++i) {
        int t = rnd.next(1, 100);
        if (t <= 8) a[i] = 1000000000;
        else if (t <= 16) a[i] = 1;
        else a[i] = rnd.next(1, 1000000000);
    }

    
    for (int i = 1; i <= n; ++i) {
        if (a[i] < 1) a[i] = 1;
        if (a[i] > 1000000000) a[i] = 1000000000;
    }
    return a;
}

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

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

    ensuref(mode == "non" || mode == "adp", "mode must be 'non' or 'adp'");

    long long seed = readSeed(argc, argv);

    int n = -1, k = -1;

    if (forcedN != -1 || forcedK != -1) {
        if (forcedN == -1) forcedN = min(500, max(1, forcedK));
        if (forcedK == -1) forcedK = min(forcedN, max(1, forcedN - 1));
        n = forcedN;
        k = forcedK;
    } else {
        if (seed == 1) {
            n = 1; k = 1; 
        } else if (seed == 2) {
            n = 3; k = 2; 
        } else if (seed == 3) {
            n = 500; k = 499; 
        } else {
            int pick = rnd.next(1, 100);
            if (pick <= 65) {
                n = 500; k = 499; 
            } else if (pick <= 80) {
                n = rnd.next(470, 500);
                if (n % 2 == 1) --n;
                if (n < 2) n = 2;
                k = n - 1; 
            } else if (pick <= 90) {
                n = rnd.next(3, 499);
                if (n % 2 == 0) ++n;
                if (n > 499) n = 499;
                k = rnd.next(2, n);
                if (k % 2 == 1) ++k;
                if (k > n) --k;
                if (k < 2) k = 2;
                
            } else {
                n = 500; k = 1; 
            }
        }
    }

    ensuref(1 <= n && n <= 500, "n out of range");
    ensuref(1 <= k && k <= n, "k out of range");

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

    
    vector<int> a = genArray(n, seed);
    cout << n << " " << k << "\n";
    for (int i = 1; i <= n; ++i) {
        if (i > 1) cout << ' ';
        cout << a[i];
    }
    cout << "\n";
    return 0;
}