This is an interactive problem.

Little L has a hidden set of size $n$ , $\{ a _ { 1 } , a _ { 2 } , \ldots , a _ { n } \}$ $0 \leq a _ { i } < 2 ^ { 3 0 }$ ), with all elements distinct.

To guess the values of the elements in the set, you can make queries to Little L. In a query, you give a non-negative integer $c$ , and Little $\mathrm { L }$ will tell you $\operatorname* { m a x } \{ a _ { i } \oplus c \}$ , where $\bigoplus$ denotes bitwise XOR $^ \dagger$ .

For example, if $\begin{array} { r l r } { a } & { { } \ = \ } & { \{ 1 , 4 , 6 \} } \end{array}$ and $\begin{array} { r l r } { c } & { { } = } & { 3 } \end{array}$ , Little L will respond 7, because $\operatorname* { m a x } \{ 1 \oplus 3 , 4 \oplus 3 , 6 \oplus 3 \} = \operatorname* { m a x } \{ 2 , 7 , 5 \} = 7$ .

You need to guess all elements of the set using no more than $2 n - 2$ queries.

$^ \dagger$ Bitwise XOR is defined as adding two binary numbers bit by bit modulo 2. For example: $( 0 0 1 1 ) _ { 2 } \oplus$ $( 0 1 0 1 ) _ { 2 } = ( 0 1 1 0 ) _ { 2 }$ .

# Input

Each test file contains multiple test cases. The first line contains the number of test cases $T$ ( $1 \le T \le 1 0 ^ { 4 }$ ).
The description of the test cases follows.

Each test case contains a single line with a positive integer $n$ ( $2 \leq n \leq 1 0 ^ { 5 }$ ), representing the size of the set.

For each test file, it is guaranteed that the sum of $n$ over all test cases does not exceed $1 0 ^ { 5 }$ .

# Interaction Protocol

To make a query, output in the format “? $c "$ ( $0 \leq c < 2 ^ { 3 0 }$ ). After flushing the output, your program should read a single integer from input, which is the value of $\operatorname* { m a x } \{ a _ { i } \oplus c \}$ . For each test case, you can make at most $2 n - 2$ queries. If you exceed this number of queries, the verdict will be undefined.

To guess the set, output in the format “! a1 a2 . . . ${ a _ { n } } ^ { \prime }$ ( $0 \leq a _ { i } < 2 ^ { 3 0 }$ ). The order of elements can be arbitrary. After flushing the output, the interaction for the current test case ends. You should immediately start handling the next test case, or exit if all test cases have been processed.

Note that the interactor is adaptive. This means that the elements in the set are not fixed at the beginning but may be dynamically adjusted based on your queries. The interactor guarantees that adjustments will not invalidate previous responses.

To flush your output, you can use:

• fflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.
• System.out.flush() in Java and Kotlin.
• stdout.flush() in Python.

# Example

standard input	 standard output

1	？0

7號

7	？1

7號	？5

7	？6

	!1267

#include "testlib.h"
#include <bits/stdc++.h>
#include <csignal>
using namespace std;

static long long total_queries = 0;
static long long total_query_limit = 0;

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

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

struct MaxXorTrie {
    vector<array<int, 2>> child;

    explicit MaxXorTrie(int reserve_values = 0) {
        child.reserve((size_t)reserve_values * 31 + 1);
        child.push_back({-1, -1});
    }

    void insert(int x) {
        int node = 0;
        for (int bit = 29; bit >= 0; bit--) {
            int b = (x >> bit) & 1;
            int& nxt = child[node][b];
            if (nxt == -1) {
                nxt = (int)child.size();
                child.push_back({-1, -1});
            }
            node = nxt;
        }
    }

    int max_xor(int c) const {
        int node = 0;
        int res = 0;
        for (int bit = 29; bit >= 0; bit--) {
            int b = (c >> bit) & 1;
            int prefer = b ^ 1;
            int nxt = child[node][prefer];
            if (nxt != -1) {
                res |= (1 << bit);
                node = nxt;
            } else {
                node = child[node][b];
                if (node == -1) break;
            }
        }
        return res;
    }
};

static uint32_t make_seed(int n, int test_idx) {
    uint32_t x = 0x243f6a88u;
    x ^= (uint32_t)n * 0x9e3779b9u;
    x ^= (uint32_t)test_idx * 0x85ebca6bu;
    return x & ((1u << 30) - 1u);
}

