This is an interactive problem.

To prevent the mischievous rabbits from freely roaming around the zoo, Zookeeper has set up a special lock for the rabbit enclosure. This lock is called the Rotary Laser Lock.

The lock consists of $n$ concentric rings numbered from $0$ to $n-1$. The innermost ring is ring $0$ and the outermost ring is ring $n-1$. All rings are split equally into $nm$ sections each. Each of those rings contains a single metal arc that covers exactly $m$ contiguous sections. At the center of the ring is a core and surrounding the entire lock are $nm$ receivers aligned to the $nm$ sections.

The core has $nm$ lasers that shine outward from the center, one for each section. The lasers can be blocked by any of the arcs. A display on the outside of the lock shows how many lasers hit the outer receivers.

 ![](https://espresso.codeforces.com/32f94ff5242137b3aec3a5ef6f5dfcc9b456bcce.png)

In the example above, there are $n=3$ rings, each covering $m=4$ sections. The arcs are colored in green (ring $0$), purple (ring $1$), and blue (ring $2$) while the lasers beams are shown in red. There are $nm=12$ sections and $3$ of the lasers are not blocked by any arc, thus the display will show $3$ in this case.

Wabbit is trying to open the lock to free the rabbits, but the lock is completely opaque, and he cannot see where any of the arcs are. Given the relative positions of the arcs, Wabbit can open the lock on his own.

To be precise, Wabbit needs $n-1$ integers $p_1,p_2,\ldots,p_{n-1}$ satisfying $0 \leq p_i < nm$ such that for each $i$ $(1 \leq i < n)$, Wabbit can rotate ring $0$ clockwise exactly $p_i$ times such that the sections that ring $0$ covers perfectly aligns with the sections that ring $i$ covers. In the example above, the relative positions are $p_1 = 1$ and $p_2 = 7$.

To operate the lock, he can pick any of the $n$ rings and rotate them by $1$ section either clockwise or anti-clockwise. You will see the number on the display after every rotation.

Because his paws are small, Wabbit has asked you to help him to find the relative positions of the arcs after all of your rotations are completed. You may perform up to $15000$ rotations before Wabbit gets impatient.

Input

The first line consists of 2 integers $n$ and $m$ $(2 \leq n \leq 100, 2 \leq m \leq 20)$, indicating the number of rings and the number of sections each ring covers.

Interaction

To perform a rotation, print on a single line "? x d" where $x$ $(0 \leq x < n)$ is the ring that you wish to rotate and $d$ $(d \in \{-1,1\})$ is the direction that you would like to rotate in. $d=1$ indicates a clockwise rotation by $1$ section while $d=-1$ indicates an anticlockwise rotation by $1$ section.

For each query, you will receive a single integer $a$: the number of lasers that are not blocked by any of the arcs after the rotation has been performed.

Once you have figured out the relative positions of the arcs, print ! followed by $n-1$ integers $p_1, p_2, \ldots, p_{n-1}$.

Do note that the positions of the rings are predetermined for each test case and won't change during the interaction process.

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

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

```
3 4

4

4

3
```

Output

```
? 0 1

? 2 -1

? 1 1

! 1 5
```

Note

For the first test, the configuration is the same as shown on the picture from the statement.

After the first rotation (which is rotating ring $0$ clockwise by $1$ section), we obtain the following configuration:

 ![](https://espresso.codeforces.com/a3ca503acc94f61b8b25428e93aa5bb3edc3c761.png)

After the second rotation (which is rotating ring $2$ counter-clockwise by $1$ section), we obtain the following configuration:

 ![](https://espresso.codeforces.com/955a2f5c4f50184d87789b5a97e5ad7c3310c859.png)

After the third rotation (which is rotating ring $1$ clockwise by $1$ section), we obtain the following configuration:

 ![](https://espresso.codeforces.com/71f95f75b83b810f4f92837351386d9060df2b2c.png)

If we rotate ring $0$ clockwise once, we can see that the sections ring $0$ covers will be the same as the sections that ring $1$ covers, hence $p_1=1$.

If we rotate ring $0$ clockwise five times, the sections ring $0$ covers will be the same as the sections that ring $2$ covers, hence $p_2=5$.

Note that if we will make a different set of rotations, we can end up with different values of $p_1$ and $p_2$ at the end.

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

using namespace std;

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

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(2, 100, "n");
    int m = inf.readInt(2, 20, "m");
    int total_sections = n * m;

    vector<int> pos(n);
    for (int i = 0; i < n; i++) {
        pos[i] = inf.readInt(0, total_sections - 1, format("pos[%d]", i));
    }

    log_metrics();

    cout << n << " " << m << endl;

    string token;

    while (cin >> token) {
        if (token == "!") {

            vector<int> ans(n - 1);
            for (int i = 0; i < n - 1; i++) {
                string val_s;
                if (!(cin >> val_s)) {
                    finish(_pe, "Unexpected end of output while reading answer");
                }
                try {
                    ans[i] = stoi(val_s);
                } catch (...) {
                    finish(_pe, "Answer elements must be integers");
                }
            }

            vector<int> expected(n - 1);
            for (int i = 1; i < n; i++) {
                int val = (pos[i] - pos[0]) % total_sections;
                if (val < 0) val += total_sections;
                expected[i - 1] = val;
            }

            bool ok = true;
            for (int i = 0; i < n - 1; i++) {
                if (ans[i] != expected[i]) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                finish(_ok, format("Correct! Used %lld queries.", queries));
            } else {
                string exp_s = "", fnd_s = "";
                int limit_disp = min((int)expected.size(), 5);
                for (int i = 0; i < limit_disp; ++i) exp_s += to_string(expected[i]) + " ";
                for (int i = 0; i < limit_disp; ++i) fnd_s += to_string(ans[i]) + " ";
                if (expected.size() > 5) { exp_s += "..."; fnd_s += "..."; }
                finish(_wa, format("Wrong answer. Expected (first 5): %s Found: %s", exp_s.c_str(), fnd_s.c_str()));
            }
        } else {

            int x = -1, d = 0;

            if (token == "?") {
                string s_x, s_d;
                if (!(cin >> s_x >> s_d)) finish(_pe, "Unexpected end of output reading query args");
                try {
                    x = stoi(s_x);
                    d = stoi(s_d);
                } catch (...) {
                    finish(_pe, "Query args must be integers");
                }
            } else {

                try {
                    x = stoi(token);
                } catch (...) {
                    finish(_pe, "Expected '?' or integer ring index");
                }

                string s_d;
                if (!(cin >> s_d)) finish(_pe, "Unexpected end of output reading direction");
                try {
                    d = stoi(s_d);
                } catch (...) {
                    finish(_pe, "Direction must be integer");
                }
            }

            if (x < 0 || x >= n) {
                finish(_pe, format("Ring index %d out of bounds [0, %d)", x, n));
            }
            if (d != 1 && d != -1) {
                finish(_pe, format("Direction %d invalid, must be 1 or -1", d));
            }

            queries++;

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

            pos[x] = (pos[x] + d) % total_sections;
            if (pos[x] < 0) pos[x] += total_sections;

            static vector<int> counts;
            if ((int)counts.size() != total_sections) counts.assign(total_sections, 0);
            else fill(counts.begin(), counts.end(), 0);

            for (int i = 0; i < n; i++) {
                int p = pos[i];

                for (int k = 0; k < m; k++) {
                    int idx = p + k;
                    if (idx >= total_sections) idx -= total_sections;
                    counts[idx]++;
                }
            }

            int visible = 0;
            for (int i = 0; i < total_sections; i++) {
                if (counts[i] == 0) visible++;
            }

            cout << visible << endl;

            if (queries % 100 == 0) log_metrics();
        }
    }

    finish(_pe, "Unexpected end of output (did not receive answer)");
    return 0;
}

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

static long long queries = 0;
static long long query_limit = 15000;
static const int HARD_CAP = 30000;

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

    }
}

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();
    int m = inf.readInt();
    int nm = n * m;

    vector<int> s(n);
    bool input_ok = true;
    for (int i = 0; i < n; i++) {

        if (inf.seekEof()) {
            input_ok = false;
            break;
        }
        s[i] = inf.readInt();
    }

    if (!input_ok) {
        mt19937 rng(1337);
        for (int i = 0; i < n; i++) {
            s[i] = rng() % nm;
        }
    }

    log_metrics();

    cout << n << " " << m << endl;

    vector<bool> covered(nm);

    while (true) {

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

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

            finish(_pe, "Unexpected end of output from contestant");
        }

        if (type == "!") {

            vector<int> p_ans(n - 1);
            for (int i = 0; i < n - 1; i++) {
                if (!(cin >> p_ans[i])) {
                    finish(_pe, "Incomplete final answer");
                }
            }

            for (int i = 1; i < n; i++) {
                int expected = (s[i] - s[0]);
                if (expected < 0) expected += nm;
                expected %= nm;

                if (p_ans[i - 1] != expected) {
                    finish(_wa, format("Wrong relative position for ring %d. Expected %d, found %d",
                                       i, expected, p_ans[i - 1]));
                }
            }

            finish(_ok, "Correct relative positions found");

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

            int x, d;
            if (!(cin >> x >> d)) {
                finish(_pe, "Invalid query format");
            }

            queries++;

            if (x < 0 || x >= n) {
                finish(_pe, format("Ring index %d out of bounds [0, %d)", x, n));
            }
            if (d != 1 && d != -1) {
                finish(_pe, format("Invalid direction %d. Must be 1 (CW) or -1 (CCW)", d));
            }

            s[x] += d;
            if (s[x] >= nm) s[x] -= nm;
            if (s[x] < 0) s[x] += nm;

            fill(covered.begin(), covered.end(), false);

            for (int i = 0; i < n; i++) {
                int start = s[i];

                for (int k = 0; k < m; k++) {
                    int idx = start + k;
                    if (idx >= nm) idx -= nm;
                    covered[idx] = true;
                }
            }

            int unblocked = 0;
            for (int k = 0; k < nm; k++) {
                if (!covered[k]) unblocked++;
            }

            cout << unblocked << endl;

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

        } else {
            finish(_pe, "Unknown query type '" + type + "'. Expected '?' or '!'");
        }
    }

    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);
    int m = opt<int>("m", -1);

    long long seed_val = 0;
    if (argc > 1 && argv[1][0] != '-') {
        try {
            seed_val = stoll(argv[1]);
        } catch (...) {
            seed_val = 0;
        }
    }

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

            int t = rnd.next(10);
            if (t < 2) n = rnd.next(2, 5);
            else if (t < 5) n = rnd.next(90, 100);
            else n = rnd.next(2, 100);
        }
    }

    if (m == -1) {
        if (seed_val == 1) m = 2;
        else if (seed_val == 2) m = 20;
        else if (seed_val == 3) m = 2;
        else if (seed_val == 4) m = 20;
        else {
            int t = rnd.next(10);
            if (t < 3) m = 2;
            else if (t < 6) m = 20;
            else m = rnd.next(2, 20);
        }
    }

    cout << n << " " << m << endl;

    if (mode == "non") {
        vector<int> p(n);
        int total = n * m;

        int strategy = 0;

        if (seed_val > 4 || seed_val <= 0) {
            int roll = rnd.next(100);
            if (roll < 70) strategy = 0;
            else if (roll < 85) strategy = 1;
            else if (roll < 95) strategy = 2;
            else strategy = 3;
        }

        if (strategy == 0) {
            for (int i = 0; i < n; i++) {
                p[i] = rnd.next(0, total - 1);
            }
        } else if (strategy == 1) {
            int center = rnd.next(0, total - 1);
            int range = max(1, total / 15);
            for (int i = 0; i < n; i++) {
                int delta = rnd.next(-range, range);
                int val = (center + delta) % total;
                if (val < 0) val += total;
                p[i] = val;
            }
        } else if (strategy == 2) {
            int start = rnd.next(0, total - 1);
            int step = total / n;
            if (step == 0) step = 1;
            for (int i = 0; i < n; i++) {
                p[i] = (start + i * step) % total;
            }
            shuffle(p.begin(), p.end());
        } else {
            int val = rnd.next(0, total - 1);
            fill(p.begin(), p.end(), val);
        }

        println(p);
    }

    return 0;
}