int main(int argc, char** argv) {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    registerInteraction(argc, argv);

    atexit(log_metrics);
#ifdef SIGPIPE
    signal(SIGPIPE, SIG_IGN);
#endif

    int T = inf.readInt();
    if (T < 1 || T > 10000) finish(_fail, "invalid T in hidden input");

    cout << T << "\n" << flush;

    for (int t = 1; t <= T; t++) {

        int n_raw = inf.readInt();
        if (n_raw < 2 || n_raw > 100000) finish(_fail, "invalid n in hidden input");
        vector<int> a;
        a.reserve(n_raw);
        for (int i = 0; i < n_raw; i++) {
            int x = inf.readInt();
            if (x < 0 || x >= (1 << 30)) finish(_fail, "a_i out of range");
            a.push_back(x);
        }

        sort(a.begin(), a.end());
        a.erase(unique(a.begin(), a.end()), a.end());
        if ((int)a.size() < n_raw) {
            unordered_set<int> seen;
            seen.reserve((size_t)n_raw * 2);
            for (int x : a) seen.insert(x);

            const uint32_t seed = make_seed(n_raw, t);
            const uint32_t mul = 1103515245u;
            const uint32_t mask = (1u << 30) - 1u;
            for (uint32_t step = 0; (int)a.size() < n_raw; step++) {
                uint32_t val = (seed + (uint64_t)step * mul) & mask;
                int x = (int)val;
                if (seen.insert(x).second) a.push_back(x);
            }
            sort(a.begin(), a.end());
        }

        MaxXorTrie trie(n_raw);
        for (int x : a) trie.insert(x);

        const long long limit_this = 2LL * n_raw - 2;
        total_query_limit += limit_this;
        log_metrics();

        cout << n_raw << "\n" << flush;

        long long queries_in_case = 0;
        while (true) {
            string token;
            if (!(cin >> token)) {
                finish(_pe, "Unexpected EOF while reading token");
            }

            if (token == "!") {

                vector<int> user_ans(n_raw);
                for (int i = 0; i < n_raw; i++) {
                    if (!(cin >> user_ans[i])) {
                        finish(_pe, "Unexpected EOF while reading answer elements");
                    }
                    if (user_ans[i] < 0 || user_ans[i] >= (1 << 30)) {
                        finish(_pe, "Answer value out of range [0,2^30)");
                    }
                }

                sort(user_ans.begin(), user_ans.end());

                if (user_ans == a) {

                    break;
                } else {
                    finish(_wa, "Incorrect set guessed");
                }
            } else {

                long long c = 0;
                if (token == "?") {

                    if (!(cin >> c)) finish(_pe, "Unexpected EOF reading query value");
                } else {

                    try {
                        size_t end_idx;
                        c = stoll(token, &end_idx);
                        if (end_idx != token.size()) finish(_pe, "Trailing garbage in query token");
                    } catch (...) {
                        finish(_pe, "Invalid query token (not a number)");
                    }
                }

                if (c < 0 || c >= (1LL << 30)) {
                    finish(_pe, "Query value out of range [0, 2^30)");
                }

                total_queries++;
                queries_in_case++;
                if (queries_in_case > limit_this) finish(_wa, "Query limit exceeded");
                if (total_queries % 2000 == 0) log_metrics();

                int ans = trie.max_xor((int)c);
                cout << ans << "\n" << flush;
                if (!cout) finish(_pe, "Broken pipe while writing answer");
            }
        }
    }

    finish(_ok, "All cases passed");
    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>
#include <csignal>

using namespace std;

static long long total_queries = 0;
static long long total_query_limit = 0;

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

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

struct MaxXorTrie {
    vector<array<int, 2>> child;

    explicit MaxXorTrie(int reserve_values = 0) {
        child.reserve((size_t)reserve_values * 31 + 1);
        child.push_back({-1, -1});
    }

    void insert(int x) {
        int node = 0;
        for (int bit = 29; bit >= 0; bit--) {
            int b = (x >> bit) & 1;
            int& nxt = child[node][b];
            if (nxt == -1) {
                nxt = (int)child.size();
                child.push_back({-1, -1});
            }
            node = nxt;
        }
    }

    int max_xor(int c) const {
        int node = 0;
        int res = 0;
        for (int bit = 29; bit >= 0; bit--) {
            int b = (c >> bit) & 1;
            int prefer = b ^ 1;
            int nxt = child[node][prefer];
            if (nxt != -1) {
                res |= (1 << bit);
                node = nxt;
            } else {
                node = child[node][b];
                if (node == -1) break;
            }
        }
        return res;
    }
};

static uint32_t make_seed(int n, int test_idx) {
    uint32_t x = 0x243f6a88u;
    x ^= (uint32_t)n * 0x9e3779b9u;
    x ^= (uint32_t)test_idx * 0x85ebca6bu;
    return x & ((1u << 30) - 1u);
}

int main(int argc, char** argv) {
    registerInteraction(argc, argv);
    atexit(log_metrics);
#ifdef SIGPIPE
    signal(SIGPIPE, SIG_IGN);
#endif

    int t = inf.readInt(1, 10000, "t");
    cout << t << "\n" << flush;

    for (int test_case = 1; test_case <= t; test_case++) {
        int n = inf.readInt(2, 100000, "n");

        const long long limit_this = 2LL * n - 2;
        total_query_limit += limit_this;
        log_metrics();

        cout << n << "\n" << flush;

        MaxXorTrie trie(n);
        const uint32_t seed = make_seed(n, test_case);
        const uint32_t mul = 1103515245u;
        const uint32_t mask = (1u << 30) - 1u;
        for (uint32_t i = 0; i < (uint32_t)n; i++) {
            uint32_t val = (seed + (uint64_t)i * mul) & mask;
            trie.insert((int)val);
        }

        vector<pair<int, int>> transcript;
        transcript.reserve((size_t)min<long long>(limit_this, 200000));

        long long queries_in_case = 0;
        while (true) {
            string token;
            if (!(cin >> token)) {
                finish(_pe, "Unexpected end of input from solution");
            }

            if (token == "?") {
                long long c_long;
                if (!(cin >> c_long)) finish(_pe, "Expected integer after '?'");
                if (c_long < 0 || c_long >= (1LL << 30)) finish(_pe, "Query c out of range [0, 2^30)");

                total_queries++;
                queries_in_case++;
                if (queries_in_case > limit_this) finish(_wa, "Query limit exceeded");
                if (total_queries % 2000 == 0) log_metrics();

                const int c = (int)c_long;
                const int ans = trie.max_xor(c);
                transcript.push_back({c, ans});
                cout << ans << "\n" << flush;
                if (!cout) finish(_pe, "Broken pipe while writing answer");

            } else if (token == "!") {
                vector<int> user_set(n);
                for (int i = 0; i < n; i++) {
                    if (!(cin >> user_set[i])) finish(_pe, "EOF while reading answer");
                    if (user_set[i] < 0 || user_set[i] >= (1 << 30)) finish(_pe, "Answer value out of range [0,2^30)");
                }

                sort(user_set.begin(), user_set.end());
                if ((int)user_set.size() != n) finish(_pe, "Invalid answer size");
                for (int i = 1; i < n; i++) {
                    if (user_set[i] == user_set[i - 1]) finish(_wa, "Answer has duplicate elements");
                }

                MaxXorTrie user_trie(n);
                for (int x : user_set) user_trie.insert(x);
                for (auto [c, ans] : transcript) {
                    if (user_trie.max_xor(c) != ans) finish(_wa, "Answer set inconsistent with transcript");
                }

                break;

            } else {

                long long c_long = 0;
                try {
                    size_t end_idx;
                    c_long = stoll(token, &end_idx);
                    if (end_idx != token.size()) finish(_pe, "Trailing garbage in query token");
                } catch (...) {
                    finish(_pe, "Expected '?' or '!' or integer c");
                }
                if (c_long < 0 || c_long >= (1LL << 30)) finish(_pe, "Query c out of range [0, 2^30)");

                total_queries++;
                queries_in_case++;
                if (queries_in_case > limit_this) finish(_wa, "Query limit exceeded");
                if (total_queries % 2000 == 0) log_metrics();

                const int c = (int)c_long;
                const int ans = trie.max_xor(c);
                transcript.push_back({c, ans});
                cout << ans << "\n" << flush;
                if (!cout) finish(_pe, "Broken pipe while writing answer");
            }
        }
    }

    finish(_ok, "All cases passed");
    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> generateSet(int n, int type) {
    vector<int> a;

    int MAX_VAL = 1073741823;

    if (type == 0) {

        a = rnd.distinct(n, 0, MAX_VAL);
    }
    else if (type == 1) {

        int limit = min((long long)MAX_VAL, (long long)n * 4);
        a = rnd.distinct(n, 0, limit);
    }
    else if (type == 2) {

        int max_start = MAX_VAL - n;
        int start = rnd.next(0, max_start);
        for (int i = 0; i < n; i++) a.push_back(start + i);
        shuffle(a.begin(), a.end());
    }
    else if (type == 3) {

        int min_bits = 0;
        while ((1 << min_bits) < n) min_bits++;

        int low_bits = rnd.next(min_bits, 29);
        int high_bits = 30 - low_bits;

        int prefix = rnd.next(0, (1 << high_bits) - 1) << low_bits;
        int max_low = (1 << low_bits) - 1;

        if (max_low + 1 >= n) {
            vector<int> low = rnd.distinct(n, 0, max_low);
            for (int x : low) a.push_back(prefix | x);
        } else {

            a = rnd.distinct(n, 0, MAX_VAL);
        }
    }
    else {

        set<int> s;
        while ((int)s.size() < n) {
            int x = 0;

            int bits = rnd.next(1, 10);
            for (int k = 0; k < bits; k++) {
                x |= (1 << rnd.next(30));
            }
            if (s.find(x) == s.end()) {
                s.insert(x);
                a.push_back(x);
            }
        }

        for (auto x : s) a.push_back(x);
    }

    shuffle(a.begin(), a.end());
    return a;
}

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

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

    long long seed_val = 0;
    try {
        seed_val = stoll(argv[1]);
    } catch (...) {
        seed_val = -1;
    }

    int t;
    vector<int> ns;
    int max_sum_n = 100000;

    if (seed_val == 1) {

        t = 1;
        ns = {2};
    } else if (seed_val == 2) {

        t = 1;
        ns = {100000};
    } else if (seed_val == 3) {

        t = 10000;
        ns.assign(t, 2);
    } else {

        int current_sum = rnd.next(100, max_sum_n);

        int limit_t = min(10000, current_sum / 2);

        if (rnd.next(2) == 0) {

            t = rnd.next(1, min(limit_t, 20));
        } else {

            t = rnd.next(1, limit_t);
        }

        ns = rnd.partition(t, current_sum, 2);
    }

    cout << t << endl;

    for (int i = 0; i < t; i++) {
        int n = ns[i];
        cout << n << endl;

        if (mode == "non") {

            int type;
            if (seed_val == 1) type = 1;
            else if (seed_val == 2) type = 0;
            else if (seed_val > 0 && seed_val <= 10) {

                type = rnd.next(0, 4);
            } else {

                type = rnd.next(0, 4);
            }

            vector<int> a = generateSet(n, type);
            for (int k = 0; k < n; k++) {
                cout << a[k] << (k == n - 1 ? "" : " ");
            }
            cout << endl;
        }

    }

    return 0;
}


This is an interactive problem.

Anya has gathered $n$ chess experts numbered from $1$ to $n$ for which the following properties hold:

* For any pair of players one of the players wins every game against the other (and no draws ever occur);
* Transitivity does not necessarily hold — it might happen that $A$ always beats $B$, $B$ always beats $C$ and $C$ always beats $A$.

Anya does not know, for each pair, who is the player who beats the other.

To organize a tournament, Anya hosts $n-1$ games. In each game, she chooses two players. One of them wins and stays, while the other one is disqualified. After all the games are hosted only one player will remain. A player is said to be a candidate master if they can win a tournament (notice that the winner of a tournament may depend on the players selected by Anya in the $n-1$ games).

Since Anya is a curious girl, she is interested in finding the candidate masters. Unfortunately, she does not have much time. To speed up the process, she will organize up to $2n$ simuls (short for "simultaneous exhibition", in which one player plays against many).

In one simul, Anya chooses exactly one player who will play against some (at least one) of the other players. The chosen player wins all games they would win in a regular game, and the same holds for losses. After the simul finishes, Anya is only told the total number of games won by the chosen player (but not which ones). Nobody is disqualified during a simul.

Can you help Anya host simuls and determine the candidate masters?

The winning players in each pair could be changed between the simuls, but only in a way that preserves the results of all previous simuls. These changes may depend on your queries.

Interaction

Firstly, the jury sends one integer $n$ ($3 \leq n \leq 250$) which should be read — the number of players. After that, your program may ask queries or report an answer.

To ask a query, print "? $i \; s_1 s_2 \ldots s_n$" (without quotes), where $i$ is the index of the player who will play against some of the other players in the simul. $s$ is a binary string that denotes the players they play against. $i$ plays against every player $j$ for which $s_j = 1$ holds (and $s_j = 1$ should hold for at least one $1 \leq j \leq n$). Please note that $s_i = 0$ must hold since a player cannot play against themselves, otherwise, the query is considered to be incorrect.

After this, you should read an integer — the number of games player $i$ has won.

When you have identified the answer, you must print "! $c_1 c_2 \ldots c_n$" (without quotes) and terminate your program. $c$ is a binary string which represents the candidate masters. Player $i$ is a candidate master if $c_i=1$ holds, otherwise, they are not.

If you ask more than $2n$ queries or if one of the queries is malformed, the interaction terminates immediately and your program receives verdict 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.

Examples

Input

```
3

1

1

1
```

Output

```
? 1 010

? 2 001

? 3 100

! 111
```

Input

```
5

0

3

4
```

Output

```
? 5 10110

? 2 10111

? 1 01111

! 10000
```

Note

In the first example, the first query describes a simul in which player $1$ plays against player $2$ (and no one else). The answer to the query is $1$, meaning that player $1$ won the only game they played. We can conclude that $1$ beats $2$. Similarly, the second query tells us that $2$ beats $3$ and the third query tells us that $3$ beats $1$. All players are candidate masters in this case as

* Player $1$ can win the tournament if $2$ and $3$ play first. $3$ loses and leaves, while $2$ stays. $1$ then plays against $2$ and wins;
* Other players can win in the same fashion.

In the second example, the third query describes a simul in which player $1$ plays against every other player. The answer to the query is $4$, meaning that they won every game they played. It can be concluded that player $1$ also beats every other player. They can never lose, hence they are the only player who can remain at the end of every possible tournament, and the only possible candidate master.

#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 << 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 main(int argc, char** argv) {

    registerInteraction(argc, argv);
    atexit(log_metrics);

    int n = inf.readInt();
    query_limit = 2LL * n;

    log_metrics();

    vector<string> adj(n);
    for (int i = 0; i < n; ++i) {
        adj[i] = inf.readToken();
    }

    vector<bool> vis(n, false);
    vector<int> order;
    function<void(int)> dfs1 = [&](int u) {
        vis[u] = true;
        for (int v = 0; v < n; ++v) {
            if (adj[u][v] == '1' && !vis[v]) {
                dfs1(v);
            }
        }
        order.push_back(u);
    };

    for (int i = 0; i < n; ++i) {
        if (!vis[i]) dfs1(i);
    }

    fill(vis.begin(), vis.end(), false);
    vector<int> component;
    function<void(int)> dfs2 = [&](int u) {
        vis[u] = true;
        component.push_back(u);
        for (int v = 0; v < n; ++v) {

            if (adj[v][u] == '1' && !vis[v]) {
                dfs2(v);
            }
        }
    };

    if (!order.empty()) {
        dfs2(order.back());
    }

    string expected_ans(n, '0');
    for (int u : component) {
        expected_ans[u] = '1';
    }

    cout << n << endl;

    int hard_cap = max(20000, 10 * (int)query_limit);

    while (true) {
        if (queries > hard_cap) {
            finish(_pe, "Hard query limit exceeded (infinite loop protection)");
        }

        string token;
        if (!(cin >> token)) {
            finish(_wa, "Unexpected EOF (expected '?' or '!')");
        }

        if (token == "!") {

            string ans;
            if (!(cin >> ans)) {
                finish(_wa, "Unexpected EOF reading answer string");
            }

            if (ans.length() != n) {
                finish(_wa, format("Answer length mismatch: expected %d, got %d", n, (int)ans.length()));
            }
            for (char c : ans) {
                if (c != '0' && c != '1') {
                    finish(_wa, "Answer string must contain only '0' and '1'");
                }
            }

            if (ans == expected_ans) {
                finish(_ok, "Correct answer");
            } else {
                finish(_wa, format("Incorrect answer. Expected: %s, Got: %s", expected_ans.c_str(), ans.c_str()));
            }

        } else {

            int u_idx = -1;
            string s;

            if (token == "?") {
                if (!(cin >> u_idx >> s)) {
                    finish(_wa, "Unexpected EOF reading query parameters");
                }
            } else {
                try {
                    u_idx = stoi(token);
                } catch (...) {
                    finish(_wa, "Invalid token (expected '?' or integer index)");
                }
                if (!(cin >> s)) {
                    finish(_wa, "Unexpected EOF reading query string");
                }
            }

            queries++;

            if (queries % 10 == 0) log_metrics();

            if (u_idx < 1 || u_idx > n) {
                finish(_wa, format("Player index %d out of bounds [1, %d]", u_idx, n));
            }
            if (s.length() != n) {
                finish(_wa, format("Query string length %d != %d", (int)s.length(), n));
            }

            bool self_play = false;
            bool non_empty = false;
            for (int j = 0; j < n; ++j) {
                if (s[j] == '1') {
                    non_empty = true;
                    if (j == u_idx - 1) self_play = true;
                } else if (s[j] != '0') {
                    finish(_wa, "Query string contains invalid characters (must be '0' or '1')");
                }
            }

            if (self_play) {
                finish(_wa, format("Player %d cannot play against themselves", u_idx));
            }
            if (!non_empty) {
                finish(_wa, "Player must play against at least one opponent");
            }

            int wins = 0;
            int u = u_idx - 1;
            for (int v = 0; v < n; ++v) {
                if (s[v] == '1' && adj[u][v] == '1') {
                    wins++;
                }
            }

            cout << wins << endl;
        }
    }

    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

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

static const long long HARD_CAP = 50000;

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 main(int argc, char** argv) {

    registerInteraction(argc, argv);

    atexit(log_metrics);

    int n = inf.readInt();

    vector<string> adj(n);
    for (int i = 0; i < n; i++) {
        adj[i] = inf.readToken();

        if ((int)adj[i].length() != n) {
            quitf(_fail, "Invalid adjacency matrix in input file: row length != n");
        }
    }

    query_limit = 2LL * n;

    cout << n << endl;

    log_metrics();

    vector<vector<bool>> R(n, vector<bool>(n, false));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {

            if (i == j || adj[i][j] == '1') {
                R[i][j] = true;
            }
        }
    }

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            if (R[i][k]) {
                for (int j = 0; j < n; j++) {
                    if (R[k][j]) {
                        R[i][j] = true;
                    }
                }
            }
        }
    }

    string expected_ans = "";
    for (int i = 0; i < n; i++) {
        bool wins_tournament = true;
        for (int j = 0; j < n; j++) {
            if (!R[i][j]) {
                wins_tournament = false;
                break;
            }
        }
        expected_ans += (wins_tournament ? '1' : '0');
    }

    while (true) {

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

        string type;
        if (!(cin >> type)) {

            finish(_pe, "Unexpected EOF while waiting for query/answer");
        }

        if (type == "!") {

            string ans;
            if (!(cin >> ans)) {
                finish(_pe, "Unexpected EOF reading answer string");
            }

            if (ans != expected_ans) {
                finish(_wa, format("Wrong Answer. Expected: %s, Found: %s", expected_ans.c_str(), ans.c_str()));
            } else {
                finish(_ok, "Correct candidate masters identified");
            }

        } else if (type == "?") {

            int i;
            string s;
            if (!(cin >> i >> s)) {
                finish(_pe, "Malformatted query arguments");
            }

            if (i < 1 || i > n) {
                finish(_wa, format("Player index %d out of range [1, %d]", i, n));
            }
            if ((int)s.length() != n) {
                finish(_wa, format("Query string length %d does not match n=%d", (int)s.length(), n));
            }

            bool has_opponent = false;
            for (char c : s) {
                if (c != '0' && c != '1') {
                    finish(_wa, "Query string must contain only '0' and '1'");
                }
                if (c == '1') has_opponent = true;
            }

            if (s[i-1] != '0') {
                finish(_wa, format("Player %d cannot play against themselves", i));
            }

            if (!has_opponent) {
                finish(_wa, "Simul must involve at least one opponent");
            }

            int wins = 0;
            int u = i - 1;
            for (int v = 0; v < n; v++) {
                if (s[v] == '1') {

                    if (adj[u][v] == '1') {
                        wins++;
                    }
                }
            }

            queries++;

            cout << wins << endl;

            if (queries % 50 == 0) {
                log_metrics();
            }

        } else {
            finish(_pe, "Unknown query token: " + type);
        }
    }

    return 0;
}