This is an interactive problem.

This is a hard version of the problem. The difference from the easy version is that in the hard version $1 \le t \le \min(n, 10^4)$ and the total number of queries is limited to $6 \cdot 10^4$.

Polycarp is playing a computer game. In this game, an array consisting of zeros and ones is hidden. Polycarp wins if he guesses the position of the $k$-th zero from the left $t$ times.

Polycarp can make no more than $6 \cdot 10^4$ requests totally of the following type:

* ? $l$ $r$ — find out the sum of all elements in positions from $l$ to $r$ ($1 \le l \le r \le n$) inclusive.

To make the game more interesting, each guessed zero turns into one and the game continues on the changed array. More formally, if the position of the $k$-th zero was $x$, then after Polycarp guesses this position, the $x$-th element of the array will be replaced from $0$ to $1$.

Help Polycarp win the game.

Interaction

First, your program must read two integers $n$ and $t$ ($1 \le n \le 2 \cdot 10^5$, $1 \le t \le \min(n, 10^4)$).

Then $t$ lines follow, each of which contains one integer $k$ ($1 \le k \le n$). It is guaranteed that at the moment of the request the array contains at least $k$ zeros. In order to get the next value of $k$, you must output the answer for the previous value of $k$.

After that, you can make no more than $6 \cdot 10^4$ requests in total.

Use the following format to output the answer (it is not a request, it doesn't count in $6 \cdot 10^4$):

* ! $x$ — position of the $k$-th zero.

Positions in the array are numbered from left to right from $1$ to $n$ inclusive.

After printing $t$ answers, your program should exit immediately.

In this task, the interactor is not adaptive. This means that within the same test, the hidden array and the queries do not change.

In case of an incorrect query, -1 will be displayed. When this value is received, your program must immediately exit normally (for example, by calling exit(0)), otherwise, the testing system may issue an arbitrary verdict.

If the number of requests is exceeded, the verdict wrong answer will be displayed.

Your solution may get the verdict Idleness limit exceeded if you don't print anything or forget to flush the output buffer.

To flush the output buffer, you need to do the following immediately after the query output and the end-of-line character:

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

Example

Input

```
6 2

2

2

1

1

0

1

0
```

Output

```
? 4 6

? 1 1

? 1 2

? 5 5

! 5

? 2 2

! 2
```

Note

In the first test, the array $[1, 0, 1, 1, 0, 1]$ is hidden. After answering the query $k=2$, the array changed to $[1, 0, 1, 1, 1, 1]$.

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

using namespace std;

static long long queries = 0;
static const long long query_limit_val = 60000;
static long long query_limit = query_limit_val;

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 Fenwick {
    int n;
    vector<int> tree;
    Fenwick(int n) : n(n), tree(n + 1, 0) {}

    void add(int i, int delta) {
        for (; i <= n; i += i & -i) tree[i] += delta;
    }

    int query(int i) {
        int s = 0;
        for (; i > 0; i -= i & -i) s += tree[i];
        return s;
    }

    int query(int l, int r) {
        if (l > r) return 0;
        return query(r) - query(l - 1);
    }
};

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

    signal(SIGPIPE, SIG_IGN);

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

    int n = inf.readInt(1, 200000, "n");
    int t = inf.readInt(1, min(n, 10000), "t");

    vector<int> a(n + 1);
    Fenwick ft(n);
    for (int i = 1; i <= n; ++i) {
        a[i] = inf.readInt(0, 1, format("a[%d]", i));
        if (a[i] == 1) {
            ft.add(i, 1);
        }
    }

    vector<int> ks(t);
    for (int i = 0; i < t; ++i) {
        ks[i] = inf.readInt(1, n, format("k[%d]", i));
    }

    log_metrics();

    cout << n << " " << t << endl;

    for (int round = 0; round < t; ++round) {
        int target_k = ks[round];
        cout << target_k << endl;

        bool round_solved = false;
        while (!round_solved) {
            string token;

            if (!(cin >> token)) {
                finish(_wa, "Unexpected EOF (solution exited prematurely)");
            }

            if (token == "!") {

                int x;
                if (!(cin >> x)) finish(_wa, "Expected index x after '!'");

                if (x < 1 || x > n) {
                    finish(_wa, format("Answer index %d out of bounds [1, %d]", x, n));
                }

                if (a[x] != 0) {
                    finish(_wa, format("Position %d contains 1, expected 0", x));
                }

                int ones_count = ft.query(x);
                int zeros_count = x - ones_count;

                if (zeros_count != target_k) {
                    finish(_wa, format("Position %d is the %d-th zero, expected %d-th", x, zeros_count, target_k));
                }

                a[x] = 1;
                ft.add(x, 1);
                round_solved = true;
            } else {

                int l, r;
                bool has_qm = (token == "?");

                if (has_qm) {
                    if (!(cin >> l)) finish(_wa, "Expected l after '?'");
                } else {

                    try {
                        size_t pos;
                        l = stoi(token, &pos);
                        if (pos != token.size()) finish(_wa, "Invalid token: " + token);
                    } catch (...) {
                        finish(_wa, "Invalid token: " + token);
                    }
                }

                if (!(cin >> r)) finish(_wa, "Expected r after l");

                if (l < 1 || r > n || l > r) {

                    cout << -1 << endl;
                    finish(_wa, format("Invalid query range [%d, %d]", l, r));
                }

                queries++;

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

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

                int ans = ft.query(l, r);
                cout << ans << endl;
            }
        }
    }

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

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

struct Fenwick {
    int n;
    vector<int> tree;
    Fenwick(int n) : n(n), tree(n + 1, 0) {}

    void add(int i, int delta) {
        for (; i <= n; i += i & -i) tree[i] += delta;
    }

    int query(int i) {
        int s = 0;
        for (; i > 0; i -= i & -i) s += tree[i];
        return s;
    }

    int find_kth_zero(int k) {
        int l = 1, r = n, ans = -1;
        while (l <= r) {
            int mid = l + (r - l) / 2;
            if (mid - query(mid) >= k) {
                ans = mid;
                r = mid - 1;
            } else {
                l = mid + 1;
            }
        }
        return ans;
    }
};

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

    string mode = opt<string>("mode", "non");
    int seed_val = atoi(argv[1]);

    int n, t;

    if (seed_val == 1) {

        n = 200000;
        t = 10000;
    } else if (seed_val == 2) {

        n = 200000;
        t = 10000;
    } else if (seed_val == 3) {

        n = 200000;
        t = 10000;
    } else if (seed_val == 4) {

        n = 200000;
        t = 10000;
    } else {

        n = rnd.next(1, 200000);
        t = rnd.next(1, min(n, 10000));

        if (rnd.next(3) > 0) {
            n = rnd.next(190000, 200000);
            t = rnd.next(9000, 10000);
        }
    }

    int min_zeros = t;
    int max_ones = n - min_zeros;
    int num_ones;

    if (seed_val == 1) {
        num_ones = 0;
    } else if (seed_val == 2) {
        num_ones = max_ones;
    } else {
        num_ones = rnd.next(0, max_ones);
    }

    vector<int> a(n, 0);
    if (num_ones > 0) {
        vector<int> p(n);
        iota(p.begin(), p.end(), 0);
        shuffle(p.begin(), p.end());
        for (int i = 0; i < num_ones; ++i) {
            a[p[i]] = 1;
        }
    }

    Fenwick ft(n);
    for (int i = 0; i < n; ++i) {
        if (a[i] == 1) ft.add(i + 1, 1);
    }

    vector<int> ks;
    int current_zeros = n - num_ones;

    for (int i = 0; i < t; ++i) {
        int k;
        if (seed_val == 3) {
            k = 1;
        } else if (seed_val == 4) {
            k = current_zeros;
        } else {

            int r = rnd.next(100);
            if (r < 10) k = 1;
            else if (r < 20) k = current_zeros;
            else if (r < 30) k = current_zeros / 2 + 1;
            else k = rnd.next(1, current_zeros);
        }

        ks.push_back(k);

        int idx = ft.find_kth_zero(k);
        ft.add(idx, 1);
        current_zeros--;
    }

    cout << n << " " << t << "\n";

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

    for (int i = 0; i < t; ++i) {
        cout << ks[i] << (i == t - 1 ? "" : " ");
    }
    cout << "\n";

    return 0;
}


You are given a rooted tree. Each vertex contains $a_i$ tons of gold, which costs $c_i$ per one ton. Initially, the tree consists only a root numbered $0$ with $a_0$ tons of gold and price $c_0$ per ton.

There are $q$ queries. Each query has one of two types:

1. Add vertex $i$ (where $i$ is an index of query) as a son to some vertex $p_i$; vertex $i$ will have $a_i$ tons of gold with $c_i$ per ton. It's guaranteed that $c_i > c_{p_i}$.
2. For a given vertex $v_i$ consider the simple path from $v_i$ to the root. We need to purchase $w_i$ tons of gold from vertices on this path, spending the minimum amount of money. If there isn't enough gold on the path, we buy all we can.