#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");

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

    int n;
    int type = 0;

    if (seed_idx == 1) { n = 3; type = 1; }
    else if (seed_idx == 2) { n = 3; type = 2; }
    else if (seed_idx == 3) { n = 250; type = 1; }
    else if (seed_idx == 4) { n = 250; type = 2; }
    else if (seed_idx == 5) { n = 250; type = 3; }
    else if (seed_idx == 6) { n = 250; type = 4; }
    else {

        n = rnd.next(3, 250);
        type = 0;
    }

    if (opt<int>("n", 0) != 0) n = opt<int>("n");

    vector<int> scc_sizes;
    if (type == 1) {
        scc_sizes = {n};
    } else if (type == 2) {
        scc_sizes.assign(n, 1);
    } else if (type == 3) {
        scc_sizes = {1, n - 1};
    } else if (type == 4) {
        scc_sizes = {n - 1, 1};
    } else {

        int m;
        int r = rnd.next(100);
        if (r < 10) m = 1;
        else if (r < 20) m = n;
        else m = rnd.next(1, n);

        scc_sizes = rnd.partition(m, n, 1);
    }

    vector<int> p = rnd.perm(n);
    vector<int> node_to_scc(n);
    vector<vector<int>> sccs(scc_sizes.size());

    int current_idx = 0;
    for (int i = 0; i < (int)scc_sizes.size(); i++) {
        for (int k = 0; k < scc_sizes[i]; k++) {
            int u = p[current_idx++];
            node_to_scc[u] = i;
            sccs[i].push_back(u);
        }
    }

    vector<string> adj(n, string(n, '0'));

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            if (node_to_scc[i] < node_to_scc[j]) {
                adj[i][j] = '1';
                adj[j][i] = '0';
            }
        }
    }

    for (const auto& nodes : sccs) {
        int sz = nodes.size();
        if (sz < 2) continue;

        for (int i = 0; i < sz; i++) {
            int u = nodes[i];
            int v = nodes[(i + 1) % sz];
            adj[u][v] = '1';
            adj[v][u] = '0';
        }

        for (int i = 0; i < sz; i++) {
            for (int j = i + 1; j < sz; j++) {
                int u = nodes[i];
                int v = nodes[j];

                if (adj[u][v] == '0' && adj[v][u] == '0') {
                    if (rnd.next(2)) {
                        adj[u][v] = '1';
                        adj[v][u] = '0';
                    } else {
                        adj[u][v] = '0';
                        adj[v][u] = '1';
                    }
                }
            }
        }
    }

    cout << n << "\n";
    for (int i = 0; i < n; i++) {
        cout << adj[i] << "\n";
    }

    return 0;
}


This is an interactive problem.

After emigrating to another country, little Hanna came across the fact that playing "Hot and cold" became more difficult: she does not understand the hint phrases! You are to write a helping program for her.

The playground where the game happens is a rectangle, and the treasure is hidden in some point with integer coordinates between 0 and $10^6$, inclusive. Hanna visits several points with valid coordinates. If the visited point contains the hidden treasure, she receives the phrase "Found!" in the local language. Fortunately, the intonations allow her to recognize this phrase — in this problem it will be denoted by an exclamation mark.

Otherwise, for each visited point except for the first one, Hanna receives a phrase in the local language stating whether she is now "Closer", "Further", or "At the same distance" from the treasure, compared to the previous point. The distances are measured in Euclidean metric. After the first visited point, in case of no treasure there, Hanna receives the phrase "Not found" in the local language.

Your program must help Hanna find the treasure by visiting at most 64 points.

Interaction

Your program should print each visited point in a line with two coordinates between 0 and $10^6$, inclusive, and flush the output after each one.

For each visited point, the testing system writes one of the phrases: "Found!", "Closer", "Further", "At the same distance", or "Not found" in some language, consistent throughout the game. The first phrase ends with an exclamation mark, all other phrases do not contain exclamation marks. All phrases contain only Latin letters, spaces and exclamation marks, have lengths between 2 and 30, inclusive, don't start or end with a space, and are pairwise distinct. The phrases are not necessarily coming from any real human language.

After receiving a phrase with an exclamation mark, your program must halt without printing anything else. Visiting points more than once is allowed, and each such visit counts towards the limit of 64 queries.

Examples

Input

```
Tabilmadi

Daha yakin

Daha yakin

Sama distanco

Dalej

Znaydeno!
```

Output

```
500 200

560 230

566 240

566 238

30 239

566 239
```

Input

```
You are lucky today!
```

Output