If we buy $x$ tons of gold in some vertex $v$ the remaining amount of gold in it decreases by $x$ (of course, we can't buy more gold that vertex has at the moment). For each query of the second type, calculate the resulting amount of gold we bought and the amount of money we should spend.

Note that you should solve the problem in online mode. It means that you can't read the whole input at once. You can read each query only after writing the answer for the last query, so don't forget to flush output after printing answers. You can use functions like fflush(stdout) in C++ and BufferedWriter.flush in Java or similar after each writing in your program. In standard (if you don't tweak I/O), endl flushes cout in C++ and System.out.println in Java (or println in Kotlin) makes automatic flush as well.

Input

The first line contains three integers $q$, $a_0$ and $c_0$ ($1 \le q \le 3 \cdot 10^5$; $1 \le a_0, c_0 < 10^6$) — the number of queries, the amount of gold in the root and its price.

Next $q$ lines contain descriptions of queries; The $i$-th query has one of two types:

* "$1$ $p_i$ $a_i$ $c_i$" ($0 \le p_i < i$; $1 \le a_i, c_i < 10^6$): add vertex $i$ as a son to vertex $p_i$. The vertex $i$ will have $a_i$ tons of gold with price $c_i$ per one ton. It's guaranteed that $p_i$ exists and $c_i > c_{p_i}$.
* "$2$ $v_i$ $w_i$" ($0 \le v_i < i$; $1 \le w_i < 10^6$): buy $w_i$ tons of gold from vertices on path from $v_i$ to $0$ spending the minimum amount of money. If there isn't enough gold, we buy as much as we can. It's guaranteed that vertex $v_i$ exist.

It's guaranteed that there is at least one query of the second type.

Output

For each query of the second type, print the resulting amount of gold we bought and the minimum amount of money we should spend.

Example

Input

```
5 5 2
2 0 2
1 0 3 4
2 2 4
1 0 1 3
2 4 2
```

Output

```
2 4
4 10
1 3
```

Note

Explanation of the sample:

At the first query, the tree consist of root, so we purchase $2$ tons of gold and pay $2 \cdot 2 = 4$. $3$ tons remain in the root.

At the second query, we add vertex $2$ as a son of vertex $0$. Vertex $2$ now has $3$ tons of gold with price $4$ per one ton.

At the third query, a path from $2$ to $0$ consists of only vertices $0$ and $2$ and since $c_0 < c_2$ we buy $3$ remaining tons of gold in vertex $0$ and $1$ ton in vertex $2$. So we bought $3 + 1 = 4$ tons and paid $3 \cdot 2 + 1 \cdot 4 = 10$. Now, in vertex $0$ no gold left and $2$ tons of gold remain in vertex $2$.

At the fourth query, we add vertex $4$ as a son of vertex $0$. Vertex $4$ now has $1$ ton of gold with price $3$.

At the fifth query, a path from $4$ to $0$ consists of only vertices $0$ and $4$. But since no gold left in vertex $0$ and only $1$ ton is in vertex $4$, we buy $1$ ton of gold in vertex $4$ and spend $1 \cdot 3 = 3$. Now, in vertex $4$ no gold left.

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

const int MAXQ = 300005;
const int LOGN = 20;

int a_amt[MAXQ];
int c_cost[MAXQ];
int up[MAXQ][LOGN];

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

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

    int q = inf.readInt(1, 300000, "q");
    int a0 = inf.readInt(1, 1000000, "a0");
    int c0 = inf.readInt(1, 1000000, "c0");

    query_limit = q;
    log_metrics();

    a_amt[0] = a0;
    c_cost[0] = c0;

    for (int k = 0; k < LOGN; k++) {
        up[0][k] = 0;
    }

    cout << q << " " << a0 << " " << c0 << endl;

    for (int i = 1; i <= q; i++) {
        int type = inf.readInt(1, 2, "type");

        if (type == 1) {

            int p = inf.readInt(0, i - 1, "p_i");
            int a = inf.readInt(1, 1000000, "a_i");
            int c = inf.readInt(1, 1000000, "c_i");

            cout << "1 " << p << " " << a << " " << c << endl;

            a_amt[i] = a;
            c_cost[i] = c;

            up[i][0] = p;
            for (int k = 1; k < LOGN; k++) {
                up[i][k] = up[up[i][k-1]][k-1];
            }

            queries = i;

        } else {

            int v = inf.readInt(0, i - 1, "v_i");
            int w = inf.readInt(1, 1000000, "w_i");

            cout << "2 " << v << " " << w << endl;

            long long ans_gold = 0;
            long long ans_money = 0;
            int rem_w = w;

            while (rem_w > 0 && a_amt[v] > 0) {

                int best = v;
                for (int k = LOGN - 1; k >= 0; k--) {
                    int u = up[best][k];

                    if (a_amt[u] > 0) {
                        best = u;
                    }
                }

                int take = min(rem_w, a_amt[best]);
                a_amt[best] -= take;
                rem_w -= take;
                ans_gold += take;
                ans_money += (long long)take * c_cost[best];
            }

            long long user_gold, user_money;
            string token;
            if (!(cin >> token)) {
                finish(_pe, "Unexpected EOF while reading answer for query " + to_string(i));
            }

            if (token == "!") {
                 if (!(cin >> user_gold >> user_money)) {
                     finish(_pe, "Unexpected EOF after '!' for query " + to_string(i));
                 }
            } else {

                 try {
                     size_t pos;
                     user_gold = stoll(token, &pos);
                 } catch (...) {
                     finish(_pe, "Expected integer output, received: " + token);
                 }
                 if (!(cin >> user_money)) {
                     finish(_pe, "Unexpected EOF while reading money for query " + to_string(i));
                 }
            }

            if (user_gold != ans_gold || user_money != ans_money) {
                finish(_wa, "Wrong answer for query " + to_string(i) +
                       ": expected " + to_string(ans_gold) + " " + to_string(ans_money) +
                       ", got " + to_string(user_gold) + " " + to_string(user_money));
            }

            queries = i;

            if (i % 1000 == 0) log_metrics();
        }
    }

    finish(_ok, "All queries correct");
}

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

using namespace std;

long long queries_processed = 0;

long long total_queries_limit = 0;

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

    }
}

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

const int MAXN = 300005;
const int LOGN = 20;

long long gold[MAXN];

long long cost[MAXN];

int up[MAXN][LOGN];

int depth[MAXN];

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

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

    int Q = inf.readInt();
    int A0 = inf.readInt();
    int C0 = inf.readInt();

    total_queries_limit = Q;

    cout << Q << " " << A0 << " " << C0 << endl;

    gold[0] = A0;
    cost[0] = C0;
    depth[0] = 0;

    for (int j = 0; j < LOGN; ++j) {
        up[0][j] = 0;
    }

    for (int i = 1; i <= Q; ++i) {
        int type = inf.readInt();

        if (type == 1) {

            int p = inf.readInt();
            int a = inf.readInt();
            int c = inf.readInt();

            cout << "1 " << p << " " << a << " " << c << endl;

            gold[i] = a;
            cost[i] = c;
            depth[i] = depth[p] + 1;

            up[i][0] = p;
            for (int j = 1; j < LOGN; ++j) {
                up[i][j] = up[up[i][j-1]][j-1];
            }

        } else {

            int v = inf.readInt();
            int w = inf.readInt();

            cout << "2 " << v << " " << w << endl;

            long long needed = w;
            long long ans_bought = 0;
            long long ans_spent = 0;

            while (needed > 0) {

                if (gold[v] == 0) {
                    break;
                }

                int curr = v;
                for (int k = LOGN - 1; k >= 0; --k) {
                    int ancestor = up[curr][k];
                    if (gold[ancestor] > 0) {
                        curr = ancestor;
                    }
                }

                long long take = min(needed, gold[curr]);
                gold[curr] -= take;
                needed -= take;
                ans_bought += take;
                ans_spent += take * cost[curr];
            }

            long long user_bought, user_spent;
            if (!(cin >> user_bought >> user_spent)) {
                finish(_pe, "Failed to read 2 integers (bought, spent) from contestant");
            }

            if (user_bought != ans_bought || user_spent != ans_spent) {
                string msg = "Wrong answer on query " + to_string(i) +
                             ". Expected: " + to_string(ans_bought) + " " + to_string(ans_spent) +
                             ", Found: " + to_string(user_bought) + " " + to_string(user_spent);
                finish(_wa, msg);
            }
        }

        queries_processed = i;
    }

    finish(_ok, "All queries processed correctly");
    return 0;
}

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

using namespace std;

const int MAX_Q = 300000;
const int LIMIT_VAL = 1000000;
const int MAX_VAL = LIMIT_VAL - 1;

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

    string mode = opt<string>("mode", "non");
    int q_arg = opt<int>("q", -1);

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

    string scenario = "random";
    if (seed == 1) scenario = "tiny";
    else if (seed == 2) scenario = "line";
    else if (seed == 3) scenario = "star";
    else if (mode == "adp") scenario = "stress";
    else scenario = "random";

    int q = MAX_Q;
    if (q_arg != -1) {
        q = q_arg;
    } else {
        if (scenario == "tiny") q = 10;

    }

    int a0 = rnd.next(1, MAX_VAL);
    int c0;
    if (scenario == "line" || scenario == "stress") {
        c0 = rnd.next(1, 10);
    } else {
        c0 = rnd.next(1, MAX_VAL);
    }

    cout << q << " " << a0 << " " << c0 << endl;

    vector<int> nodes;
    nodes.reserve(q + 1);
    nodes.push_back(0);

    vector<int> costs(q + 1);
    costs[0] = c0;

    int line_tail = 0;
    bool has_type2 = false;

    for (int i = 1; i <= q; ++i) {

        int type = 1;

        if (i == q && !has_type2) {
            type = 2;
        } else {
            if (scenario == "tiny") {
                if (nodes.size() < 2) type = 1;
                else type = (rnd.next(100) < 60) ? 1 : 2;
            } else if (scenario == "line") {

                if (nodes.size() < q / 10) type = 1;
                else type = (rnd.next(100) < 90) ? 1 : 2;
            } else if (scenario == "star") {
                if (nodes.size() < 2) type = 1;
                else type = (rnd.next(100) < 70) ? 1 : 2;
            } else if (scenario == "stress") {

                if (nodes.size() < 10) type = 1;
                else type = (rnd.next(100) < 60) ? 1 : 2;
            } else {
                if (nodes.size() < 2) type = 1;
                else type = (rnd.next(100) < 60) ? 1 : 2;
            }
        }

        if (type == 1) {
            int p = 0;

            if (scenario == "line") {
                p = line_tail;
            } else if (scenario == "star") {
                p = 0;
            } else if (scenario == "stress") {

                if (rnd.next(100) < 85) {
                    int k = rnd.next(1, min((int)nodes.size(), 30));
                    p = nodes[nodes.size() - k];
                } else {
                    p = nodes[rnd.next(nodes.size())];
                }
            } else {
                p = nodes[rnd.next(nodes.size())];
            }

            if (costs[p] >= MAX_VAL) {

                if (costs[0] < MAX_VAL) {
                    p = 0;
                } else {

                    type = 2;
                    goto FORCE_QUERY;
                }
            }

            int min_c = costs[p] + 1;
            int c;
            if (scenario == "line") {

                c = min_c + rnd.next(0, 1);
            } else if (scenario == "stress") {

                if (rnd.next(3) == 0) c = rnd.next(min_c, min(MAX_VAL, min_c + 1000));
                else c = rnd.next(min_c, min(MAX_VAL, min_c + 5));
            } else {
                c = rnd.next(min_c, MAX_VAL);
            }
            if (c > MAX_VAL) c = MAX_VAL;

            int a = rnd.next(1, MAX_VAL);

            cout << "1 " << p << " " << a << " " << c << "\n";

            nodes.push_back(i);
            costs[i] = c;
            if (scenario == "line") line_tail = i;

        } else {
            FORCE_QUERY:
            has_type2 = true;
            int v;

            if (scenario == "line") {

                if (rnd.next(100) < 80) v = line_tail;
                else v = nodes[rnd.next(nodes.size())];
            } else if (scenario == "stress") {

                if (rnd.next(100) < 80) {
                    int k = rnd.next(1, min((int)nodes.size(), 50));
                    v = nodes[nodes.size() - k];
                } else {
                    v = nodes[rnd.next(nodes.size())];
                }
            } else {
                v = nodes[rnd.next(nodes.size())];
            }

            int w = rnd.next(1, MAX_VAL);
            cout << "2 " << v << " " << w << "\n";
        }
    }

    return 0;
}


The only difference between this problem and the other two versions is the maximum number of queries. In this version, you are allowed to ask at most $\mathbf{25}$ queries.

This is an interactive problem.

"Everybody! Doremy's Perfect Data Structure Class is about to start! Come and do your best if you want to have as much IQ as me!" In today's Data Structure class, Doremy is teaching everyone a powerful data structure — Doremy tree! Now she gives you a quiz to prove that you are paying attention in class.

Given an array $a$ of length $m$, Doremy tree supports the query $Q(l,r,k)$, where $1 \leq l \leq r \leq m$ and $1 \leq k \leq m$, which returns the number of distinct integers in the array $\left[\lfloor\frac{a_l}{k} \rfloor, \lfloor\frac{a_{l+1}}{k} \rfloor, \ldots, \lfloor\frac{a_r}{k} \rfloor\right]$.

Doremy has a secret permutation $p$ of integers from $1$ to $n$. You can make queries, in one query, you give $3$ integers $l,r,k$ ($1 \leq l \leq r \leq n$, $1 \leq k \leq n$) and receive the value of $Q(l,r,k)$ for the array $p$. Can you find the index $y$ ($1 \leq y \leq n$) such that $p_y=1$ in at most $\mathbf{25}$ queries?

Note that the permutation $p$ is fixed before any queries are made.

Interaction

You begin the interaction by reading an integer $n$ ($3 \le n \le 1024$) in the first line — the length of the permutation.

To make a query, you should output

* "? $l\ r\ k$" ($1 \leq l \leq r \leq n$, $1 \leq k \leq n$)

in a separate line. After each query, you should read an integer $x$ — the value of $Q(l,r,k)$ for $p$. In this version of the problem, you can make at most $25$ such queries.

To give the answer, you should output

* "! $y$" ($1 \leq y \leq n$)

in a separate line, where $p_y=1$.

After printing a query or the answer, 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 documentation for other languages.

Example

Input

```
5

2

2

1

3
```

Output

```
? 1 3 4

? 3 5 3

? 3 4 5

? 3 5 2

! 4
```

Note

The permutation in the example is $[3,5,2,1,4]$.

The input and output for example illustrate possible interaction on that test (empty lines are inserted only for clarity).

In this interaction process:

* For the first query, $\lfloor\frac{3}{4}\rfloor=0,\lfloor\frac{5}{4}\rfloor=1,\lfloor\frac{2}{4}\rfloor=0$, so the answer is $2$.
* For the second query, $\lfloor\frac{2}{3}\rfloor=0,\lfloor\frac{1}{3}\rfloor=0,\lfloor\frac{4}{3}\rfloor=1$, so the answer is still $2$.
* For the third query, $\lfloor\frac{2}{5}\rfloor=0,\lfloor\frac{1}{5}\rfloor=0$, so the answer is $1$.
* For the fourth query, $\lfloor\frac{2}{2}\rfloor=1,\lfloor\frac{1}{2}\rfloor=0,\lfloor\frac{4}{2}\rfloor=2$, so the answer is $3$.

The correct answer is got after $4$ queries, so this process will be judged correct.

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

using namespace std;

static long long queries = 0;

static const long long query_limit = 25;

static const long long HARD_CAP = 1000;

static int n;
static vector<int> p;

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

    n = inf.readInt(3, 1024, "n");
    p.resize(n);
    vector<bool> seen(n + 1, false);
    for (int i = 0; i < n; i++) {
        p[i] = inf.readInt(1, n, format("p[%d]", i + 1));
        if (seen[p[i]]) {
            quitf(_fail, "Input is not a permutation: duplicate value %d found.", p[i]);
        }
        seen[p[i]] = true;
    }

    log_metrics();

    cout << n << endl;
    cout.flush();

    while (true) {

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

        string token;

        if (!(cin >> token)) {

            finish(_wa, "Unexpected EOF: contestant program terminated without outputting an answer.");
        }

        if (token == "!") {

            int y;
            if (!(cin >> y)) {
                finish(_wa, "Invalid format for answer: expected integer index after '!'.");
            }

            log_metrics();

            if (y < 1 || y > n) {
                finish(_wa, format("Answer index %d out of bounds [1, %d].", y, n));
            }

            if (p[y - 1] == 1) {
                finish(_ok, format("Correct! Found index %d with value 1 in %lld queries.", y, queries));
            } else {
                finish(_wa, format("Wrong answer: p[%d] = %d, expected 1.", y, p[y - 1]));
            }

            break;

        } else {

            int l, r, k;

            if (token == "?") {
                if (!(cin >> l >> r >> k)) {
                    finish(_wa, "Invalid query format: expected 'l r k' after '?'.");
                }
            } else {

                try {
                    size_t processed = 0;
                    l = stoi(token, &processed);
                    if (processed != token.size()) {
                        finish(_wa, format("Invalid token '%s': expected '?', '!', or integer.", token.c_str()));
                    }
                } catch (...) {
                    finish(_wa, format("Invalid token '%s': expected '?', '!', or integer.", token.c_str()));
                }
                if (!(cin >> r >> k)) {
                    finish(_wa, "Invalid query format: expected 'r k' after l.");
                }
            }

            queries++;

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

            if (l < 1 || l > n) finish(_wa, format("Query l=%d out of bounds [1, %d].", l, n));
            if (r < 1 || r > n) finish(_wa, format("Query r=%d out of bounds [1, %d].", r, n));
            if (k < 1 || k > n) finish(_wa, format("Query k=%d out of bounds [1, %d].", k, n));
            if (l > r) finish(_wa, format("Invalid range: l (%d) > r (%d).", l, r));

            static vector<int> vals;
            vals.clear();

            for (int i = l - 1; i < r; ++i) {
                vals.push_back(p[i] / k);
            }

            sort(vals.begin(), vals.end());
            int ans = 0;
            if (!vals.empty()) {
                ans = 1;
                for (size_t i = 1; i < vals.size(); ++i) {
                    if (vals[i] != vals[i - 1]) ans++;
                }
            }

            cout << ans << endl;
            cout.flush();
        }
    }

    return 0;
}

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

using namespace std;

static long long queries = 0;
static long long query_limit = 25;
static const long long HARD_CAP = 300;

int N;
vector<int> P;

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

void generate_adversarial(int n) {

    mt19937 rng(n * 239017);

    P.resize(n);
    int split = n / 2;
    vector<int> left, right;

    if (rng() % 2) left.push_back(1);
    else right.push_back(1);

    for (int v = 2; v <= n; v += 2) {
        int v1 = v;
        int v2 = v + 1;
        if (v2 > n) {

            if (rng() % 2) left.push_back(v1);
            else right.push_back(v1);
        } else {

            int choice = rng() % 3;
            if (choice == 0) {
                if (rng() % 2) { left.push_back(v1); left.push_back(v2); }
                else { right.push_back(v1); right.push_back(v2); }
            } else {
                if (rng() % 2) { left.push_back(v1); right.push_back(v2); }
                else { left.push_back(v2); right.push_back(v1); }
            }
        }
    }

    shuffle(left.begin(), left.end(), rng);
    shuffle(right.begin(), right.end(), rng);

    while ((int)left.size() < split) {
        left.push_back(right.back());
        right.pop_back();
    }
    while ((int)left.size() > split) {
        right.push_back(left.back());
        left.pop_back();
    }

    shuffle(left.begin(), left.end(), rng);
    shuffle(right.begin(), right.end(), rng);

    for(int i=0; i<(int)left.size(); ++i) P[i] = left[i];
    for(int i=0; i<(int)right.size(); ++i) P[split + i] = right[i];
}

int query_val(int l, int r, int k) {

    set<int> distinct;
    for (int i = l - 1; i < r; i++) {
        distinct.insert(P[i] / k);
    }
    return (int)distinct.size();
}

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

    N = inf.readInt(3, 1024, "n");

    if (!inf.seekEof()) {
        P.resize(N);
        vector<bool> seen(N + 1, false);
        for (int i = 0; i < N; i++) {
            P[i] = inf.readInt(1, N, "p_i");
            if (seen[P[i]]) quitf(_fail, "Duplicate element in permutation");
            seen[P[i]] = true;
        }
    } else {
        generate_adversarial(N);
    }

    cout << N << endl;

    while (true) {
        string type;
        if (!(cin >> type)) {
            finish(_pe, "Unexpected EOF reading query type");
        }

        if (type == "!") {
            int y;
            if (!(cin >> y)) finish(_pe, "Expected answer index y");

            if (y < 1 || y > N) finish(_pe, "Answer index out of range [1, N]");

            log_metrics();

            if (P[y-1] == 1) {
                finish(_ok, "Correct");
            } else {
                finish(_wa, "Wrong answer: p[y] != 1");
            }
        } else if (type == "?") {
            int l, r, k;
            if (!(cin >> l >> r >> k)) finish(_pe, "Expected arguments l r k");

            if (l < 1 || r > N || l > r) finish(_pe, "Invalid range [l, r]");
            if (k < 1 || k > N) finish(_pe, "Invalid k");

            queries++;

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

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

            int ans = query_val(l, r, k);
            cout << ans << endl;
        } else {
            finish(_pe, "Unknown query type (expected '?' or '!')");
        }
    }

    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 seed_val = atoi(argv[1]);

    int n;

    if (seed_val == 1) n = 3;
    else if (seed_val == 2) n = 1024;
    else if (seed_val == 3) n = 4;
    else {

        int t = rnd.next(3);
        if (t == 0) {

            n = rnd.next(3, 1024);
        } else if (t == 1) {

            n = 1 << rnd.next(2, 10);
        } else {

            n = (1 << rnd.next(2, 10)) + rnd.next(-2, 2);
            n = max(3, min(1024, n));
        }
    }

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

    vector<int> p(n);

    bool adversarial = (seed_val > 5 && seed_val % 2 == 0);

    if (!adversarial) {
        iota(p.begin(), p.end(), 1);
        shuffle(p.begin(), p.end());
    } else {
        int split = n / 2;
        vector<int> left, right;

        if (rnd.next(2)) left.push_back(1);
        else right.push_back(1);

        int max_val = n;

        for (int v = 2; v <= max_val; v += 2) {
            int v1 = v;
            int v2 = v + 1;
            if (v2 > max_val) {

                if (rnd.next(2)) left.push_back(v1);
                else right.push_back(v1);
            } else {

                if (rnd.next(3)) {
                    if (rnd.next(2)) { left.push_back(v1); right.push_back(v2); }
                    else { left.push_back(v2); right.push_back(v1); }
                } else {
                    if (rnd.next(2)) { left.push_back(v1); left.push_back(v2); }
                    else { right.push_back(v1); right.push_back(v2); }
                }
            }
        }

        shuffle(left.begin(), left.end());
        shuffle(right.begin(), right.end());

        while ((int)left.size() < split) {
            left.push_back(right.back());
            right.pop_back();
        }
        while ((int)left.size() > split) {
            right.push_back(left.back());
            left.pop_back();
        }

        shuffle(left.begin(), left.end());
        shuffle(right.begin(), right.end());

        for(int i=0; i<(int)left.size(); ++i) p[i] = left[i];
        for(int i=0; i<(int)right.size(); ++i) p[split + i] = right[i];
    }

    cout << n << endl;
    for (int i = 0; i < n; i++) {
        cout << p[i] << (i == n - 1 ? "" : " ");
    }
    cout << endl;

    return 0;
}