```
777777 777777
```

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

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

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 main(int argc, char** argv) {
    registerInteraction(argc, argv);
    atexit(log_metrics);

    long long target_x = inf.readInt();
    long long target_y = inf.readInt();
    inf.readLine();

    string p_found = inf.readLine();
    string p_closer = inf.readLine();
    string p_further = inf.readLine();
    string p_same = inf.readLine();
    string p_not_found = inf.readLine();

    if (p_found.empty() || p_closer.empty()) {
        finish(_fail, "Invalid hidden input: failed to read phrases");
    }

    long long prev_dist_sq = -1;
    long long hard_cap = 2000;

    while (true) {

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

        string token;
        cin >> token;

        if (cin.eof() || cin.fail()) {
            finish(_wa, "Unexpected EOF (did not find treasure)");
        }

        long long x = -1, y = -1;
        try {

            if (token == "?" || token == "!") {

                if (!(cin >> token)) {
                    finish(_wa, "Expected X coordinate after prefix");
                }
            }

            size_t idx = 0;
            x = stoll(token, &idx);
            if (idx != token.size()) finish(_wa, "Invalid format for X coordinate");

            string token_y;
            if (!(cin >> token_y)) finish(_wa, "Expected Y coordinate");
            y = stoll(token_y, &idx);
            if (idx != token_y.size()) finish(_wa, "Invalid format for Y coordinate");

        } catch (...) {
            finish(_wa, "Failed to parse coordinates");
        }

        queries++;

        if (queries % 10 == 0) log_metrics();

        if (x < 0 || x > 1000000 || y < 0 || y > 1000000) {
            finish(_wa, "Coordinates out of bounds [0, 1000000]");
        }

        if (x == target_x && y == target_y) {
            cout << p_found << endl;
            finish(_ok, "Found treasure!");
        }

        long long curr_dist_sq = (x - target_x) * (x - target_x) + (y - target_y) * (y - target_y);

        if (queries == 1) {
            cout << p_not_found << endl;
        } else {
            if (curr_dist_sq < prev_dist_sq) {
                cout << p_closer << endl;
            } else if (curr_dist_sq > prev_dist_sq) {
                cout << p_further << endl;
            } else {
                cout << p_same << endl;
            }
        }

        prev_dist_sq = curr_dist_sq;
    }

    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long queries = 0;
static const long long query_limit = 64;

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

struct Point {
    double x, y;
};
typedef vector<Point> Polygon;

struct PointInt {
    long long x, y;
    bool operator<(const PointInt& other) const {
        if (x != other.x) return x < other.x;
        return y < other.y;
    }
    bool operator==(const PointInt& other) const {
        return x == other.x && y == other.y;
    }
};

Polygon poly;
vector<PointInt> candidates;
bool phase2 = false;
PointInt last_p = {-1, -1};
bool first_query = true;

string s_found, s_closer, s_further, s_same, s_notfound;

double get_area(const Polygon& p) {
    double area = 0.0;
    if (p.size() < 3) return 0.0;
    for (size_t i = 0; i < p.size(); ++i) {
        size_t j = (i + 1) % p.size();
        area += (p[i].x * p[j].y - p[j].x * p[i].y);
    }
    return abs(area) / 2.0;
}

Polygon clip(const Polygon& poly, double a, double b, double c) {
    Polygon new_poly;
    if (poly.empty()) return new_poly;

    for (size_t i = 0; i < poly.size(); ++i) {
        Point p1 = poly[i];
        Point p2 = poly[(i + 1) % poly.size()];

        double v1 = a * p1.x + b * p1.y + c;
        double v2 = a * p2.x + b * p2.y + c;

        if (v1 <= 1e-9) {
            new_poly.push_back(p1);
        }

        if ((v1 > 1e-9 && v2 < -1e-9) || (v1 < -1e-9 && v2 > 1e-9) ||
            (v1 > 1e-9 && v2 <= 1e-9) || (v1 <= 1e-9 && v2 > 1e-9)) {

            double num = -c - a * p1.x - b * p1.y;
            double den = a * (p2.x - p1.x) + b * (p2.y - p1.y);
            if (abs(den) > 1e-12) {
                double t = num / den;
                new_poly.push_back({p1.x + t * (p2.x - p1.x), p1.y + t * (p2.y - p1.y)});
            }
        }
    }
    return new_poly;
}

void switch_to_phase2() {
    if (phase2) return;

    double min_x = 1e18, max_x = -1e18, min_y = 1e18, max_y = -1e18;
    for (auto& p : poly) {
        min_x = min(min_x, p.x); max_x = max(max_x, p.x);
        min_y = min(min_y, p.y); max_y = max(max_y, p.y);
    }

    long long lx = max(0LL, (long long)floor(min_x - 1e-7));
    long long rx = min(1000000LL, (long long)ceil(max_x + 1e-7));
    long long ly = max(0LL, (long long)floor(min_y - 1e-7));
    long long ry = min(1000000LL, (long long)ceil(max_y + 1e-7));

    candidates.clear();

    for (long long x = lx; x <= rx; ++x) {
        for (long long y = ly; y <= ry; ++y) {
            bool inside = true;
            for (size_t i = 0; i < poly.size(); ++i) {
                Point p1 = poly[i];
                Point p2 = poly[(i + 1) % poly.size()];

                double cp = (p2.x - p1.x) * (y - p1.y) - (p2.y - p1.y) * (x - p1.x);
                if (cp < -1e-7) {
                    inside = false;
                    break;
                }
            }
            if (inside) {
                candidates.push_back({x, y});
            }
        }
    }
    phase2 = true;
}

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

    inf.readInt(); inf.readInt();
    inf.readLine();

    s_found = inf.readLine();
    s_closer = inf.readLine();
    s_further = inf.readLine();
    s_same = inf.readLine();
    s_notfound = inf.readLine();

    poly = {{0, 0}, {1000000, 0}, {1000000, 1000000}, {0, 1000000}};

    log_metrics();

    while (true) {

        if (queries > 200) {
            finish(_pe, "Too many queries (hard cap)");
        }

        if (cin.eof()) break;
        string token;
        cin >> token;
        if (cin.fail()) break;

        long long x, y;
        try {
            x = stoll(token);
            cin >> y;
        } catch (...) {
            finish(_pe, "Invalid coordinate format");
        }

        if (x < 0 || x > 1000000 || y < 0 || y > 1000000) {
            finish(_pe, "Coordinates out of range");
        }

        queries++;
        PointInt curr_p = {x, y};
        string reply = "";

        if (!phase2) {
            double min_x = 1e18, max_x = -1e18, min_y = 1e18, max_y = -1e18;
            for (auto& p : poly) {
                min_x = min(min_x, p.x); max_x = max(max_x, p.x);
                min_y = min(min_y, p.y); max_y = max(max_y, p.y);
            }
            double box_area = (max_x - min_x) * (max_y - min_y);

            if (box_area < 5000.0) {
                switch_to_phase2();
            }
        }

        if (first_query) {
            reply = s_notfound;
            first_query = false;

            if (phase2) {
                vector<PointInt> next_c;
                for (auto& p : candidates) {
                    if (p.x == curr_p.x && p.y == curr_p.y) continue;
                    next_c.push_back(p);
                }
                candidates = next_c;
                if (candidates.empty()) finish(_wa, "Inconsistent state (first query exhausted all points)");
            }
        } else {

            long long A = 2LL * (last_p.x - curr_p.x);
            long long B = 2LL * (last_p.y - curr_p.y);
            long long C_val = (curr_p.x * curr_p.x + curr_p.y * curr_p.y) - (last_p.x * last_p.x + last_p.y * last_p.y);

            if (!phase2) {

                Polygon poly_closer = clip(poly, A, B, C_val);
                Polygon poly_further = clip(poly, -A, -B, -C_val);

                double area_closer = get_area(poly_closer);
                double area_further = get_area(poly_further);

                if (area_closer >= area_further) {
                    poly = poly_closer;
                    reply = s_closer;
                } else {
                    poly = poly_further;
                    reply = s_further;
                }
            } else {

                vector<PointInt> set_c, set_f, set_s;
                bool curr_is_candidate = false;

                for (auto& p : candidates) {
                    if (p == curr_p) {
                        curr_is_candidate = true;
                        continue;
                    }
                    long long val = A * p.x + B * p.y + C_val;
                    if (val < 0) set_c.push_back(p);
                    else if (val > 0) set_f.push_back(p);
                    else set_s.push_back(p);
                }

                size_t sc = set_c.size();
                size_t sf = set_f.size();
                size_t ss = set_s.size();

                if (sc == 0 && sf == 0 && ss == 0) {
                    if (curr_is_candidate) {
                        reply = s_found;
                    } else {
                        finish(_wa, "Inconsistent state: no candidates left");
                    }
                } else {

                    if (sc >= sf && sc >= ss) {
                        candidates = set_c;
                        reply = s_closer;
                    } else if (sf >= sc && sf >= ss) {
                        candidates = set_f;
                        reply = s_further;
                    } else {
                        candidates = set_s;
                        reply = s_same;
                    }
                }
            }
        }

        last_p = curr_p;
        cout << reply << endl;

        log_metrics();

        if (!reply.empty() && reply.back() == '!') {
            finish(_ok, "Contestant found the treasure");
        }
    }

    finish(_wa, "Stream ended without Found!");
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

string gen_phrase(bool is_found) {
    string res = "";
    int type = rnd.next(0, 2);

    if (type == 0) {

        int len = rnd.next(2, is_found ? 29 : 30);
        for (int i = 0; i < len; ++i) {
            int t = rnd.next(0, 52);
            if (t < 26) res += (char)('a' + t);
            else if (t < 52) res += (char)('A' + (t - 26));
            else res += ' ';
        }
    }

    else if (type == 1) {
        int words = rnd.next(1, 3);
        for(int w = 0; w < words; ++w) {
            if(w > 0) res += " ";
            int wlen = rnd.next(1, 8);
            for(int i = 0; i < wlen; ++i) {
                res += (char)(rnd.next(0, 1) ? rnd.next('a', 'z') : rnd.next('A', 'Z'));
            }
        }
    }

    else {
        static const vector<string> bases = {
            "Yes", "No", "Warm", "Cold", "Maybe", "Far", "Near",
            "Left", "Right", "Stop", "Go", "Same", "Bingo", "Ops",
            "Closer", "Further", "Found", "Distance", "Try", "Again"
        };
        res = bases[rnd.next(0, (int)bases.size() - 1)];

        if (rnd.next(0, 2) == 0) {
            res += " ";
            res += (char)('a' + rnd.next(0, 25));
        }
    }

    while (!res.empty() && res.front() == ' ') res.erase(res.begin());
    while (!res.empty() && res.back() == ' ') res.pop_back();

    for (char &c : res) if (c == '!') c = 'i';

    int max_len = is_found ? 29 : 30;
    int min_len = is_found ? 1 : 2;

    if ((int)res.length() > max_len) res.resize(max_len);
    while ((int)res.length() < min_len) {
        res += (char)('a' + rnd.next(0, 25));
    }

    if (is_found) {
        res += '!';
    }

    return res;
}

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

    string mode = opt<string>("mode", "non");
    long long seed_val = 0;
    try {
        if (argc > 1) seed_val = stoll(string(argv[1]));
    } catch (...) {}

    int N = 1000000;
    int x, y;

    if (mode == "non" && seed_val >= 1 && seed_val <= 5) {
        if (seed_val == 1) { x = 0; y = 0; }
        else if (seed_val == 2) { x = N; y = N; }
        else if (seed_val == 3) { x = 0; y = N; }
        else if (seed_val == 4) { x = N; y = 0; }
        else { x = N / 2; y = N / 2; }
    } else {

        x = rnd.next(0, N);
        y = rnd.next(0, N);
    }

    println(x, y);

    vector<string> phrases;
    set<string> seen;

    while (true) {
        string s = gen_phrase(true);
        if (seen.find(s) == seen.end()) {
            phrases.push_back(s);
            seen.insert(s);
            break;
        }
    }

    for (int i = 0; i < 4; ++i) {
        while (true) {
            string s = gen_phrase(false);
            if (seen.find(s) == seen.end()) {
                phrases.push_back(s);
                seen.insert(s);
                break;
            }
        }
    }

    for (const string &s : phrases) {
        println(s);
    }

    return 0;
}


This is an interactive problem.

Harry and Hermione are trying to hunt down hoglins which are haunting Hogwarts. There is a long hallway in Hogwarts, consisting of $n$ individual cells, numbered from 1 to $n$ from the left to the right.

Hermione can cast a spell that would block any cell of the hallway of her choosing. After the spell is cast, the blocked cell will remain blocked while she casts other spells.