This is an interactive problem.

Lewis is one of the developers of the new programming language called DiverC. The main feature of the program written in this language is that the code consists of pairwise distinct words. The compiler of DiverC developed by Lewis is, of course, written in DiverC and consists of $N$ pairwise distinct words.

Lewis is using the DiverC online autofill service. But Lewis has made one serious mistake: he forgot to switch the “use my data for the improvement of the service database” function off. And Lewis was the first person who registered on this service, so now the service contains only the words from his compiler.

Hacker Fernando wants to know all the words Lewis used in the compiler. So he registered at the DiverC online autofill service (wisely switching the dangerous function off), and now, for each prefix $S$ and integer $K$ entered by Fernando, the service returns, in lexicographic order, the first $K$ words from Lewis’s code that begin with the prefix $S$ . If there are only $k < K$ words, the service gives out only $k$ words (but the service usage counter increases by $K$ even in this case).

Fernando checked the scripts used for the online service and found that one user is limited with $3 8 0 0$ as the total value of $K$ in all queries. He wants to determine all $N$ words used by Lewis with several queries such as the sum of $K$ in those queries is $3 8 0 0$ or less.

Can you help him?

# Interaction Protocol

In the beginning, your program shall read one integer $T$ — the number of the test cases to be processed $1 \leq T \leq 5$ ).

At the beginning of each test case, the jury program tells one integer $N$ — the number of the words in Lewis’s DiverC compiler ( $1 \leq N \leq 1 0 0 0$ ).

Your program can then make two types of requests:

• query S K — get $K$ ( $1 ~ \leq ~ K ~ \leq ~ N$ ) lexicographically minimal words starting with prefix $S$ $( 1 \leq | S | \leq 1 0 )$ ). If the dictionary contains only $k$ such words, where $k < K$ , the answer to the query will contain $k$ words. The response to the query will be one line of the form $k S _ { 1 } S _ { 2 } \ldots S _ { k }$ , where $k$ is the number of the words ( $0 \leq k \leq K$ ), and then $k$ words $S _ { i }$ in lexicographic order follow. • answer $S _ { 1 }$ $S _ { 2 }$ ... $S _ { N }$ — tell the full Lewis’s dictionary. After the word answer you shall print all $N$ words in an arbitrary order separated by spaces. There will be no response from the jury program to this request, and your program must then continue with the next test case or exit if the current test case was the last one.

The words in Lewis’s code are composed of lowercase English letters. The length of words is between 1 to 10 characters. All words in Lewis’s code are pairwise distinct.

The sum of $K$ for all queries of the first type for each test should be 3 800 or less.

Violating the interaction protocol or exceeding the limits for the sum of $K$ cause the “Wrong answer” verdict.

Make sure you print the newline character after each query and flush the output stream buffer (flush language command) after each request. Otherwise, the solution may get the idleness limit exceeded verdict.

Note that the jury program is adaptive, i.e. the set of Lewis’s words may be generated at the runtime, but the set is guaranteed to be consistent with the answers to previous queries.

# Example

standard input	standard output

1

4	query a 1

1 aaa

2 aaa aba	query a 4

1 cxyxy	query c 1

0	query cy 1

	query cz 1

1 czzzz	answer aaa aba czzzz cxyxy

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

using namespace std;

static long long max_queries_seen = 0;
static const long long QUERY_LIMIT = 3800;
static const long long HARD_CAP = 200000;

static void log_metrics() {

    try {
        tout << "queries=" << max_queries_seen << 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 T = inf.readInt();
    cout << T << endl;

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

        int N = inf.readInt();

        vector<string> dict;
        dict.reserve(N);
        for (int i = 0; i < N; ++i) {
            dict.push_back(inf.readToken());
        }

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

        cout << N << endl;

        long long current_case_queries = 0;
        bool case_active = true;

        while (case_active) {

            string type;

            if (!(cin >> type)) {
                finish(_wa, "Unexpected EOF (waiting for query/answer)");
            }

            if (type == "?") type = "query";
            if (type == "!") type = "answer";

            if (type == "query") {
                string S;
                int K;
                if (!(cin >> S >> K)) {
                    finish(_wa, "Invalid format for query command");
                }

                if (S.empty() || S.length() > 10) finish(_wa, "S length out of range [1, 10]");
                for (char c : S) {
                    if (c < 'a' || c > 'z') finish(_wa, "S contains non-lowercase characters");
                }
                if (K < 1 || K > N) finish(_wa, "K out of range [1, N]");

                current_case_queries += K;
                max_queries_seen = max(max_queries_seen, current_case_queries);

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

                vector<string> result;
                auto it = lower_bound(dict.begin(), dict.end(), S);

                while (it != dict.end() && result.size() < (size_t)K) {

                    if (it->size() >= S.size() && it->substr(0, S.size()) == S) {
                        result.push_back(*it);
                    } else {
                        break;
                    }
                    it++;
                }

                cout << result.size();
                for (const auto& w : result) {
                    cout << " " << w;
                }
                cout << endl;

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

                vector<string> guess;
                guess.reserve(N);
                for (int i = 0; i < N; ++i) {
                    string w;
                    if (!(cin >> w)) finish(_wa, "Failed to read answer words");
                    guess.push_back(w);
                }

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

                if (guess.size() != dict.size()) finish(_wa, "Incorrect number of words");

                bool correct = true;
                if (guess.size() != dict.size()) correct = false;
                else {
                    for (size_t i = 0; i < dict.size(); ++i) {
                        if (guess[i] != dict[i]) {
                            correct = false;
                            break;
                        }
                    }
                }

                if (!correct) {
                    finish(_wa, "Incorrect dictionary guessed");
                }

                case_active = false;

            } else {

                finish(_wa, "Unknown command token: " + type);
            }
        }
    }

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

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

using namespace std;

static long long max_queries_usage = 0;
static const long long QUERY_LIMIT = 3800;

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

    }
}

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 T = inf.readInt();
    cout << T << endl;

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

        int N = inf.readInt();
        cout << N << endl;

        cout.flush();

        string firstToken = inf.readToken();

        vector<string> hidden_words;

        if (isdigit(firstToken[0])) {

            long long seed_val = stoll(firstToken);
            string charset = inf.readToken();

            rnd.setSeed(seed_val);
            set<string> distinct_words;
            int attempts = 0;

            while ((int)distinct_words.size() < N && attempts < 200000) {
                attempts++;
                int strategy = rnd.next(0, 1);
                string cand = "";

                if (strategy == 0 && !distinct_words.empty()) {
                    auto it = distinct_words.begin();
                    advance(it, rnd.next((int)distinct_words.size()));
                    string base = *it;
                    if (base.length() < 10) {
                        cand = base + charset[rnd.next((int)charset.size())];
                    }
                }

                if (cand == "") {
                    int len = rnd.next(1, 10);

                    if (rnd.next(5) == 0) len = rnd.next(1, 4);

                    for (int i = 0; i < len; ++i) {
                        cand += charset[rnd.next((int)charset.size())];
                    }
                }

                distinct_words.insert(cand);
            }

            if ((int)distinct_words.size() < N) {
                string full_charset = "abcdefghijklmnopqrstuvwxyz";
                while ((int)distinct_words.size() < N) {
                    string s = "";
                    int len = rnd.next(4, 10);
                    for(int k=0; k<len; ++k) s += full_charset[rnd.next(26)];
                    distinct_words.insert(s);
                }
            }

            hidden_words.assign(distinct_words.begin(), distinct_words.end());

        } else {

            hidden_words.push_back(firstToken);
            for (int i = 1; i < N; ++i) {
                hidden_words.push_back(inf.readToken());
            }
        }

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

        long long current_k_sum = 0;

        while (true) {
            string type;
            if (!(cin >> type)) {
                finish(_wa, "Unexpected EOF waiting for command");
            }

            if (type == "query") {
                string S;
                int K;
                if (!(cin >> S >> K)) {
                    finish(_wa, "Invalid query arguments");
                }

                if (S.length() < 1 || S.length() > 10) finish(_wa, "Prefix length must be 1-10");
                if (K < 1 || K > N) finish(_wa, "K must be between 1 and N");

                current_k_sum += K;
                max_queries_usage = max(max_queries_usage, current_k_sum);

                log_metrics();

                if (current_k_sum > QUERY_LIMIT) {
                    finish(_wa, "Sum of K exceeded limit (3800)");
                }

                vector<string> result;
                int count = 0;
                for (const string& w : hidden_words) {

                    if (w.size() >= S.size() && w.compare(0, S.size(), S) == 0) {
                        result.push_back(w);
                        count++;

                        if (count >= K) break;
                    }
                }

                cout << result.size();
                for (const string& w : result) {
                    cout << " " << w;
                }
                cout << endl;

            } else if (type == "answer") {
                vector<string> user_ans;
                string w;
                for (int i = 0; i < N; ++i) {
                    if (!(cin >> w)) finish(_wa, "Not enough words in answer");
                    user_ans.push_back(w);
                }

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

                if (user_ans != hidden_words) {
                    finish(_wa, "Incorrect set of words");
                }

                break;

            } else {
                finish(_wa, "Unknown command: " + type);
            }
        }
    }

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

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

using namespace std;