Hoglins are simple creatures; all they do is randomly move around and bump into stuff. To be more precise, every hoglin has a range which it considers to be accessible. Initially, when the hoglin appears, it is a range from the cell 1 to the cell $n$ .

Initially, a single hoglin appears in a cell of the hallway chosen uniformly at random. Then, until this hoglin is caught, the following happens on every round of the hunt:

• Hermione can cast a spell to block any single cell of her choosing, or do nothing.
• If the cell she is trying to block is the cell with a hoglin in it, the hoglin is caught. After that, all the blocked cells become free again, and, if there are more hoglins to be caught, a new hoglin immediately appears in a random location, and the hunt begins again.
• Otherwise, the hoglin chooses a cell uniformly at random from its accessible range and tries to move to that cell, moving one cell at a time towards a chosen cell. Regardless of the distance, all the steps of the movement, as described below, happen in the same round.
• If the chosen cell is to the right of the hoglin, it moves to the right; if the chosen cell is to the left of the hoglin, it moves to the left. If the chosen cell is the same as where the hoglin is now, it does nothing.
• If at any point during the movement towards the chosen cell a hoglin is trying to move to the right or to the left from an unblocked cell at position $i$ to the neighbouring blocked cell at position $i \pm 1$ , the hoglin updates the right or left boundary of its accessible range correspondingly to be $i$ .
• If on the way to the chosen cell, the hoglin tries to move to a blocked cell, Harry and Hermione hear a loud sound, as the hoglin bumps into the blocked cell. In this case, the hoglin returns to the position it has originally started from at the beginning of this round.
• Otherwise, if the hoglin does not bump into any blocked cells on its way, it does not change its accessible range and stays at the new position. In that case, Harry and Hermione hear nothing.

To free Hogwarts from hoglins, Harry and Hermione should catch $k$ of them, but they don’t have much time. They can only afford to hunt hoglins for at most 200 000 rounds. Please help them find an efficient strategy to do that.

# Interaction Protocol

First, the testing system will write two integers $n$ and $k$ ( $1 \leq n \leq 1 0 ^ { 1 8 } ; 1 \leq k \leq 8 0 0 _ { \cdot }$ ) — the number of cells in Hogwarts’ hallway and the number of hoglins that should be caught. Then the catching process begins.

The following interaction proceeds in rounds as described in the problem statement.

At the start of each round, your program should output Hermione’s action — an integer $p$ ( $0 \leq p \leq n$ ) representing the position of the cell Hermione is going to block. If $p = 0$ or the cell at position $p$ is already blocked, she does nothing in this round.

Then, if the current position of the hoglin is at the newly blocked cell $p$ , the hoglin is caught; the testing system outputs 2, all the blocked cells become free, and interaction rounds start again. In case you caught the $k$ -th hoglin, the testing system outputs 3 instead of 2, and your program should immediately stop execution.

Otherwise, the hoglin attempts to move according to the rules described in the problem statement. If in the process it bumps into any blocked cell, the testing system outputs 1; otherwise, it outputs 0.

If your 200 000-th action does not catch the $k$ -th hoglin, the testing system outputs -1 instead of its usual answer, and your program should immediately stop execution to guarantee the “Wrong Answer” verdict.

The interactor in this problem is not adaptive. It is guaranteed that the hoglins follow the rules described in the problem statement. The starting cell for each hoglin is chosen uniformly at random and their moves are chosen uniformly at random from the range of cells that they consider accessible.

The problem has at most 15 tests.

Here is the summary of all possible interactor answers:

• -1 — too many actions;
• 0 — hoglin moved successfully, did not bump;
• 1 — hoglin attempted to move, bumped into blocked cell;
• 2 — hoglin is caught, interaction starts again;
• 3 — hoglin is caught, stop.

# Example

standard input	standard output	Illustration

92 3				123456789

								start at 8

7									block 3

							move to 4, success

							block 7

5							move to 9, bumped

							block 5

							move to 3,bumped

1 0 9								block 1

1									move to 4, success

						block 9

4								move to 5, bumped

2									block 4, caught

							start at 3

5 7								block 5

1 0									move to 9,bumped

							block 7

0								move to 1, success

0									do nothing

							move to 2, success

2	block 2,caught

# Note

We show the sample from the point of view of the hoglins.

The black dot shows the current position of the hoglin.

Crosses mark blocked cells.

White cells mark the range which the hoglin considers to be accessible; other cells are marked gray.

On the right is the action that was performed by either Hermione or the hoglin to get to this state from the previous one.

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

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

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 main(int argc, char** argv) {

    registerInteraction(argc, argv);

    atexit(log_metrics);

    long long n = inf.readLong();
    int k = inf.readInt();
    long long seed = inf.readLong();

    rnd.setSeed(seed);

    cout << n << " " << k << endl;

    long long pos = rnd.next(1LL, n);
    long long L = 1;
    long long R = n;
    set<long long> blocked;
    int caught = 0;

    while (true) {

        if (queries > 0 && queries % 100 == 0) {
            log_metrics();
        }

        string token;
        if (!(cin >> token)) {
            finish(_wa, "Unexpected EOF (expected move)");
        }

        long long p;

        if (token == "?" || token == "!") {
            if (!(cin >> p)) {
                finish(_wa, "Unexpected EOF after prefix token");
            }
        } else {
            try {
                size_t idx;
                p = stoll(token, &idx);
                if (idx != token.size()) finish(_wa, "Garbage in input token");
            } catch (...) {
                finish(_wa, "Invalid integer format: " + token);
            }
        }

        if (p < 0 || p > n) {
            finish(_wa, "Action out of bounds: " + to_string(p));
        }

        queries++;

        bool just_caught = false;

        if (p != 0 && blocked.find(p) == blocked.end()) {

            if (p == pos) {
                just_caught = true;
            } else {
                blocked.insert(p);
            }
        }

        if (just_caught) {
            caught++;
            blocked.clear();

            if (caught == k) {

                cout << 3 << endl;
                finish(_ok, "Caught all " + to_string(k) + " hoglins");
            } else {

                if (queries >= query_limit) {
                    cout << -1 << endl;
                    finish(_wa, "Query limit reached immediately after catching a hoglin (caught " + to_string(caught) + "/" + to_string(k) + ")");
                }

                cout << 2 << endl;

                pos = rnd.next(1LL, n);
                L = 1;
                R = n;

                continue;
            }
        }

        if (queries >= query_limit) {
            cout << -1 << endl;
            finish(_wa, "Query limit exceeded without catching K-th hoglin");
        }

        long long target = rnd.next(L, R);

        if (target == pos) {

            cout << 0 << endl;
        } else {

            long long dir = (target > pos) ? 1 : -1;

            long long obstacle = -1;

            if (dir == 1) {

                auto it = blocked.upper_bound(pos);
                if (it != blocked.end()) {
                    long long blk = *it;
                    if (blk <= target) {
                        obstacle = blk;
                    }
                }
            } else {

                auto it = blocked.lower_bound(pos);
                if (it != blocked.begin()) {
                    it--;
                    long long blk = *it;
                    if (blk >= target) {
                        obstacle = blk;
                    }
                }
            }

            if (obstacle != -1) {

                cout << 1 << endl;

                if (dir == 1) {

                    R = obstacle - 1;
                } else {

                    L = obstacle + 1;
                }

            } else {

                cout << 0 << endl;
                pos = target;
            }
        }
    }

    return 0;
}

#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");

    long long seed_input = -1;
    bool explicit_case = false;

    if (argc > 1) {
        string s = argv[1];
        try {
            size_t pos;
            long long val = stoll(s, &pos);

            if (pos == s.size() && val >= 1 && val <= 20) {
                seed_input = val;
                explicit_case = true;
            }
        } catch (...) {

            explicit_case = false;
        }
    }

    long long n;
    int k;

    if (explicit_case) {
        switch (seed_input) {
            case 1: n = 1; k = 1; break;
            case 2: n = 2; k = 1; break;
            case 3: n = 10; k = 1; break;
            case 4: n = 100; k = 50; break;
            case 5: n = 1000000000000000000LL; k = 1; break;
            case 6: n = 1000000000000000000LL; k = 800; break;
            case 7: n = 2; k = 800; break;
            case 8: n = 1000; k = 800; break;
            case 9: n = 1000000; k = 100; break;
            case 10: n = 999999999999999999LL; k = 799; break;
            default:

                n = rnd.next(100LL, 100000LL);
                k = rnd.next(1, 100);
                break;
        }
    } else {

        int type_n = rnd.next(100);

        if (type_n < 5) {

            n = rnd.next(1LL, 100LL);
        } else if (type_n < 15) {

            n = rnd.next(100LL, 100000LL);
        } else if (type_n < 30) {

            n = rnd.next(100000LL, 1000000000LL);
        } else if (type_n < 50) {

            n = rnd.next(1000000000LL, 1000000000000000LL);
        } else {

            n = rnd.next(1000000000000000LL, 1000000000000000000LL);
        }

        int type_k = rnd.next(100);
        if (type_k < 10) {
            k = 1;
        } else if (type_k < 30) {
            k = rnd.next(1, 10);
        } else if (type_k < 60) {
            k = rnd.next(10, 100);
        } else {

            k = rnd.next(100, 800);
        }
    }

    cout << n << " " << k << "\n";

    if (mode == "non") {

        long long interactor_seed = rnd.next(1LL, 2000000000000000000LL);
        cout << interactor_seed << "\n";
    }
    else if (mode == "adp") {

    }

    return 0;
}