string gen_word(int len, const string& charset) {
    string s = "";
    for (int i = 0; i < len; ++i) {
        s += charset[rnd.next((int)charset.size())];
    }
    return s;
}

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

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

    long long seed_val = 0;
    if (argc > 1) {
        try {
            seed_val = stoll(string(argv[1]));
        } catch (...) {
            seed_val = 0;
        }
    }

    int T = 1;
    cout << T << "\n";

    int N;
    string charset = "abcdefghijklmnopqrstuvwxyz";
    int strategy = 0;

    if (seed_val == 1) {

        N = 5;
        strategy = 0;
    } else if (seed_val == 2) {

        N = 1000;
        strategy = 0;
    } else if (seed_val == 3) {

        N = 1000;
        charset = "ab";
        strategy = 1;
    } else if (seed_val == 4) {

        N = 1000;
        charset = "abc";
        strategy = 2;
    } else {

        N = rnd.next(900, 1000);
        if (rnd.next(10) == 0) N = rnd.next(1, 100);

        int type = rnd.next(5);
        if (type == 0) charset = "abcdefghijklmnopqrstuvwxyz";
        else if (type == 1) charset = "ab";
        else if (type == 2) charset = "abcde";
        else if (type == 3) {

            string all = "abcdefghijklmnopqrstuvwxyz";
            shuffle(all.begin(), all.end());
            charset = all.substr(0, rnd.next(1, 10));
        } else {

            charset = "az";
        }

        if (charset.size() <= 2) strategy = 1;
        else if (rnd.next(3) == 0) strategy = 2;
        else strategy = 0;
    }

    cout << N << "\n";

    if (mode == "adp") {

        cout << rnd.next(1, 2000000000) << " " << charset << "\n";
        return 0;
    }

    set<string> words;
    int max_attempts = N * 500;
    int attempts = 0;

    while ((int)words.size() < N && attempts < max_attempts) {
        attempts++;

        if (strategy == 2) {

            string base = "";
            if (!words.empty() && rnd.next(3) != 0) {
                auto it = words.begin();
                std::advance(it, rnd.next((int)words.size()));
                base = *it;
            }
            if (base.length() < 10) {
                base += charset[rnd.next((int)charset.size())];
                words.insert(base);
            }
        } else {

            int len;
            if (charset.size() <= 2) len = rnd.next(5, 10);
            else len = rnd.next(1, 10);

            if (rnd.next(10) == 0) len = rnd.next(1, 4);

            words.insert(gen_word(len, charset));
        }
    }

    if ((int)words.size() < N) {
        string full_charset = "abcdefghijklmnopqrstuvwxyz";
        while ((int)words.size() < N) {
            words.insert(gen_word(rnd.next(4, 10), full_charset));
        }
    }

    vector<string> result(words.begin(), words.end());
    shuffle(result.begin(), result.end());

    for (int i = 0; i < N; ++i) {
        cout << result[i] << (i == N - 1 ? "" : " ");
    }
    cout << "\n";

    return 0;
}


Alessia and Bernardo are discovering the world of competitive programming through the books of their university library.

The library consists of $m$ sections numbered from 1 to $m$ . Each section contains only books dedicated to a particular subject and different sections correspond to different subjects. In order to prevent the students from wandering in the library, the university has established a system of passes. Each pass has a length $y$ associated to it and allows access to an interval of $y$ consecutive sections in the library. During a visit, the student must choose exactly one book from one of these sections and leave the library. Each pass can be used only once.

At the moment Alessia and Bernardo have $n$ passes of lengths $x _ { 1 }$ , $x _ { 2 }$ , . . . , $x _ { n }$ . They have different opinions on the best way to improve: Alessia thinks that it is important to study many different topics, while Bernardo believes that it is important to study deeply at least one topic. So, Alessia wants to use the $n$ passes to get $n$ books on distinct topics, while Bernardo would like to get at least two books on the same topic.

They have reached the following agreement: for each of the following $n$ days, Alessia will choose a pass of length $y$ among those which are still available and an interval of $y$ sections in the library, and Bernardo will go into the library and will take exactly one book from one of those sections.

Can Bernardo manage to get at least two books on the same subject, or will Alessia be able to avoid it?

You should decide whether you want to be Alessia or Bernardo, and you have to fulfill the goal of your chosen character. The judge will impersonate the other character. Note that, even if at some moment Bernardo has already taken two books on the same subject, the interaction should go on until the end of the $n$ days.

# Input

The first line contains two integers $n$ and $m$ ( $1 \leq n \leq 1 0 0$ , $n \leq m \leq 5 0 0 0$ ) — the number of passes and the number of sections.

The second line contains $n$ integers $x _ { 1 }$ , $x _ { 2 }$ , . . . , $x _ { n }$ $\mathrm { ~ 1 ~ } \leq x _ { i } \leq m$ ) — the lengths of the passes available.

# Interaction

First, you should print a line containing either the string Alessia or the string Bernardo — the character that you want to impersonate.

Then, for each of the $n$ turns:

• If you are taking the role of Alessia, print a single line consisting of two integers $y$ and $a$ ( $1 \leq a \leq m - y + 1 )$ — you are choosing a pass of length $y$ and the interval of sections $[ a , a + y - 1 ]$ . Note that at least one pass of length $y$ must still be available. After this, read a single integer $b$ $a \leq b \leq a + y - 1 ,$ ) — the subject of the book selected by Bernardo.

• If you are taking the role of Bernardo, read two integers $y$ and $a$ ( $1 \leq a \leq m - y + 1$ ) — the length of the pass chosen by Alessia and the index of the first section of the interval. It is guaranteed that there is at least one pass of length $y$ available. Then, print a line consisting of a single integer $b$ $a \leq b \leq a + y - 1 _ { \mathit { \cdot } }$ ) — the subject from which you choose to take a book.

If one of your interactions is malformed, the interactor terminates immediately and your program receives the verdict WRONG-ANSWER. Otherwise, you will receive the verdict according to the game’s criteria described above.

After printing a line do not forget to end the line and flush the output. Otherwise, you will get the verdict TIMELIMIT. To flush the output, use:

• fflush(stdout) in C;
• fflush(stdout), cout << flush or cout.flush() in $\mathrm { C } + +$ ;
• System.out.flush() in Java and Kotlin;
• sys.stdout.flush() in Python.

# Samples

Sample input 1	Sample output 1

514 372310

# Explanation of sample 1.

It can be shown that Alessia can accomplish her goal. An example of interaction (after reading the input) follows:

Contestant	Judge	Explanation

Alessia		The program will act as Alessia

311		Choose y = 3 and a = 11

	13	Judge selects b= 13

102		Choose y = 10 and a= 2

	9	Judge selects b = 9

71		Choose y= 7 and a = 1

	4	Judge selects b = 4

210		Choose y = 2 and a = 10

	10	Judge selects b = 10

36		Choose y= 3 and a = 6

	7	Judge selects b = 7

The program of the contestant wins because all the books chosen by Bernardo pertain to different topics. The actions performed by the contestant and the judge in this example of interaction may be non-optimal.

Sample input 2	Sample output 2

410

4164

# Explanation of sample 2.

It can be shown that Bernardo can manage to fulfil his goal. An example of interaction (after reading the input) follows:

Contestant	Judge	Explanation

Bernardo		The program will act as Bernardo

	41	Judge chooses y = 4 and a = 1

4		Select b= 4

	110	Judge chooses y = 1 and a = 10

10		Select b=10

	63	Judge chooses y = 6 and a = 3

4		Select b=4

	45	Judge chooses y = 4 and a = 5

8		Select b = 8

The program of the contestant wins because Bernardo has selected two books on topic number 4. The actions performed by the contestant and the judge in this example of interaction may be non-optimal.

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

struct Gap {
    int L, R;
    int len() const { return R - L + 1; }
};

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

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

    int n = inf.readInt();
    int m = inf.readInt();
    vector<int> x(n);
    map<int, int> available_passes;
    for (int i = 0; i < n; ++i) {
        x[i] = inf.readInt();
        available_passes[x[i]]++;
    }

    query_limit = n;

    cout << n << " " << m << endl;
    for (int i = 0; i < n; ++i) {
        cout << x[i] << (i == n - 1 ? "" : " ");
    }
    cout << endl;

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

    string role_lower = role;
    transform(role_lower.begin(), role_lower.end(), role_lower.begin(), ::tolower);

    bool contestant_is_alessia = false;
    if (role_lower == "alessia") {
        contestant_is_alessia = true;
    } else if (role_lower == "bernardo") {
        contestant_is_alessia = false;
    } else {
        finish(_wa, "Invalid role: " + role);
    }

    vector<bool> topic_used(m + 1, false);

    vector<int> sorted_passes = x;
    sort(sorted_passes.rbegin(), sorted_passes.rend());
    vector<Gap> gaps;
    gaps.push_back({1, m});

    for (int turn = 0; turn < n; ++turn) {
        queries = turn + 1;

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

        if (contestant_is_alessia) {

            int y, a;
            if (!(cin >> y >> a)) {
                finish(_wa, "Failed to read move (y a) on turn " + to_string(turn + 1));
            }

            if (available_passes.find(y) == available_passes.end() || available_passes[y] <= 0) {
                finish(_wa, "Pass length " + to_string(y) + " not available or invalid");
            }
            available_passes[y]--;

            if (a < 1 || a + y - 1 > m) {
                finish(_wa, "Interval [" + to_string(a) + ", " + to_string(a + y - 1) +
                            "] out of bounds [1, " + to_string(m) + "]");
            }

            int chosen_b = -1;
            for (int k = a; k < a + y; ++k) {
                if (topic_used[k]) {
                    chosen_b = k;
                    break;
                }
            }
            if (chosen_b == -1) {
                chosen_b = a;
            }

            topic_used[chosen_b] = true;
            cout << chosen_b << endl;

        } else {

            int y = sorted_passes[turn];

            int best_gap_idx = -1;
            int min_len = m + 2;

            for (int i = 0; i < (int)gaps.size(); ++i) {
                if (gaps[i].len() >= y) {
                    if (gaps[i].len() < min_len) {
                        min_len = gaps[i].len();
                        best_gap_idx = i;
                    }
                }
            }

            int a;
            if (best_gap_idx != -1) {

                a = gaps[best_gap_idx].L;
            } else {

                a = 1;
            }

            cout << y << " " << a << endl;

            int b;
            if (!(cin >> b)) {
                finish(_wa, "Failed to read response b on turn " + to_string(turn + 1));
            }

            if (b < a || b > a + y - 1) {
                finish(_wa, "Response b=" + to_string(b) + " not in interval [" +
                            to_string(a) + ", " + to_string(a + y - 1) + "]");
            }

            topic_used[b] = true;

            gaps.clear();
            int current_L = -1;
            for (int i = 1; i <= m; ++i) {
                if (!topic_used[i]) {
                    if (current_L == -1) current_L = i;
                } else {
                    if (current_L != -1) {
                        gaps.push_back({current_L, i - 1});
                        current_L = -1;
                    }
                }
            }
            if (current_L != -1) {
                gaps.push_back({current_L, m});
            }
        }
    }

    int distinct_books = 0;
    for (int i = 1; i <= m; ++i) {
        if (topic_used[i]) distinct_books++;
    }

    bool alessia_won = (distinct_books == n);
    bool bernardo_won = !alessia_won;

    if (contestant_is_alessia) {
        if (alessia_won) {
            finish(_ok, "Contestant (Alessia) won: all topics distinct");
        } else {
            finish(_wa, "Contestant (Alessia) lost: duplicates found");
        }
    } else {
        if (bernardo_won) {
            finish(_ok, "Contestant (Bernardo) won: duplicate topics found");
        } else {
            finish(_wa, "Contestant (Bernardo) lost: all topics distinct");
        }
    }

    return 0;
}