### Problem Statement

This is an **interactive problem** (a type of problem where your program interacts with the judge program through Standard Input and Output).

There are $N$ bottles of juice, numbered $1$ to $N$. It has been discovered that exactly one of these bottles has gone bad. Even a small sip of the spoiled juice will cause stomach upset the next day.

Takahashi must identify the spoiled juice by the next day. To do this, he decides to call the **minimum necessary number** of friends and serve them some of the $N$ bottles of juice. He can give any number of bottles to each friend, and each bottle of juice can be given to any number of friends.

Print the number of friends to call and how to distribute the juice, then receive information on whether each friend has an upset stomach the next day, and print the spoiled bottle's number.

### Constraints

* $N$ is an integer.
* $2 \leq N \leq 100$

### Input/Output

This is an interactive problem (a type of problem where your program interacts with the judge program through Standard Input and Output).

Before the interaction, the judge secretly selects an integer $X$ between $1$ and $N$ as the spoiled bottle's number. The value of $X$ is not given to you. Also, **the value of $X$ may change during the interaction as long as it is consistent with the constraints and previous outputs.**

First, the judge will give you $N$ as input.

```
$N$
```

You should print the number of friends to call, $M$, followed by a newline.

```
$M$
```

Next, you should perform the following procedure to print $M$ outputs.
For $i = 1, 2, \ldots, M$, the $i$-th output should contain the number $K_i$ of bottles of juice you will serve to the $i$-th friend, and the $K_i$ bottles' numbers in **ascending order**, $A_{i, 1}, A_{i, 2}, \ldots, A_{i, K_i}$, separated by spaces, followed by a newline.

```
$K_i$ $A_{i, 1}$ $A_{i, 2}$ $\ldots$ $A_{i, K_i}$
```

Then, the judge will inform you whether each friend has a stomach upset the next day by giving you a string $S$ of length $M$ consisting of `0` and `1`.

```
$S$
```

For $i = 1, 2, \ldots, M$, the $i$-th friend has a stomach upset if and only if the $i$-th character of $S$ is `1`.

You should respond by printing the number of the spoiled juice bottle $X'$, followed by a newline.

```
$X'$
```

Then, terminate the program immediately.

If the $M$ you printed is the **minimum necessary** number of friends to identify the spoiled juice out of the $N$ bottles, and the $X'$ you printed matches the spoiled bottle's number $X$, then your program is considered correct.

### Notes

* **Each output should end with a newline and flushing Standard Output. Otherwise, you may receive a TLE verdict.**
* **The verdict is indeterminate if your program prints an invalid output during the interaction or terminates prematurely.** In particular, note that if a runtime error occurs during the execution of the program, the verdict may be WA or TLE instead of RE.
* Terminate the program immediately after printing $X'$. Otherwise, the verdict is indeterminate.
* **The judge for this problem is adaptive, meaning that the value of $X$ may change as long as it is consistent with the constraints and previous outputs.**

---

### Sample Input/Output

Below is an interaction with $N = 3$.

| Input | Output | Description |
| --- | --- | --- |
| `3` |  | The number of bottles, $N$, is given. |
|  | `2` | Print the number of friends to call, $M$. |
|  | `2 1 2` | Serve juice $1$ and juice $2$ to the first friend. |
|
|  | `1 2` | Serve juice $2$ to the second friend. |
|
| `10` |  | The string $S$ is given, indicating whether each friend has a stomach upset the next day. |
|  | `1` | Print the spoiled bottle's number. |
|

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

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

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 main(int argc, char** argv) {

    registerInteraction(argc, argv);
    atexit(log_metrics);

    log_metrics();

    int N = inf.readInt(2, 100, "N");
    int X = inf.readInt(1, N, "X");

    int min_M = 0;
    while ((1 << min_M) < N) {
        min_M++;
    }

    cout << N << endl;

    string m_token;
    if (!(cin >> m_token)) {
        finish(_wa, "Failed to read M (empty output)");
    }

    if (m_token == "?" || m_token == "!") {
        finish(_wa, "Protocol violation: Expected integer M, found '" + m_token + "'");
    }

    int user_M = -1;
    try {
        size_t idx;
        user_M = stoi(m_token, &idx);
        if (idx != m_token.size()) finish(_wa, "Garbage in M token: " + m_token);
    } catch (...) {
        finish(_wa, "M is not a valid integer: " + m_token);
    }

    if (user_M != min_M) {
        finish(_wa, "M is not the minimum necessary number. Expected " + to_string(min_M) + ", found " + to_string(user_M));
    }

    string result_S = "";

    for (int i = 0; i < user_M; ++i) {
        int K;
        if (!(cin >> K)) {
            finish(_wa, "Failed to read K for friend " + to_string(i + 1));
        }

        if (K < 0 || K > N) {
            finish(_wa, "K is out of bounds [0, " + to_string(N) + "] for friend " + to_string(i + 1));
        }

        bool drinks_spoiled = false;
        for (int j = 0; j < K; ++j) {
            int bottle;
            if (!(cin >> bottle)) {
                finish(_wa, "Failed to read bottle index for friend " + to_string(i + 1));
            }
            if (bottle < 1 || bottle > N) {
                finish(_wa, "Bottle index " + to_string(bottle) + " out of bounds [1, " + to_string(N) + "]");
            }
            if (bottle == X) {
                drinks_spoiled = true;
            }
        }
        result_S += (drinks_spoiled ? '1' : '0');
    }

    queries = 1;
    log_metrics();

    cout << result_S << endl;

    string ans_token;
    if (!(cin >> ans_token)) {
        finish(_wa, "Failed to read final answer");
    }

    if (ans_token == "!") {
        if (!(cin >> ans_token)) {
            finish(_wa, "Failed to read final answer number after '!'");
        }
    }

    int ans_X = -1;
    try {
        size_t idx;
        ans_X = stoi(ans_token, &idx);
        if (idx != ans_token.size()) finish(_wa, "Garbage in answer token: " + ans_token);
    } catch (...) {
        finish(_wa, "Answer is not a valid integer: " + ans_token);
    }

    if (ans_X == X) {
        finish(_ok, "Correct");
    } else {
        finish(_wa, "Wrong answer. Expected " + to_string(X) + ", found " + to_string(ans_X));
    }

    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

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

static int N = 0;
static int M_opt = 0;

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

template <typename T>
bool read_val(T &val) {
    if (!(cin >> val)) return false;
    return true;
}

int main(int argc, char** argv) {

    registerInteraction(argc, argv);
    atexit(log_metrics);

    N = inf.readInt(2, 100, "N");

    int m_calc = 0;
    while ((1LL << m_calc) < N) {
        m_calc++;
    }
    M_opt = m_calc;

    query_limit = M_opt;
    log_metrics();

    cout << N << endl;

    int M;
    if (!read_val(M)) {
        finish(_pe, "Failed to read M (number of friends)");
    }

    queries = M;
    log_metrics();

    if (M < 0) {
        finish(_pe, "M cannot be negative");
    }

    if (M > 2000) {
        finish(_pe, "M exceeds allowed hard limit (2000)");
    }

    vector<vector<int>> bottle_sigs(N + 1, vector<int>(M, 0));

    for (int i = 0; i < M; i++) {
        int K;
        if (!read_val(K)) {
            finish(_pe, "Failed to read K for friend " + to_string(i + 1));
        }

        if (K < 0 || K > N) {
            finish(_pe, "K is out of range [0, N] for friend " + to_string(i + 1));
        }

        for (int j = 0; j < K; j++) {
            int bottle_idx;
            if (!read_val(bottle_idx)) {
                finish(_pe, "Failed to read bottle index");
            }
            if (bottle_idx < 1 || bottle_idx > N) {
                finish(_pe, "Bottle index out of range [1, N]: " + to_string(bottle_idx));
            }
            bottle_sigs[bottle_idx][i] = 1;
        }
    }

    map<vector<int>, vector<int>> sig_map;
    for (int b = 1; b <= N; b++) {
        sig_map[bottle_sigs[b]].push_back(b);
    }

    vector<int> chosen_S;
    vector<int> candidates;

    bool found_ambiguous = false;
    for (auto const& [sig, bottles] : sig_map) {
        if (bottles.size() >= 2) {
            chosen_S = sig;
            candidates = bottles;
            found_ambiguous = true;
            break;
        }
    }

    if (!found_ambiguous) {

        if (sig_map.empty()) {
            finish(_fail, "Internal error: no bottle signatures computed");
        }

        chosen_S = sig_map.begin()->first;
        candidates = sig_map.begin()->second;
    }

    string s_out = "";
    for (int bit : chosen_S) {
        s_out += (bit ? '1' : '0');
    }
    cout << s_out << endl;

    int X_prime;
    if (!read_val(X_prime)) {
        finish(_pe, "Failed to read answer X'");
    }

    if (candidates.size() > 1) {

        int actual = candidates[0];
        if (actual == X_prime) actual = candidates[1];
        finish(_wa, "Ambiguous outcome. The data is consistent with bottle "
                    + to_string(actual) + ", but you output " + to_string(X_prime));
    } else {

        int actual = candidates[0];
        if (X_prime != actual) {
            finish(_wa, "Wrong answer. The hidden bottle was " + to_string(actual)
                        + ", but you output " + to_string(X_prime));
        } else {

            if (M != M_opt) {
                finish(_wa, "Correct bottle identified, but used " + to_string(M)
                            + " friends. Minimum necessary is " + to_string(M_opt));
            } else {
                finish(_ok, "Correct");
            }
        }
    }

    return 0;
}

#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<int>("n", 0);

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

        if (seed_val == 1) n = 2;
        else if (seed_val == 2) n = 100;
        else if (seed_val == 3) n = 3;
        else if (seed_val == 4) n = 64;
        else if (seed_val == 5) n = 65;
        else if (seed_val == 6) n = 63;
        else if (seed_val == 7) n = 32;
        else if (seed_val == 8) n = 33;
        else {

            int type = rnd.next(100);
            if (type < 40) {

                n = rnd.next(80, 100);
            } else if (type < 70) {

                vector<int> candidates = {4, 8, 16, 32, 64};
                int base = candidates[rnd.next((int)candidates.size())];
                n = base + rnd.next(-1, 1);
            } else {

                n = rnd.next(2, 100);
            }
        }
    }

    n = max(2, min(100, n));

    if (mode == "non") {

        int x = rnd.next(1, n);
        println(n, x);
    } else if (mode == "adp") {

        println(n);
    } else {
        quitf(_fail, "Unknown mode: %s. Use 'non' or 'adp'.", mode.c_str());
    }

    return 0;
}