#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 n, m;
multiset<int> available_passes;
set<int> used_books;

void run_judge_bernardo() {
    for (int turn = 0; turn < n; turn++) {

        int y;
        if (!(cin >> y)) finish(_wa, "Unexpected end of input (reading y)");
        int a;
        if (!(cin >> a)) finish(_wa, "Unexpected end of input (reading a)");

        queries++;
        log_metrics();

        auto it = available_passes.find(y);
        if (it == available_passes.end()) {
            finish(_wa, format("Contestant used pass length %d which is not available", y));
        }
        available_passes.erase(it);

        if (a < 1 || a > m - y + 1) {
            finish(_wa, format("Contestant interval start %d is invalid for length %d with m=%d", a, y, m));
        }

        int choice = -1;
        for (int book : used_books) {
            if (book >= a && book <= a + y - 1) {
                choice = book;
                break;
            }
        }

        if (choice == -1) {
            choice = a;
        }

        cout << choice << endl;
        used_books.insert(choice);
    }

    if (used_books.size() < n) {

        finish(_wa, "Bernardo (Judge) collected duplicates. Alessia (Contestant) lost.");
    } else {

        finish(_ok, "Bernardo (Judge) collected n distinct books. Alessia (Contestant) won.");
    }
}

void run_judge_alessia() {

    vector<int> passes(available_passes.begin(), available_passes.end());
    sort(passes.rbegin(), passes.rend());

    for (int turn = 0; turn < n; turn++) {
        int y = passes[turn];

        int chosen_a = -1;

        for (int a = 1; a <= m - y + 1; a++) {
            bool conflict = false;

            auto it = used_books.lower_bound(a);
            if (it != used_books.end() && *it <= a + y - 1) {
                conflict = true;
            }

            if (!conflict) {
                chosen_a = a;
                break;
            }
        }

        if (chosen_a == -1) {

            chosen_a = 1;
        }

        cout << y << " " << chosen_a << endl;

        int b;
        if (!(cin >> b)) finish(_wa, "Unexpected end of input (reading b)");

        queries++;
        log_metrics();

        if (b < chosen_a || b > chosen_a + y - 1) {
            finish(_wa, format("Contestant chosen book %d is outside interval [%d, %d]", b, chosen_a, chosen_a + y - 1));
        }

        used_books.insert(b);
    }

    if (used_books.size() < n) {

        finish(_ok, "Bernardo (Contestant) managed to find duplicates. Won.");
    } else {

        finish(_wa, "Bernardo (Contestant) failed to find duplicates. Lost.");
    }
}

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

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

    n = inf.readInt(1, 100, "n");
    m = inf.readInt(n, 5000, "m");
    vector<int> x = inf.readInts(n, 1, m, "x");
    for (int val : x) available_passes.insert(val);

    query_limit = n;
    log_metrics();

    cout << n << " " << m << endl;
    for (int i = 0; i < n; i++) {
        cout << x[i] << (i == n - 1 ? "" : " ");
    }
    cout << endl;

    string role;
    if (!(cin >> role)) finish(_wa, "Failed to read role");

    if (role == "Alessia") {
        run_judge_bernardo();
    } else if (role == "Bernardo") {
        run_judge_alessia();
    } else {
        finish(_wa, "Invalid role '" + role + "'. Expected 'Alessia' or 'Bernardo'.");
    }

    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_val = -1;
    if (argc > 1) {
        try {
            seed_val = stoll(argv[1]);
        } catch (...) {
            seed_val = -1;
        }
    }

    int n, m;
    vector<int> x;

    if (seed_val == 1) {
        cout << "5 14" << endl;
        cout << "3 7 2 3 10" << endl;
        return 0;
    }

    if (seed_val == 2) {
        cout << "4 10" << endl;
        cout << "4 1 6 4" << endl;
        return 0;
    }

    if (seed_val == 3) {

        n = 100;
        m = 5000;
        x.assign(n, m);
    } else if (seed_val == 4) {

        n = 100;
        m = 5000;
        x.assign(n, 1);
    } else if (seed_val == 5) {

        n = 100;
        m = 100;
        x.assign(n, 1);
    } else {

        int min_n = 1, max_n = 100;
        int max_m = 5000;

        if (rnd.next(10) == 0) {
            max_n = 10;
            max_m = 50;
        }

        n = rnd.next(min_n, max_n);

        int m_strat = rnd.next(3);
        int upper_bound_m = max_m;

        if (m_strat == 0) {
            upper_bound_m = min((long long)max_m, (long long)n * 2);
        } else if (m_strat == 1) {
            upper_bound_m = min((long long)max_m, (long long)n * 10);
        }

        m = rnd.next(n, upper_bound_m);

        x.resize(n);
        for (int i = 0; i < n; i++) {

            int x_strat = rnd.next(10);
            if (x_strat < 3) {
                int limit = max(1, m / max(1, n));
                x[i] = rnd.next(1, limit);
            } else if (x_strat < 5) {
                int start = max(1, m / 2);
                x[i] = rnd.next(start, m);
            } else {
                x[i] = rnd.next(1, m);
            }
        }

        shuffle(x.begin(), x.end());
    }

    if (mode == "adp") {

    }

    println(n, m);
    println(x);

    return 0;
}


This is an interactive problem.

Returning from a restful vacation on Australia's Gold Coast, Penchick forgot to bring home gifts for his pet duck Duong Canh! But perhaps a beautiful problem crafted through deep thought on the scenic beaches could be the perfect souvenir.

There is a hidden permutation$^{\text{∗}}$ $p$ of length $n$, where $n$ is even. You are allowed to make the following query:

* Choose a subsequence$^{\text{†}}$ of the permutation $p$ with even length $4\le k\le n$. The interactor will return the value of the two medians$^{\text{‡}}$ in the chosen subsequence.

Find the index of the two medians in permutation $p$ using at most $80$ queries.

Note that the interactor is non-adaptive. This means that the permutation $p$ is fixed at the beginning and will not change based on your queries.

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).

$^{\text{†}}$A sequence $a$ is a subsequence of a sequence $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) element from arbitrary positions.

$^{\text{‡}}$The two medians of an array $a$ with even length $k$ are defined as the $\frac{k}{2}$-th and $\left(\frac{k}{2} + 1\right)$-th smallest element in the array ($1$-indexed).

Input

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

The only line of each test case contains a single integer $n$ ($6 \le n \le 100$, $n$ is even) — the length of the hidden permutation $p$.

For each test case, after reading the integer $n$, you should begin the interaction and find the answer before reading $n$ for the next test case.

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

Interaction

To make a query, print a single line in the following format:

* $\mathtt{?}\;k\;x_1\;x_2 \ldots x_{k-1}\;x_k$ ($4\le k\le n$, $k$ is even, $1 \le x_i \le n$, $x_i$ is pairwise distinct) — the length of the chosen subsequence followed by the indices of the chosen subsequence.

After each query, you should read a line containing two integers $m_1$ and $m_2$ ($1 \le m_1 < m_2 \le n$) — the value of the two medians in array $[p_{x_1}, p_{x_2}, \ldots, p_{x_{k-1}}, p_{x_k}]$.

You can make at most $80$ such queries in each test case.

To give the final answer, print a single line in the following format:

* $\mathtt{!}\;i_1\;i_2$ ($1\le i_1, i_2 \le n$) — the index of the two medians.

Note that the order in which $i_1$ and $i_2$ is printed does not matter. In other words, your solution is valid as long as $p_{i_1} = \frac{n}{2}$ and $p_{i_2} = \frac{n}{2} + 1$, or $p_{i_1} = \frac{n}{2} + 1$ and $p_{i_2} = \frac{n}{2}$.

After printing each query do not forget to output the end of line and flush$^{\text{∗}}$ the output. Otherwise, you will get Idleness limit exceeded verdict.

If, at any interaction step, you read $-1$ instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

Example

Input

```
2
6

3 4

3 4

2 3

10

3 4

6 7
```

Output

```
? 6 1 2 3 4 5 6

? 4 3 6 1 5

? 4 3 6 2 5

! 3 6

? 6 1 3 7 8 9 10

? 8 1 2 3 4 5 6 7 8

! 6 5
```

Note

In the first test case, the hidden permutation is $p = [6, 2, 3, 5, 1, 4]$.

1. The entire permutation was chosen for the first query. The two medians of the entire permutation $p$ are $3$ and $4$.
2. The indices of the chosen subsequence in the second query are $3$, $6$, $1$, and $5$. The interactor returns the two medians of the subsequence $[p_3, p_6, p_1, p_5] = [3, 4, 6, 1]$, which are $3$ and $4$.
3. The indices of the chosen subsequence in the second query are $3$, $6$, $2$, and $5$. The interactor returns the two medians of the subsequence $[p_3, p_6, p_2, p_5] = [3, 4, 2, 1]$, which are $2$ and $3$.

The answer "! 3 6" is valid as $p_3 = 3$ and $p_6 = 4$.

In the second test case, the hidden permutation is $p = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]$.

1. The indices of the chosen subsequence in the second query are $1$, $3$, $7$, $8$, $9$, and $10$. The interactor returns the two medians of the subsequence $[p_1, p_3, p_7, p_8, p_9, p_{10}] = [10, 8, 4, 3, 2, 1]$, which are $3$ and $4$.
2. The indices of the chosen subsequence in the second query are $1$, $2$, $3$, $4$, $5$, $6$, $7$, and $8$. The interactor returns the two medians of the subsequence $[p_1, p_2, p_3, p_4, p_5, p_6, p_7, p_8] = [10, 9, 8, 7, 6, 5, 4, 3]$, which are $6$ and $7$.

The answer "! 5 6" is valid as $p_5 = 6$ and $p_6 = 5$.

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

static bool isIntegerToken(const string& s) {
    if (s.empty()) return false;
    int i = 0;
    if (s[0] == '-') {
        if ((int)s.size() == 1) return false;
        i = 1;
    }
    for (; i < (int)s.size(); ++i) if (!isdigit((unsigned char)s[i])) return false;
    return true;
}

static bool readToken(string& tok) {
    if (!(cin >> tok)) return false;
    return true;
}

static bool readLongLong(long long& x) {
    string tok;
    if (!readToken(tok)) return false;
    if (!isIntegerToken(tok)) return false;
    try {
        size_t pos = 0;
        long long v = stoll(tok, &pos);
        if (pos != tok.size()) return false;
        x = v;
        return true;
    } catch (...) {
        return false;
    }
}

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

    int t = 0;
    t = inf.readInt(1, 1000, "t");

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

    log_metrics();

    vector<int> ns(t);
    vector<vector<int>> perms(t);
    for (int tc = 0; tc < t; ++tc) {
        int n = inf.readInt(6, 100, "n");
        ensuref(n % 2 == 0, "n must be even");
        ns[tc] = n;
        perms[tc].assign(n + 1, 0);
        vector<int> seen(n + 1, 0);
        for (int i = 1; i <= n; ++i) {
            int v = inf.readInt(1, n, "p[i]");
            ensuref(!seen[v], "Permutation contains duplicates");
            seen[v] = 1;
            perms[tc][i] = v;
        }
    }

    cout << t << endl;

    for (int tc = 0; tc < t; ++tc) {
        int n = ns[tc];
        const auto& p = perms[tc];
        int needA = n / 2;
        int needB = needA + 1;

        cout << n << endl;

        bool answered = false;
        while (!answered) {
            string cmd;
            if (!readToken(cmd)) {
                finish(_pe, "Unexpected EOF from contestant");
            }

            if (cmd == "?") {
                long long kll = 0;
                if (!readLongLong(kll)) finish(_pe, "Malformed query: missing/invalid k");
                if (kll < 0 || kll > 1000000) finish(_pe, "Malformed query: k out of sane bounds");
                int k = (int)kll;

                if (k < 4 || k > n || (k % 2 != 0)) finish(_pe, "Invalid query: k must be even and in [4,n]");

                vector<int> idx(k);
                vector<char> used(n + 1, 0);
                for (int i = 0; i < k; ++i) {
                    long long xll = 0;
                    if (!readLongLong(xll)) finish(_pe, "Malformed query: missing/invalid index");
                    if (xll < 1 || xll > n) finish(_pe, "Invalid query: index out of range");
                    int x = (int)xll;
                    if (used[x]) finish(_pe, "Invalid query: duplicate indices");
                    used[x] = 1;
                    idx[i] = x;
                }

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

                vector<int> vals;
                vals.reserve(k);
                for (int x : idx) vals.push_back(p[x]);
                nth_element(vals.begin(), vals.begin() + (k / 2) - 1, vals.end());
                int m1 = vals[(k / 2) - 1];
                nth_element(vals.begin(), vals.begin() + (k / 2), vals.end());
                int m2 = vals[(k / 2)];
                if (m1 > m2) swap(m1, m2);

                cout << m1 << " " << m2 << endl;
            } else if (cmd == "!") {
                long long i1ll = 0, i2ll = 0;
                if (!readLongLong(i1ll) || !readLongLong(i2ll)) finish(_pe, "Malformed answer: need two indices");
                if (i1ll < 1 || i1ll > n || i2ll < 1 || i2ll > n) finish(_pe, "Answer indices out of range");
                int i1 = (int)i1ll, i2 = (int)i2ll;
                if (i1 == i2) finish(_wa, "Answer indices must be distinct");

                int v1 = p[i1], v2 = p[i2];
                bool ok = (v1 == needA && v2 == needB) || (v1 == needB && v2 == needA);
                if (!ok) finish(_wa, "Wrong median indices");
                answered = true;
            } else {
                finish(_pe, "Unknown command from contestant");
            }
        }
    }

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

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

static vector<int> buildAlternatingExtremes(int n, int ex1, int ex2) {
    vector<int> vals;
    vals.reserve(n - 2);
    int lo = 1, hi = n;
    while (lo <= hi) {
        if (hi != ex1 && hi != ex2) vals.push_back(hi);
        hi--;
        if (lo <= hi + 1) {
            if (lo != ex1 && lo != ex2) vals.push_back(lo);
            lo++;
        }
    }
    return vals;
}

static vector<int> buildTwoBlocks(int n, int ex1, int ex2) {
    vector<int> hiBlock, loBlock;
    hiBlock.reserve(n);
    loBlock.reserve(n);
    for (int v = n; v >= 1; --v) {
        if (v == ex1 || v == ex2) continue;
        if (v > ex2) hiBlock.push_back(v);
        else if (v < ex1) loBlock.push_back(v);
        else {
            if (v < ex1) loBlock.push_back(v);
        }
    }
    vector<int> vals;
    vals.reserve(n - 2);
    for (int v : hiBlock) vals.push_back(v);
    for (int v : loBlock) vals.push_back(v);
    for (int v = ex2 - 1; v >= ex1 + 1; --v) {
        if (v == ex1 || v == ex2) continue;
        vals.push_back(v);
    }
    return vals;
}

static vector<int> buildBitReverseLike(int n, int ex1, int ex2) {
    vector<int> vals;
    vals.reserve(n - 2);
    int bits = 0;
    while ((1 << bits) < n) bits++;
    vector<int> used(n + 1, 0);
    used[ex1] = used[ex2] = 1;

    auto bitrev = [&](int x) -> int {
        int y = 0;
        for (int b = 0; b < bits; ++b) {
            y = (y << 1) | ((x >> b) & 1);
        }
        return y;
    };

    vector<pair<int,int>> order;
    order.reserve(n);
    for (int v = 1; v <= n; ++v) {
        if (used[v]) continue;
        order.push_back({bitrev(v), v});
    }
    sort(order.begin(), order.end());
    for (auto &pr : order) vals.push_back(pr.second);
    return vals;
}

static void chooseMedianPositions(int n, const string& placeMode, int &posA, int &posB) {
    if (placeMode == "adj") {
        int i = rnd.next(1, n - 1);
        if (i == n) i = n - 1;
        if (i == n) i = n - 1;
        posA = i;
        posB = i + 1;
    } else if (placeMode == "far") {
        posA = 1;
        posB = n;
    } else if (placeMode == "ends") {
        posA = 1;
        posB = n;
    } else if (placeMode == "rand") {
        posA = rnd.next(1, n);
        do {
            posB = rnd.next(1, n);
        } while (posB == posA);
    } else {
        int t = rnd.next(1, 100);
        if (t <= 40) {
            int i = rnd.next(1, n - 1);
            posA = i;
            posB = i + 1;
        } else if (t <= 70) {
            posA = 1;
            posB = n;
        } else {
            posA = rnd.next(1, n);
            do {
                posB = rnd.next(1, n);
            } while (posB == posA);
        }
    }
    if (posA > posB) swap(posA, posB);
}

static vector<int> makePermutation(int n, int seed, int pattern, const string& placeMode) {
    int a = n / 2;
    int b = a + 1;

    int posA = 1, posB = n;
    chooseMedianPositions(n, placeMode, posA, posB);

    vector<int> remaining;
    if (pattern == 0) remaining = buildAlternatingExtremes(n, a, b);
    else if (pattern == 1) {
        remaining = buildAlternatingExtremes(n, a, b);

        int swaps = rnd.next(0, min(200, (int)remaining.size() * 3 + 5));
        for (int s = 0; s < swaps; ++s) {
            int i = rnd.next(0, (int)remaining.size() - 1);
            int j = rnd.next(0, (int)remaining.size() - 1);
            swap(remaining[i], remaining[j]);
        }
    } else if (pattern == 2) remaining = buildTwoBlocks(n, a, b);
    else remaining = buildBitReverseLike(n, a, b);

    int revs = rnd.next(0, 6);
    for (int r = 0; r < revs; ++r) {
        if ((int)remaining.size() <= 2) break;
        int L = rnd.next(0, (int)remaining.size() - 2);
        int R = rnd.next(L + 1, (int)remaining.size() - 1);
        reverse(remaining.begin() + L, remaining.begin() + R + 1);
    }

    vector<int> p(n + 1, 0);
    p[posA] = a;
    p[posB] = b;

    int idx = 0;
    for (int i = 1; i <= n; ++i) {
        if (i == posA || i == posB) continue;
        if (idx >= (int)remaining.size()) {

            vector<int> used(n + 1, 0);
            for (int j = 1; j <= n; ++j) if (p[j]) used[p[j]] = 1;
            for (int v = 1; v <= n; ++v) {
                if (!used[v]) {
                    p[i] = v;
                    used[v] = 1;
                    break;
                }
            }
        } else {
            p[i] = remaining[idx++];
        }
    }

    vector<int> seen(n + 1, 0);
    for (int i = 1; i <= n; ++i) {
        ensuref(1 <= p[i] && p[i] <= n, "Permutation out of range");
        ensuref(!seen[p[i]], "Duplicate value in permutation");
        seen[p[i]] = 1;
    }

    vector<int> out(n);
    for (int i = 1; i <= n; ++i) out[i - 1] = p[i];
    return out;
}

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

    string mode = opt<string>("mode", "non");
    int nOpt = opt<int>("n", -1);
    string placeMode = opt<string>("place", "mix");
    int patternOpt = opt<int>("pattern", -1);

    int seed = 1;
    if (argc >= 2) seed = atoi(argv[1]);

    int n = 0;
    vector<int> perm;

    if (seed == 1) {
        n = (nOpt != -1 ? nOpt : 6);
        ensuref(n % 2 == 0 && n >= 6 && n <= 100, "n must be even and in [6,100]");

        perm = {6, 3, 1, 5, 4, 2};
        if ((int)perm.size() != n) {
            perm = makePermutation(n, seed, 0, "rand");
        }
    } else if (seed == 2) {
        n = (nOpt != -1 ? nOpt : 100);
        ensuref(n % 2 == 0 && n >= 6 && n <= 100, "n must be even and in [6,100]");

        perm = makePermutation(n, seed, 0, "ends");
    } else if (seed == 3) {
        n = (nOpt != -1 ? nOpt : 10);
        ensuref(n % 2 == 0 && n >= 6 && n <= 100, "n must be even and in [6,100]");

        perm = makePermutation(n, seed, 2, "adj");
    } else {
        if (nOpt != -1) {
            n = nOpt;
            ensuref(n % 2 == 0 && n >= 6 && n <= 100, "n must be even and in [6,100]");
        } else {
            int half = rnd.next(3, 50);
            n = half * 2;
        }
        int pattern = patternOpt;
        if (pattern == -1) {
            int r = rnd.next(1, 100);
            if (r <= 45) pattern = 0;
            else if (r <= 70) pattern = 1;
            else if (r <= 85) pattern = 2;
            else pattern = 3;
        }
        perm = makePermutation(n, seed, pattern, placeMode);
    }

    cout << 1 << "\n";
    if (mode == "non") {
        cout << n << "\n";
        for (int i = 0; i < n; ++i) {
            if (i) cout << ' ';
            cout << perm[i];
        }
        cout << "\n";
    } else if (mode == "adp") {

        cout << n << "\n";
    } else {
        quitf(_fail, "Unknown mode: %s", mode.c_str());
    }

    return 0;
}