This problem is interactive.

We have hidden a permutation $p_1, p_2, \dots, p_n$ of numbers from $1$ to $n$ from you, where $n$ is even. You can try to guess it using the following queries:

$?$ $k$ $a_1$ $a_2$ $\dots$ $a_k$.

In response, you will learn if the average of elements with indexes $a_1, a_2, \dots, a_k$ is an integer. In other words, you will receive $1$ if $\frac{p_{a_1} + p_{a_2} + \dots + p_{a_k}}{k}$ is integer, and $0$ otherwise.

You have to guess the permutation. You can ask not more than $18n$ queries.

Note that permutations $[p_1, p_2, \dots, p_k]$ and $[n + 1 - p_1, n + 1 - p_2, \dots, n + 1 - p_k]$ are indistinguishable. Therefore, you are guaranteed that $p_1 \le \frac{n}{2}$.

Note that the permutation $p$ is fixed before the start of the interaction and doesn't depend on your queries. In other words, interactor is not adaptive.

Note that you don't have to minimize the number of queries.

Input

The first line contains a single integer $n$ ($2 \le n \le 800$, $n$ is even).

Interaction

You begin the interaction by reading $n$.

To ask a question about elements on positions $a_1, a_2, \dots, a_k$, in a separate line output

$?$ $k$ $a_1$ $a_2$ ... $a_k$

Numbers in the query have to satisfy $1 \le a_i \le n$, and all $a_i$ have to be different. Don't forget to 'flush', to get the answer.

In response, you will receive $1$ if $\frac{p_{a_1} + p_{a_2} + \dots + p_{a_k}}{k}$ is integer, and $0$ otherwise.

In case your query is invalid or you asked more than $18n$ queries, the program will print $-1$ and will finish interaction. You will receive a Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.

When you determine permutation, output

$!$ $p_1$ $p_2$ ... $p_n$

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.

Example

Input

```
2
1 2
```

Output

```
? 1 2
? 1 1
! 1 2
```

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

static long long queries = 0;
static long long query_limit = 0;
static bool finished = false;

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

    }
}

template <typename... Args>
void finish(TResult verdict, const char* fmt, Args... args) {
    log_metrics();
    finished = true;
    quitf(verdict, fmt, args...);
}

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

    registerInteraction(argc, argv);

    atexit(log_metrics);

    int n = inf.readInt();

    query_limit = 18LL * n;

    vector<int> p(n + 1);
    for (int i = 1; i <= n; ++i) {
        p[i] = inf.readInt();
    }

    cout << n << endl;

    while (!finished) {

        if (queries % 20 == 0) log_metrics();

        string token;

        if (!(cin >> token)) {
            finish(_pe, "Unexpected EOF (expected query or answer)");
            return 0;
        }

        if (token == "!") {

            vector<int> guess(n + 1);
            for (int i = 1; i <= n; ++i) {
                if (!(cin >> guess[i])) {
                     finish(_pe, "Unexpected EOF while reading answer permutation");
                }
            }

            bool correct = true;
            for (int i = 1; i <= n; ++i) {
                if (guess[i] != p[i]) {
                    correct = false;
                    break;
                }
            }

            if (correct) {
                finish(_ok, "Correct permutation guessed in %lld queries", queries);
            } else {
                finish(_wa, "Incorrect permutation guessed");
            }
        } else {

            int k;
            if (token == "?") {
                if (!(cin >> k)) {
                    finish(_pe, "Unexpected EOF reading k after '?'");
                }
            } else {

                try {
                    k = stoi(token);
                } catch (...) {
                    finish(_pe, "Invalid token '%s' (expected '?' or integer k)", token.c_str());
                }
            }

            if (k < 1 || k > n) {
                finish(_pe, "Invalid k=%d (must be 1..n)", k);
            }

            vector<int> a(k);
            vector<int> current_seen(n + 1, 0);
            long long sum = 0;

            for (int i = 0; i < k; ++i) {
                if (!(cin >> a[i])) {
                    finish(_pe, "Unexpected EOF reading indices");
                }

                if (a[i] < 1 || a[i] > n) {
                    finish(_pe, "Index out of bounds: %d", a[i]);
                }

                if (current_seen[a[i]]) {
                    finish(_pe, "Duplicate index in query: %d", a[i]);
                }
                current_seen[a[i]] = 1;
                sum += p[a[i]];
            }

            queries++;

            if (queries > query_limit) {

                cout << -1 << endl;
                finish(_wa, "Query limit exceeded (>%lld)", query_limit);
            }

            int result = (sum % k == 0) ? 1 : 0;
            cout << result << endl;
        }
    }

    return 0;
}

#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<int>("n", -1);

    unsigned long long seed_val = 0;
    if (argc > 1) {
        try {
            seed_val = stoull(string(argv[1]));
        } catch (...) {
            seed_val = rnd.next(1000, 100000);
        }
    }

    if (n == -1) {
        if (seed_val == 1) n = 2;
        else if (seed_val == 2) n = 800;
        else if (seed_val == 3) n = 800;
        else if (seed_val == 4) n = 800;
        else if (seed_val == 5) n = 4;
        else {

            n = rnd.next(1, 400) * 2;
        }
    }

    if (n % 2 != 0) n--;
    n = max(2, min(800, n));

    if (mode == "adp") {

        cout << n << endl;
    } else {

        cout << n << endl;
        vector<int> p(n);

        if (seed_val == 2) {

            iota(p.begin(), p.end(), 1);
        } else if (seed_val == 3) {

            int l = 1, r = n;
            for (int i = 0; i < n; ++i) {
                if (i % 2 == 0) p[i] = l++;
                else p[i] = r--;
            }
        } else {

            iota(p.begin(), p.end(), 1);
            shuffle(p.begin(), p.end());
        }

        if (p[0] > n / 2) {
            for (int &x : p) {
                x = n + 1 - x;
            }
        }

        println(p);
    }

    return 0;
}