This is an interactive problem.

This is an easy version of the problem. The difference from the hard version is that in the easy version $t=1$ and the number of queries is limited to $20$.

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 $20$ requests 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.

In this (easy version) of the problem, this paragraph doesn't really make sense since $t=1$ always. 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$. Of course, this feature affects something only for $t>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$, $t=1$).

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 current value of $k$.

After that, you can make no more than $20$ requests.

Use the following format to output the answer (it is not a request, it doesn't count in $20$):

* ! $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 1
2

2

1

1

0

0
```

Output

```
? 4 6

? 1 1

? 1 2

? 2 2

? 5 5

! 5
```

Note

In the first test, the $[1, 0, 1, 1, 0, 1]$ array is hidden. In this test $k=2$.

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

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

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

    }
}

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

static bool readLongLongFromCin(long long &x) {
    if (!(cin >> x)) return false;
    return true;
}

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

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

    int n = 0, t = 0;
    try {
        n = inf.readInt(1, 200000, "n");
        t = inf.readInt(1, 200000, "t");
    } catch (...) {
        finish(_fail, "Failed to read n,t from input");
    }

    vector<int> rest;
    rest.reserve((size_t)n + (size_t)t + 5);
    try {
        while (!inf.seekEof()) rest.push_back(inf.readInt());
    } catch (...) {
        finish(_fail, "Failed to read remaining hidden input");
    }

    vector<int> a; a.reserve(n);
    vector<int> ks; ks.reserve(t);

    if ((int)rest.size() == n + t) {
        for (int i = 0; i < n; i++) {
            int v = rest[i];
            if (v != 0 && v != 1) finish(_fail, "Hidden array contains values other than 0/1");
            a.push_back(v);
        }
        for (int i = 0; i < t; i++) {
            int k = rest[n + i];
            if (k < 1 || k > n) finish(_fail, "k out of [1..n] in hidden input");
            ks.push_back(k);
        }
    } else if ((int)rest.size() == t) {
        finish(_fail, "Hidden input has no array (adaptive schema), non-adaptive interactor requires explicit array");
    } else {
        finish(_fail, "Unexpected number of tokens in hidden input");
    }

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

    auto onesSum = [&](int l, int r) -> int {
        return pref[r] - pref[l - 1];
    };

    auto kthZeroPosStatic = [&](int k) -> int {
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == 0) {
                cnt++;
                if (cnt == k) return i + 1;
            }
        }
        return -1;
    };

    int totalZeros = 0;
    for (int v : a) if (v == 0) totalZeros++;
    for (int k : ks) {
        if (k > totalZeros) finish(_fail, "Hidden k requests more zeros than exist in array");
    }

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

    int round = 0;
    if (t > 0) {
        cout << ks[0] << "\n";
        cout.flush();
    }

    while (round < t) {
        const int k = ks[round];
        const int correctPos = kthZeroPosStatic(k);
        if (correctPos == -1) finish(_fail, "Internal: could not find k-th zero");

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

            if (cmd == "?") {
                long long lll, rll;
                if (!readLongLongFromCin(lll) || !readLongLongFromCin(rll)) finish(_pe, "Malformed query: expected two integers after '?'");

                queries++;
                if (queries > hard_cap) finish(_pe, "Hard cap exceeded (too many queries), possible infinite loop");

                if (lll < 1 || rll < 1 || lll > rll || rll > n) {
                    cout << -1 << "\n";
                    cout.flush();
                    finish(_pe, "Invalid query range");
                }

                int l = (int)lll, r = (int)rll;
                int ans = onesSum(l, r);
                cout << ans << "\n";
                cout.flush();
            } else if (cmd == "!") {
                long long xll;
                if (!readLongLongFromCin(xll)) finish(_pe, "Malformed answer: expected integer after '!'");
                if (xll < 1 || xll > n) finish(_wa, "Answer position out of range");

                int x = (int)xll;
                if (x != correctPos) finish(_wa, "Wrong position of k-th zero");

                round++;
                if (round == t) finish(_ok, "OK");
                cout << ks[round] << "\n";
                cout.flush();
                break;
            } else {
                finish(_pe, "Unknown command (expected '?' or '!')");
            }
        }
    }

    finish(_ok, "OK");
    return 0;
}

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

struct NonCase {
    int n;
    int t;
    vector<int> a;
    int k;
};

static NonCase makeNonCaseCorner(int seed) {
    NonCase cs;
    cs.t = 1;
    if (seed == 1) {
        cs.n = 1;
        cs.a = {0};
        cs.k = 1;
        return cs;
    }
    if (seed == 2) {
        cs.n = 200000;
        cs.a.assign(cs.n, 1);
        cs.a.back() = 0;
        cs.k = 1;
        return cs;
    }

    cs.n = 200000;
    cs.a.resize(cs.n);

    for (int i = 0; i < cs.n; i++) cs.a[i] = (i % 2 == 0 ? 0 : 1);
    cs.k = cs.n / 2;
    return cs;
}

static NonCase makeNonCaseRandom(int nOpt, int kOpt) {
    NonCase cs;
    cs.t = 1;

    int n = nOpt;
    n = max(1, min(n, 200000));
    cs.n = n;

    int B = rnd.next(10, 40);
    if (B < 3) B = 3;

    int minFirst = max(1, n / 4);
    int maxFirst = max(1, n / 2);
    int firstLen = rnd.next(minFirst, maxFirst);

    int minLast = max(1, n / 4);
    int maxLast = max(1, n / 2);
    int lastLen = rnd.next(minLast, maxLast);

    int middleBlocks = B - 2;
    int minMiddleSum = middleBlocks;
    if (firstLen + lastLen + minMiddleSum > n) {

        int maxLastAllowed = n - firstLen - minMiddleSum;
        if (maxLastAllowed < 1) {

            firstLen = max(1, n - minMiddleSum - 1);
            maxLastAllowed = n - firstLen - minMiddleSum;
        }
        lastLen = max(1, maxLastAllowed);
    }
    int remaining = n - firstLen - lastLen;
    if (remaining < minMiddleSum) {

        firstLen = max(1, n / 2);
        lastLen = max(1, (n - firstLen) / 2);
        remaining = n - firstLen - lastLen;
        middleBlocks = max(1, n - firstLen - lastLen);
        B = middleBlocks + 2;
    }

    vector<int> lens;
    lens.reserve(B);
    lens.push_back(firstLen);

    int rem = remaining;
    for (int i = 0; i < middleBlocks - 1; i++) {
        int leftBlocks = (middleBlocks - 1) - i;
        int len = rnd.next(1, rem - leftBlocks);
        lens.push_back(len);
        rem -= len;
    }
    if (middleBlocks > 0) lens.push_back(rem);
    lens.push_back(lastLen);

    vector<int> a;
    a.reserve(n);
    for (int i = 0; i < (int)lens.size(); i++) {
        int val;
        if (i == 0) val = 1;
        else if (i == (int)lens.size() - 1) val = 0;
        else val = (i % 2 == 1 ? 0 : 1);
        for (int j = 0; j < lens[i]; j++) a.push_back(val);
    }
    if ((int)a.size() != n) {

        a.resize(n, 0);
    }

    int flips = max(1, n / 500);
    for (int i = 0; i < flips; i++) {
        int pos = rnd.next(0, n - 1);
        a[pos] ^= 1;
    }

    long long totalZeros = 0;
    for (int v : a) if (v == 0) totalZeros++;

    if (totalZeros == 0) {

        a[n - 1] = 0;
        totalZeros = 1;
    }
    cs.a = std::move(a);

    int k;
    if (kOpt > 0) {
        k = kOpt;
        if (k > (int)totalZeros) k = (int)totalZeros;
        if (k < 1) k = 1;
    } else {

        int maxDelta = (int)min<long long>(5000LL, totalZeros - 1);
        int delta = (maxDelta > 0 ? rnd.next(0, maxDelta) : 0);
        k = (int)totalZeros - delta;
        if (k < 1) k = 1;
    }
    cs.k = k;
    return cs;
}

static pair<int,int> makeAdpCaseCorner(int seed) {
    if (seed == 1) return {1, 1};
    if (seed == 2) return {200000, 1};
    return {200000, 100000};
}

static pair<int,int> makeAdpCaseRandom(int nOpt, int kOpt) {
    int n = nOpt;
    n = max(1, min(n, 200000));
    int k;
    if (kOpt > 0) {
        k = max(1, min(kOpt, n));
    } else {

        int coin = rnd.next(1, 100);
        if (coin <= 60) k = rnd.next(max(1, n - 5000), n);
        else if (coin <= 90) k = rnd.next(max(1, n / 2 - 5000), min(n, n / 2 + 5000));
        else k = rnd.next(1, n);
    }
    return {n, k};
}

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

    string mode = opt<string>("mode", "non");
    int nOpt = opt<int>("n", 200000);
    int kOpt = opt<int>("k", -1);

    int seed = 1;
    if (argc >= 2) {

        seed = atoi(argv[1]);
        if (seed <= 0) seed = 1;
    }

    if (mode == "non") {
        NonCase cs = (seed <= 3 ? makeNonCaseCorner(seed) : makeNonCaseRandom(nOpt, kOpt));

        cout << cs.n << " " << cs.t << "\n";
        for (int i = 0; i < cs.n; i++) {
            if (i) cout << ' ';
            cout << cs.a[i];
        }
        cout << "\n";
        cout << cs.k << "\n";
        return 0;
    } else if (mode == "adp") {
        auto [n, k] = (seed <= 3 ? makeAdpCaseCorner(seed) : makeAdpCaseRandom(nOpt, kOpt));
        int t = 1;
        cout << n << " " << t << "\n";
        cout << k << "\n";
        return 0;
    } else {
        quitf(_fail, "Unknown --mode '%s' (expected 'non' or 'adp')", mode.c_str());
    }
}


Alice was recently given a homework assignment to write a program that would output the number of inversions in any subarray of a given permutation. She happily turned it in and got full marks on her assignment. The next week, their homework assignment was to find the length of the longest increasing subsequences in the same array. Unfortunately, Alice had already thrown away the paper that contained the permutation she needed.

Luckily, this permutation was stored in the program she wrote. Unfortunately, she is now only able to query for the number of inversions in the subarrays of the permutation. As class is close to starting, she asks you for help to solve this problem in a timely manner.

A sequence $a$ is a subsequence of an array $b$ if it is possible to delete some (possibly zero) elements from $b$ to get $a$ . A sequence is increasing if every element is strictly greater than all preceding ones, and the LLIS of an array is the length of the longest increasing subsequence.

# Interaction

This is an interactive problem.

Interaction starts by reading a single integer $n$ $( 1 \leq n \leq 1 0 ^ { 3 }$ ), the length of the permutation $p$

You are then able to make at most $n$ queries of the form ? l r where $1 \leq l \leq r \leq n$ . Each query should be on a single line. After each query, read in a single integer, the number of inversions in the subarray $[ l , r ]$ . An inversion is a pair of integers $( x , y )$ where $l \leq x < y \leq r$ and $p _ { x } > p _ { y }$ .

When you have determined the LLIS, output the answer in the form: ! ans on a single line, where ans is the LLIS. After outputting the answer, your program should exit. If you attempt to read a response after outputting an answer, you will receive an arbitrary verdict.

Do not forget to flush the output after each query you output.

The interactor is not adaptive: When the interaction begins, the permutation $p$ is already determined. It is guaranteed that each integer from 1 to $n$ appears exactly once.

If the interactor receives any invalid or unexpected input, the interactor will output $- 1$ and then immediately terminate. Your program should cleanly exit in order to receive a Wrong Answer verdict, otherwise the verdict that it receives may be an arbitrary verdict indicating that your submission is incorrect.

If your program terminates before outputting the answer, your submission will receive an arbitrary verdict indicating that your submission is incorrect.

You are provided with a command-line tool for local testing. The tool has comments at the top to explain its use.

# Read

Write

Sample Interaction 1

3

	？13

1

	？12

1

	！2

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

using namespace std;

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

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 calc_llis(const vector<int>& p) {
    if (p.empty()) return 0;
    vector<int> tails;
    for (int x : p) {
        auto it = lower_bound(tails.begin(), tails.end(), x);
        if (it == tails.end()) {
            tails.push_back(x);
        } else {
            *it = x;
        }
    }
    return (int)tails.size();
}

long long count_inversions(const vector<int>& sub) {
    if (sub.empty()) return 0;
    int max_val = 0;
    for (int x : sub) max_val = max(max_val, x);

    vector<int> bit(max_val + 1, 0);

    auto update = [&](int idx, int val) {
        for (; idx <= max_val; idx += idx & -idx) bit[idx] += val;
    };

    auto query = [&](int idx) {
        int res = 0;
        for (; idx > 0; idx -= idx & -idx) res += bit[idx];
        return res;
    };

    long long inv_count = 0;
    for (size_t i = 0; i < sub.size(); ++i) {
        int x = sub[i];

        inv_count += (i - query(x));
        update(x, 1);
    }
    return inv_count;
}

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

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

    int n = inf.readInt(1, 1000, "n");
    vector<int> p(n);
    vector<bool> seen(n + 1, false);
    for (int i = 0; i < n; ++i) {
        p[i] = inf.readInt(1, n, format("p[%d]", i));
        if (seen[p[i]]) {
            finish(_fail, format("Duplicate value %d in permutation", p[i]));
        }
        seen[p[i]] = true;
    }

    query_limit = n;

    int hard_cap = max(2000, n * 5);

    cout << n << endl;

    while (true) {
        string token;

        if (!(cin >> token)) {
            finish(_wa, "Unexpected EOF: Contestant terminated without providing an answer");
        }

        if (token == "!") {

            int ans;
            if (!(cin >> ans)) {
                finish(_wa, "Failed to read integer answer after '!'");
            }

            int expected = calc_llis(p);
            if (ans == expected) {
                finish(_ok, format("Correct. LLIS is %d.", ans));
            } else {
                finish(_wa, format("Wrong answer. Expected %d, found %d.", expected, ans));
            }
        } else {

            int l, r;
            if (token == "?") {

                if (!(cin >> l >> r)) {
                    finish(_wa, "Failed to read query parameters l r after '?'");
                }
            } else {

                try {
                    size_t idx = 0;
                    l = stoi(token, &idx);
                    if (idx != token.size()) {
                        cout << -1 << endl;
                        finish(_wa, "Invalid token format: " + token);
                    }
                } catch (...) {
                    cout << -1 << endl;
                    finish(_wa, "Invalid token (expected integer or '?'): " + token);
                }

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

            queries++;

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

            if (l < 1 || l > n || r < 1 || r > n || l > r) {
                cout << -1 << endl;
                finish(_wa, format("Query range [%d, %d] is invalid (n=%d)", l, r, n));
            }

            if (queries > hard_cap) {
                finish(_pe, format("Query hard cap (%d) exceeded. Limit was %d.", hard_cap, query_limit));
            }

            vector<int> sub;
            sub.reserve(r - l + 1);
            for (int i = l - 1; i < r; ++i) {
                sub.push_back(p[i]);
            }
            long long result = count_inversions(sub);

            cout << result << endl;
        }
    }

    return 0;
}

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

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

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

    long long seed_num = -1;
    try {
        string s = argv[1];
        if (!s.empty() && all_of(s.begin(), s.end(), ::isdigit)) {
            seed_num = stoll(s);
        }
    } catch (...) {
        seed_num = -1;
    }

    int n;
    vector<int> p;

    if (seed_num >= 1 && seed_num <= 3) {
        if (seed_num == 1) {
            n = 1;
            p = {1};
        } else if (seed_num == 2) {
            n = 5;
            p = {1, 2, 3, 4, 5};
        } else {
            n = 5;
            p = {5, 4, 3, 2, 1};
        }
    } else {

        if (n_opt != -1) {
            n = n_opt;
        } else {

            if (rnd.next(3) == 0) n = rnd.next(1, 100);
            else n = rnd.next(900, 1000);
        }

        p.resize(n);
        iota(p.begin(), p.end(), 1);

        int type = rnd.next(1, 5);
        if (type == 1) {

            shuffle(p.begin(), p.end());
        } else if (type == 2) {

            int k = rnd.next(0, (int)sqrt(n) + 2);
            for(int i = 0; i < k; ++i) {
                int a = rnd.next(n);
                int b = rnd.next(n);
                swap(p[a], p[b]);
            }
        } else if (type == 3) {

            reverse(p.begin(), p.end());
            int k = rnd.next(0, (int)sqrt(n) + 2);
            for(int i = 0; i < k; ++i) {
                int a = rnd.next(n);
                int b = rnd.next(n);
                swap(p[a], p[b]);
            }
        } else if (type == 4) {

            p.clear();
            int base_k = (int)sqrt(n);
            if (base_k < 1) base_k = 1;
            int cur = 1;
            while (cur <= n) {
                int rem = n - cur + 1;

                int sz = rnd.next(1, min(rem, max(2, base_k * 2)));

                for (int i = 0; i < sz; ++i) {
                    p.push_back(cur + sz - 1 - i);
                }
                cur += sz;
            }

            int swaps = rnd.next(0, 5);
            for(int i = 0; i < swaps; ++i) swap(p[rnd.next(n)], p[rnd.next(n)]);
        } else {

            int l = rnd.next(0, n - 1);
            int r = rnd.next(0, n - 1);
            if (l > r) swap(l, r);
            reverse(p.begin() + l, p.begin() + r + 1);
        }
    }

    if (mode == "non") {

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

        cout << n << endl;
    }

    return 0;
}


This problem is different with easy version only by constraints on total answers length

It is an interactive problem

Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string $s$ of length $n$, consisting only of lowercase English letters. The player can ask two types of queries:

* ? l r – ask to list all substrings of $s[l..r]$. Substrings will be returned in random order, and in every substring, all characters will be randomly shuffled.
* ! s – guess the string picked by the orderlies. This query can be asked exactly once, after that the game will finish. If the string is guessed correctly, the player wins, otherwise he loses.

The player can ask no more than $3$ queries of the first type.

To make it easier for the orderlies, there is an additional limitation: the total number of returned substrings in all queries of the first type must not exceed $\left\lceil 0.777(n+1)^2 \right\rceil$ ($\lceil x \rceil$ is $x$ rounded up).

Venya asked you to write a program, which will guess the string by interacting with the orderlies' program and acting by the game's rules.

Your program should immediately terminate after guessing the string using a query of the second type. In case your program guessed the string incorrectly, or it violated the game rules, it will receive verdict Wrong answer.

Note that in every test case the string is fixed beforehand and will not change during the game, which means that the interactor is not adaptive.

Input

First line contains number $n$ ($1 \le n \le 100$) — the length of the picked string.

Interaction

You start the interaction by reading the number $n$.

To ask a query about a substring from $l$ to $r$ inclusively ($1 \le l \le r \le n$), you should output

? l r

on a separate line. After this, all substrings of $s[l..r]$ will be returned in random order, each substring exactly once. In every returned substring all characters will be randomly shuffled.

In the case, if you ask an incorrect query, ask more than $3$ queries of the first type or there will be more than $\left\lceil 0.777(n+1)^2 \right\rceil$ substrings returned in total, you will receive verdict Wrong answer.

To guess the string $s$, you should output

! s

on a separate line.

After printing each query, do not forget to flush the output. Otherwise, you will get Idleness limit exceeded. To flush the output, you can use:

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

If you received - (dash) as an answer to any query, you need to terminate your program with exit code 0 (for example, by calling exit(0)). This means that there was an error in the interaction protocol. If you don't terminate with exit code 0, you can receive any unsuccessful verdict.

Example

Input

```
4

a
aa
a

cb
b
c

c
```

Output

```
? 1 2

? 3 4

? 4 4

! aabc
```

#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 parseNonNegIntToken(const string& tok, long long& out) {
    if (tok.empty()) return false;
    long long val = 0;
    for (char c : tok) {
        if (c < '0' || c > '9') return false;
        int d = c - '0';
        if (val > (LLONG_MAX - d) / 10) return false;
        val = val * 10 + d;
    }
    out = val;
    return true;
}

static long long ceil_777_thousand(long long x) {

    __int128 num = (__int128)777 * (__int128)x;
    return (long long)((num + 999) / 1000);
}

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

    int n = inf.readInt(1, 100, "n");
    string hidden = inf.readToken();
    if ((int)hidden.size() != n) finish(_fail, "Hidden string length mismatch with n");
    for (char c : hidden) if (c < 'a' || c > 'z') finish(_fail, "Hidden string contains non-lowercase letters");

    query_limit = 3;

    log_metrics();

    cout << n << endl;

    long long hard_query_cap = max(200000LL, 10LL * query_limit);
    long long official_total_substrings_limit = ceil_777_thousand(1LL * (n + 1) * (n + 1));
    long long hard_substrings_cap = max(200000LL, 10LL * official_total_substrings_limit);

    long long total_returned_substrings = 0;

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

        if (cmd == "?") {
            string tokL, tokR;
            if (!(cin >> tokL >> tokR)) {
                cout << "-" << endl;
                finish(_pe, "Malformed query: expected '? l r'");
            }

            long long l = -1, r = -1;
            if (!parseNonNegIntToken(tokL, l) || !parseNonNegIntToken(tokR, r)) {
                cout << "-" << endl;
                finish(_wa, "Invalid query indices");
            }

            if (!(1 <= l && l <= r && r <= n)) {
                cout << "-" << endl;
                finish(_wa, "Query indices out of range");
            }

            queries++;
            if (queries > hard_query_cap) {
                cout << "-" << endl;
                finish(_pe, "Hard cap exceeded (too many queries)");
            }

            int L = (int)l - 1;
            int R = (int)r - 1;
            int m = R - L + 1;
            long long k = 1LL * m * (m + 1) / 2;

            total_returned_substrings += k;
            if (total_returned_substrings > hard_substrings_cap) {
                cout << "-" << endl;
                finish(_pe, "Hard cap exceeded (too many substrings requested)");
            }

            for (int i = 0; i < m; i++) {
                string cur;
                cur.reserve(m - i);
                for (int j = i; j < m; j++) {
                    cur.push_back(hidden[L + j]);
                    string outStr = cur;
                    sort(outStr.begin(), outStr.end());
                    cout << outStr << "\n";
                }
            }
            cout.flush();
            continue;
        }

        if (cmd == "!") {
            string guess;
            if (!(cin >> guess)) {
                finish(_pe, "Malformed answer: expected '! s'");
            }
            if ((int)guess.size() != n) {
                finish(_wa, "Wrong answer (length mismatch)");
            }
            for (char c : guess) {
                if (c < 'a' || c > 'z') finish(_wa, "Wrong answer (non-lowercase letters)");
            }
            if (guess == hidden) finish(_ok, "OK");
            finish(_wa, "Wrong answer");
        }

        cout << "-" << endl;
        finish(_pe, "Unknown command (expected '?' or '!')");
    }
}

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

static int clampInt(int x, int lo, int hi) {
    if (x < lo) return lo;
    if (x > hi) return hi;
    return x;
}

static string makeAlternating(int n, int k) {
    string s;
    s.reserve(n);
    int a = 0;
    int b = (k >= 2 ? 1 : 0);
    for (int i = 0; i < n; i++) s.push_back(char('a' + (i % 2 ? b : a)));
    return s;
}

static string makeBlocks(int n, int k) {
    string s;
    s.reserve(n);
    int i = 0;
    int prev = -1;
    while (i < n) {
        int c = rnd.next(0, k - 1);
        if (k >= 2 && c == prev) c = (c + 1) % k;
        int maxLen = min(n - i, 1 + rnd.next(1, 12));
        int len = rnd.next(1, maxLen);
        for (int j = 0; j < len; j++) s.push_back(char('a' + c));
        i += len;
        prev = c;
    }
    return s;
}

static string makePalindromeWithNoise(int n, int k) {
    string s(n, 'a');
    int half = (n + 1) / 2;
    for (int i = 0; i < half; i++) {
        int c = rnd.next(0, k - 1);
        s[i] = char('a' + c);
        s[n - 1 - i] = char('a' + c);
    }
    int flips = max(1, n / 12);
    for (int t = 0; t < flips; t++) {
        int pos = rnd.next(0, n - 1);
        int c = rnd.next(0, k - 1);
        s[pos] = char('a' + c);
    }
    return s;
}

static string makeBiasedRandom(int n, int k) {
    vector<int> weights(k, 1);
    if (k >= 1) weights[0] = 8;
    if (k >= 2) weights[1] = 6;
    if (k >= 3) weights[2] = 4;
    if (k >= 4) weights[3] = 3;

    long long sum = 0;
    for (int w : weights) sum += w;

    string s;
    s.reserve(n);
    for (int i = 0; i < n; i++) {
        long long x = rnd.next(1LL, sum);
        long long acc = 0;
        int pick = 0;
        for (int j = 0; j < k; j++) {
            acc += weights[j];
            if (x <= acc) {
                pick = j;
                break;
            }
        }
        s.push_back(char('a' + pick));
    }

    if (n >= 4) {
        s[0] = 'a';
        s[n - 1] = char('a' + min(k - 1, 1));
        s[1] = char('a' + min(k - 1, 2));
        s[n - 2] = char('a' + min(k - 1, 3));
    }
    return s;
}

static string makeAdversarialMix(int n, int k) {
    int t = rnd.next(0, 3);
    string s;
    if (t == 0) s = makeBlocks(n, k);
    else if (t == 1) s = makePalindromeWithNoise(n, k);
    else if (t == 2) s = makeAlternating(n, k);
    else s = makeBiasedRandom(n, k);

    if (n >= 10 && k >= 2) {
        int p1 = n / 3;
        int p2 = (2 * n) / 3;
        s[p1] = 'a';
        s[p2] = 'b';
    }
    if (n >= 20 && k >= 4) {
        s[n / 2] = 'c';
        s[min(n - 1, n / 2 + 1)] = 'd';
    }
    return s;
}

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

    string mode = opt<string>("mode", "non");
    int forcedN = opt<int>("n", -1);
    int k = clampInt(opt<int>("k", 4), 1, 26);
    int forcedType = opt<int>("type", -1);
    long long seedVal = 0;
    if (argc >= 2) {
        try {
            seedVal = stoll(string(argv[1]));
        } catch (...) {
            seedVal = 0;
        }
    }

    int n;
    string s;

    if (seedVal == 1) {
        n = 1;
        s = "a";
    } else if (seedVal == 2) {
        n = 100;
        s.assign(n, 'a');
        s[n / 2] = 'b';
        s[0] = 'a';
        s[n - 1] = 'a';
    } else if (seedVal == 3) {
        n = 100;
        s = makeAlternating(n, 2);
        s[49] = 'a';
        s[50] = 'b';
    } else {
        if (forcedN != -1) n = clampInt(forcedN, 1, 100);
        else {
            int roll = rnd.next(1, 100);
            if (roll <= 70) n = 100;
            else if (roll <= 90) n = rnd.next(85, 100);
            else n = rnd.next(60, 100);
        }

        int type = forcedType;
        if (type < 0 || type > 3) type = rnd.next(0, 3);

        if (type == 0) s = makeBlocks(n, k);
        else if (type == 1) s = makePalindromeWithNoise(n, k);
        else if (type == 2) s = makeAlternating(n, k);
        else s = makeAdversarialMix(n, k);

        if ((int)s.size() != n) s.resize(n, 'a');
        for (char& ch : s) {
            if (ch < 'a' || ch > 'z') ch = 'a';
        }
    }

    if (forcedN != -1) {
        n = clampInt(forcedN, 1, 100);
        if ((int)s.size() != n) {
            if ((int)s.size() < n) s += string(n - (int)s.size(), 'a');
            else s.resize(n);
        }
    }

    if (mode == "non") {
        cout << n << "\n" << s << "\n";
    } else if (mode == "adp") {
        cout << n << "\n";
    } else {
        quitf(_fail, "Unknown --mode (expected non/adp)");
    }
    return 0;
}


This is an interactive problem. Don't forget to flush output after printing queries using cout.flush() or fflush(stdout) in C++ or similar functions in other programming languages.

There are $n$ gift boxes in a row, numbered from $1$ to $n$ from left to right. It's known that exactly $k$ of them contain valuable gifts — other boxes contain just lucky stones. All boxes look the same and differ only in weight. All boxes with stones have the same weight and are strictly heavier than boxes with valuable items. But valuable gifts may be different, so the boxes with valuable items may have different weights.

You can ask no more than $50$ queries (printing an answer doesn't count). By each query you can compare total weights of two non-intersecting subsets of boxes $a_1, a_2, \dots, a_{k_a}$ and $b_1, b_2, \dots, b_{k_b}$. In return you'll get one of four results:

* FIRST, if subset $a_1, a_2, \dots, a_{k_a}$ is strictly heavier;
* SECOND, if subset $b_1, b_2, \dots, b_{k_b}$ is strictly heavier;
* EQUAL, if subsets have equal total weights;
* WASTED, if the query is incorrect or the limit of queries is exceeded.

Using such queries (or, maybe, intuition) find the box with a valuable gift with the minimum index.

Input

The input consists of several cases. In the beginning, you receive the integer $T$ ($1 \le T \le 500$) — the number of test cases.

At the beginning of each test case, you receive two integers $n$ and $k$ ($2 \le n \le 1000$, $1 \le k \le \frac{n}{2}$) — the number of boxes in a row and the number of boxes with valuable gifts.

It's guaranteed that the order of boxes is fixed beforehand and that the sum of $n$ in one test doesn't exceed $1000$.

Output

For each test case print the minimum index among all boxes with a valuable gift in the following format: "! $x$" where $x$ ($1 \le x \le n$) — the index of the box.

Interaction

Print each query in three lines. In the first line print the sizes of subset in the following format: "? $k_a$ $k_b$" where $k_a$ and $k_b$ ($1 \le k_a, k_b \le n$; $k_a + k_b \le n$) — the corresponding sizes.

In the second line print $k_a$ integers $a_1, a_2, \dots, a_{k_a}$ ($1 \le a_i \le n$; $a_i \neq a_j$ if $i \neq j$) — indexes of boxes in the first subset.

In the third line print $k_b$ integers $b_1, b_2, \dots, b_{k_b}$ ($1 \le b_i \le n$; $b_i \neq b_j$ if $i \neq j$) — indexes of boxes in the second subset.

The subsets shouldn't intersect, i. e. $a_i \neq b_j$ for all $i$ and $j$.

You'll receive one of four responses described above. In the case of WASTED stop your program to avoid getting random verdict instead of Wrong Answer.

Example

Input

```
2
2 1
-
-
-
FIRST
-
5 2
-
-
-
FIRST
-
-
-
SECOND
-
-
-
EQUAL
-
```

Output

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

Note

Additional separators "–" in the sample are used only to increase the readability of the sample. Don't print any unnecessary symbols or line breaks in your solution when you send it to the system.

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

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

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

    }
}

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

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

static long long readLLFromContestantOrDie(const string& what) {
    long long x;
    if (!(cin >> x)) finish(_pe, "Malformed or missing " + what);
    return x;
}

static void sendLine(const string& s) {
    cout << s << "\n";
    cout.flush();
}

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

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

    int T = inf.readInt(1, 500, "T");
    vector<int> n(T), k(T);
    vector<vector<long long>> w(T);
    vector<int> answer(T, -1);

    for (int tc = 0; tc < T; ++tc) {
        n[tc] = inf.readInt(2, 1000, "n");
        k[tc] = inf.readInt(1, n[tc] / 2, "k");

        w[tc].assign(n[tc] + 1, 0);
        long long mx = LLONG_MIN;
        for (int i = 1; i <= n[tc]; ++i) {
            w[tc][i] = inf.readLong(1LL, (long long)4e18, "weight");
            mx = max(mx, w[tc][i]);
        }

        int best = -1;
        for (int i = 1; i <= n[tc]; ++i) {
            if (w[tc][i] < mx) {
                best = i;
                break;
            }
        }
        if (best == -1) best = 1;
        answer[tc] = best;
    }

    query_limit = 50LL * (long long)T;
    log_metrics();

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

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

    for (int tc = 0; tc < T; ++tc) {
        cout << n[tc] << " " << k[tc] << "\n";
        cout.flush();

        while (true) {
            string cmd;
            if (!readTokenFromContestant(cmd)) finish(_pe, "Unexpected EOF from contestant");

            if (cmd == "?") {
                long long ka = readLLFromContestantOrDie("ka");
                long long kb = readLLFromContestantOrDie("kb");

                if (ka < 1 || kb < 1 || ka > n[tc] || kb > n[tc] || ka + kb > n[tc]) {
                    sendLine("WASTED");
                    finish(_pe, "Invalid subset sizes");
                }

                vector<int> A((size_t)ka), B((size_t)kb);
                vector<char> used((size_t)n[tc] + 1, 0);

                for (int i = 0; i < (int)ka; ++i) {
                    long long x = readLLFromContestantOrDie("a_i");
                    if (x < 1 || x > n[tc]) {
                        sendLine("WASTED");
                        finish(_pe, "Index out of range in A");
                    }
                    if (used[(int)x]) {
                        sendLine("WASTED");
                        finish(_pe, "Duplicate or intersecting index");
                    }
                    used[(int)x] = 1;
                    A[i] = (int)x;
                }

                for (int i = 0; i < (int)kb; ++i) {
                    long long x = readLLFromContestantOrDie("b_i");
                    if (x < 1 || x > n[tc]) {
                        sendLine("WASTED");
                        finish(_pe, "Index out of range in B");
                    }
                    if (used[(int)x]) {
                        sendLine("WASTED");
                        finish(_pe, "Duplicate or intersecting index");
                    }
                    used[(int)x] = 1;
                    B[i] = (int)x;
                }

                ++queries;
                if (queries > hard_cap) {
                    sendLine("WASTED");
                    finish(_pe, "Hard cap exceeded");
                }

                long long sumA = 0, sumB = 0;
                for (int x : A) sumA += w[tc][x];
                for (int x : B) sumB += w[tc][x];

                if (sumA > sumB) sendLine("FIRST");
                else if (sumB > sumA) sendLine("SECOND");
                else sendLine("EQUAL");
            } else if (cmd == "!") {
                long long x = readLLFromContestantOrDie("answer x");
                if (x < 1 || x > n[tc]) finish(_pe, "Answer out of range");
                if ((int)x != answer[tc]) finish(_wa, "Wrong answer for test case");
                break;
            } else {
                finish(_pe, "Unknown command token");
            }
        }
    }

    finish(_ok, "OK");
    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 << "\n";
        tout << "query_limit=" << query_limit << "\n";
        tout.flush();
    } catch (...) {
    }
}

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

static bool parseLL(const string& s, long long& out) {
    if (s.empty()) return false;
    int i = 0;
    bool neg = false;
    if (s[0] == '-') {
        neg = true;
        i = 1;
        if (i == (int)s.size()) return false;
    }
    long long val = 0;
    for (; i < (int)s.size(); ++i) {
        unsigned char c = (unsigned char)s[i];
        if (!isdigit(c)) return false;
        int d = s[i] - '0';
        if (val > (LLONG_MAX - d) / 10) return false;
        val = val * 10 + d;
    }
    out = neg ? -val : val;
    return true;
}

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

static bool readLong(long long& x) {
    string tok;
    if (!readToken(tok)) return false;
    return parseLL(tok, x);
}

static vector<string> splitWS(const string& line) {
    vector<string> t;
    string cur;
    for (char ch : line) {
        if (isspace((unsigned char)ch)) {
            if (!cur.empty()) {
                t.push_back(cur);
                cur.clear();
            }
        } else {
            cur.push_back(ch);
        }
    }
    if (!cur.empty()) t.push_back(cur);
    return t;
}

static bool isNonEmptyLine(const string& s) {
    for (char c : s) if (!isspace((unsigned char)c)) return true;
    return false;
}

static string readNextNonEmptyInfLine() {
    while (!inf.eof()) {
        string line = inf.readLine();
        if (isNonEmptyLine(line)) return line;
    }
    return "";
}

struct AdaptiveCase {
    int n = 0, k = 0;
    long long stoneW = 0;
    long long giftW = 0;
    long long D = 0;
    vector<int> feasibleL;
};

static int giftCountInWindow(const vector<int>& pref, int L, int k) {
    int R = L + k - 1;
    return pref[R] - pref[L - 1];
}

static void outputToContestant(const string& s) {
    cout << s << "\n";
    cout.flush();
}

static void outputToContestantIntPair(int a, int b) {
    cout << a << " " << b << "\n";
    cout.flush();
}

static void outputWastedAndDie(const string& msg) {
    outputToContestant("WASTED");
    finish(_pe, msg);
}

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

    int T = inf.readInt();
    if (T < 1 || T > 500) finish(_pe, "bad T in input");
    query_limit = 50LL * T;
    log_metrics();

    outputToContestant(to_string(T));

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

    for (int tc = 1; tc <= T; ++tc) {
        int n = inf.readInt();
        int k = inf.readInt();
        if (n < 2 || n > 1000) finish(_pe, "bad n in input");
        if (k < 1 || k > n / 2) finish(_pe, "bad k in input");

        (void)inf.readLine();
        string line1 = readNextNonEmptyInfLine();
        if (line1.empty()) finish(_pe, "unexpected EOF while reading case payload");

        vector<string> tok1 = splitWS(line1);

        bool fixed_mode = false;
        vector<long long> weights(n + 1, 0);
        AdaptiveCase ac;
        ac.n = n;
        ac.k = k;

        if ((int)tok1.size() == 1) {

            long long stoneW_in = 0;
            if (!parseLL(tok1[0], stoneW_in)) finish(_pe, "bad stoneW token");
            string line2 = readNextNonEmptyInfLine();
            if (line2.empty()) finish(_pe, "unexpected EOF while reading gmin/gmax");
            vector<string> tok2 = splitWS(line2);
            if ((int)tok2.size() != 2) finish(_pe, "bad gmin/gmax line");

            long long gmin_in = 0, gmax_in = 0;
            if (!parseLL(tok2[0], gmin_in) || !parseLL(tok2[1], gmax_in)) finish(_pe, "bad gmin/gmax tokens");

            long long stoneW = max(2LL, stoneW_in);
            long long gmin = max(1LL, gmin_in);
            long long gmax = max(gmin, gmax_in);

            if (gmax >= stoneW) {
                stoneW = gmax + 1;
            }
            long long giftW = min(gmin, stoneW - 1);
            if (giftW < 1) giftW = 1;
            if (giftW >= stoneW) giftW = stoneW - 1;
            if (giftW < 1) stoneW = max(stoneW, 2LL), giftW = 1;

            ac.stoneW = stoneW;
            ac.giftW = giftW;
            ac.D = ac.stoneW - ac.giftW;
            if (ac.D <= 0) {
                ac.stoneW = max(ac.stoneW, ac.giftW + 1);
                ac.D = ac.stoneW - ac.giftW;
                if (ac.D <= 0) finish(_pe, "failed to ensure stoneW>giftW");
            }

            int maxL = n - k + 1;
            ac.feasibleL.resize(maxL);
            iota(ac.feasibleL.begin(), ac.feasibleL.end(), 1);
        } else if ((int)tok1.size() == n) {

            fixed_mode = true;
            for (int i = 1; i <= n; ++i) {
                long long wi = 0;
                if (!parseLL(tok1[i - 1], wi)) finish(_pe, "bad weight token");
                weights[i] = wi;
            }
        } else {
            finish(_pe, "cannot detect input mode (line token count mismatch)");
        }

        outputToContestantIntPair(n, k);

        int fixed_answer = -1;
        if (fixed_mode) {
            long long stoneW = *max_element(weights.begin() + 1, weights.end());
            fixed_answer = n + 1;
            int giftCount = 0;
            for (int i = 1; i <= n; ++i) {
                if (weights[i] < stoneW) {
                    fixed_answer = min(fixed_answer, i);
                    giftCount++;
                }
            }
            if (fixed_answer == n + 1) finish(_pe, "fixed mode: no gifts detected");

            if (giftCount != k) {

            }
        }

        while (true) {
            string cmd;
            if (!readToken(cmd)) finish(_pe, "unexpected EOF from contestant");

            if (cmd == "?") {
                long long ka_ll = 0, kb_ll = 0;
                if (!readLong(ka_ll) || !readLong(kb_ll)) outputWastedAndDie("bad query sizes");
                if (ka_ll < 1 || kb_ll < 1 || ka_ll > n || kb_ll > n) outputWastedAndDie("query sizes out of range");
                if (ka_ll + kb_ll > n) outputWastedAndDie("query subsets intersect by size");
                int ka = (int)ka_ll, kb = (int)kb_ll;

                queries++;
                if (queries > hard_cap) outputWastedAndDie("too many queries (hard cap)");

                vector<int> used(n + 1, 0);
                vector<int> A;
                vector<int> B;
                A.reserve(ka);
                B.reserve(kb);

                for (int i = 0; i < ka; ++i) {
                    long long idx_ll = 0;
                    if (!readLong(idx_ll)) outputWastedAndDie("bad A index token");
                    if (idx_ll < 1 || idx_ll > n) outputWastedAndDie("A index out of range");
                    int idx = (int)idx_ll;
                    if (used[idx]) outputWastedAndDie("duplicate index in A");
                    used[idx] = 1;
                    A.push_back(idx);
                }
                for (int i = 0; i < kb; ++i) {
                    long long idx_ll = 0;
                    if (!readLong(idx_ll)) outputWastedAndDie("bad B index token");
                    if (idx_ll < 1 || idx_ll > n) outputWastedAndDie("B index out of range");
                    int idx = (int)idx_ll;
                    if (used[idx]) outputWastedAndDie("intersection or duplicate index in B");
                    used[idx] = 1;
                    B.push_back(idx);
                }

                if (fixed_mode) {
                    __int128 sumA = 0, sumB = 0;
                    for (int idx : A) sumA += (__int128)weights[idx];
                    for (int idx : B) sumB += (__int128)weights[idx];

                    if (sumA > sumB) outputToContestant("FIRST");
                    else if (sumA < sumB) outputToContestant("SECOND");
                    else outputToContestant("EQUAL");
                    continue;
                }

                vector<int> markA(n + 1, 0), markB(n + 1, 0);
                for (int idx : A) markA[idx] = 1;
                for (int idx : B) markB[idx] = 1;

                vector<int> prefA(n + 1, 0), prefB(n + 1, 0);
                for (int i = 1; i <= n; ++i) {
                    prefA[i] = prefA[i - 1] + markA[i];
                    prefB[i] = prefB[i - 1] + markB[i];
                }

                vector<int> groupFirst, groupSecond, groupEqual;
                groupFirst.reserve(ac.feasibleL.size());
                groupSecond.reserve(ac.feasibleL.size());
                groupEqual.reserve(ac.feasibleL.size());

                for (int L : ac.feasibleL) {
                    int gA = giftCountInWindow(prefA, L, k);
                    int gB = giftCountInWindow(prefB, L, k);
                    long long sumA = ac.stoneW * (long long)ka - ac.D * (long long)gA;
                    long long sumB = ac.stoneW * (long long)kb - ac.D * (long long)gB;
                    if (sumA > sumB) groupFirst.push_back(L);
                    else if (sumA < sumB) groupSecond.push_back(L);
                    else groupEqual.push_back(L);
                }

                auto span = [&](const vector<int>& v) -> int {
                    if (v.empty()) return -1;
                    int mn = v[0], mx = v[0];
                    for (int x : v) mn = min(mn, x), mx = max(mx, x);
                    return mx - mn;
                };

                struct Choice {
                    string word;
                    vector<int>* group;
                    int sz;
                    int sp;
                    int pr;
                };

                vector<Choice> choices;
                choices.push_back({"EQUAL", &groupEqual, (int)groupEqual.size(), span(groupEqual), 3});
                choices.push_back({"FIRST", &groupFirst, (int)groupFirst.size(), span(groupFirst), 2});
                choices.push_back({"SECOND", &groupSecond, (int)groupSecond.size(), span(groupSecond), 1});

                Choice best = {"", nullptr, -1, -1, -1};
                for (auto& c : choices) {
                    if (c.sz == 0) continue;
                    if (c.sz > best.sz) best = c;
                    else if (c.sz == best.sz) {
                        if (c.sp > best.sp) best = c;
                        else if (c.sp == best.sp) {
                            if (c.pr > best.pr) best = c;
                            else if (c.pr == best.pr) {

                                if (c.word < best.word) best = c;
                            }
                        }
                    }
                }

                if (best.group == nullptr) {

                    outputWastedAndDie("internal: empty partition");
                }

                outputToContestant(best.word);
                ac.feasibleL.swap(*best.group);
                continue;
            }

            if (cmd == "!") {
                long long x_ll = 0;
                if (!readLong(x_ll)) finish(_pe, "bad final answer token");
                if (x_ll < 1 || x_ll > n) finish(_wa, "final answer out of range");
                int x = (int)x_ll;

                if (fixed_mode) {
                    if (x != fixed_answer) finish(_wa, "wrong answer (fixed mode)");
                } else {
                    bool okForAll = true;
                    for (int L : ac.feasibleL) {
                        if (L != x) {
                            okForAll = false;
                            break;
                        }
                    }
                    if (!okForAll) finish(_wa, "wrong answer (not forced by interaction)");
                }
                break;
            }

            finish(_pe, "unknown command from contestant");
        }
    }

    finish(_ok, "OK");
    return 0;
}

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

static long long clampLL(long long x, long long lo, long long hi) {
    if (x < lo) return lo;
    if (x > hi) return hi;
    return x;
}

static int clampInt(int x, int lo, int hi) {
    if (x < lo) return lo;
    if (x > hi) return hi;
    return x;
}

static void fisherYatesShuffle(vector<int>& a) {
    for (int i = (int)a.size() - 1; i > 0; --i) {
        int j = rnd.next(0, i);
        swap(a[i], a[j]);
    }
}

static vector<int> buildGiftIndices(int n, int k, int& leftmost, int pattern) {
    vector<int> isGift(n + 1, 0);
    vector<int> gifts;
    gifts.reserve(k);

    auto addGift = [&](int idx) {
        if (idx < 1 || idx > n) return;
        if (!isGift[idx]) {
            isGift[idx] = 1;
            gifts.push_back(idx);
        }
    };

    if (pattern == 2) {
        int start = n - k + 1;
        leftmost = start;
        for (int i = start; i <= n; ++i) addGift(i);
        return gifts;
    }

    addGift(leftmost);

    if (pattern == 1) {
        for (int i = leftmost + 1; i <= n && (int)gifts.size() < k; i += 2) addGift(i);
        for (int i = leftmost + 2; i <= n && (int)gifts.size() < k; i += 2) addGift(i);
    }

    if ((int)gifts.size() < k) {
        vector<int> cand;
        cand.reserve(n);
        for (int i = leftmost + 1; i <= n; ++i) if (!isGift[i]) cand.push_back(i);
        fisherYatesShuffle(cand);
        for (int i = 0; i < (int)cand.size() && (int)gifts.size() < k; ++i) addGift(cand[i]);
    }

    if ((int)gifts.size() < k) {
        for (int i = 1; i <= n && (int)gifts.size() < k; ++i) addGift(i);
    }

    sort(gifts.begin(), gifts.end());
    return gifts;
}

static vector<long long> buildWeights(int n, const vector<int>& gifts, long long stoneW, long long gmin, long long gmax, bool nearStone, bool uniqueRandom) {
    vector<long long> w(n + 1, stoneW);
    int k = (int)gifts.size();

    gmax = min(gmax, stoneW - 1);
    if (gmax < gmin) gmax = gmin;

    if (nearStone) {
        for (int i = 0; i < k; ++i) {
            long long gw = stoneW - 1 - i;
            if (gw < 1) gw = 1;
            w[gifts[i]] = gw;
        }
        return w;
    }

    long long range = gmax - gmin + 1;
    if (!uniqueRandom || range <= k + 5) {
        long long start = gmin;
        if (start + (k - 1) > gmax) start = max(gmin, gmax - (k - 1));
        for (int i = 0; i < k; ++i) w[gifts[i]] = start + i;
        return w;
    }

    unordered_set<long long> used;
    used.reserve((size_t)k * 2 + 1);
    int idx = 0;
    int guard = 0;
    while (idx < k) {
        if (++guard > 2000000) {
            long long start = gmin;
            if (start + (k - 1) > gmax) start = max(gmin, gmax - (k - 1));
            for (int i = 0; i < k; ++i) w[gifts[i]] = start + i;
            return w;
        }
        long long gw = rnd.next((long long)gmin, (long long)gmax);
        if (used.insert(gw).second) {
            w[gifts[idx]] = gw;
            ++idx;
        }
    }
    return w;
}

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

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

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

    int nOpt = opt<int>("n", 1000);
    long long stoneWOpt = opt<long long>("stone", 1000000000LL);
    long long gminOpt = opt<long long>("gmin", 1LL);
    long long gmaxOpt = opt<long long>("gmax", stoneWOpt - 1);

    int n = clampInt(nOpt, 2, 1000);
    int kOpt = opt<int>("k", -1);
    int k = (kOpt == -1 ? n / 2 : clampInt(kOpt, 1, n / 2));

    long long stoneW = max(2LL, stoneWOpt);
    long long gmin = max(1LL, gminOpt);
    long long gmax = min(gmaxOpt, stoneW - 1);
    if (gmax < gmin) gmax = gmin;

    int leftmost = 1;
    int pattern = 0;
    bool nearStone = false;
    bool uniqueRandom = true;

    if (seed == 1) {
        n = 2; k = 1;
        leftmost = 2;
        pattern = 0;
        nearStone = false;
        uniqueRandom = false;
    } else if (seed == 2) {
        n = 1000; k = 500;
        leftmost = n - k + 1;
        pattern = 2;
        nearStone = false;
        uniqueRandom = true;
    } else if (seed == 3) {
        n = 8; k = 4;
        leftmost = 2;
        pattern = 1;
        nearStone = true;
        uniqueRandom = false;
    } else {
        n = clampInt(n, 2, 1000);
        k = clampInt(k, 1, n / 2);

        int maxLeft = n - k + 1;
        int lo = max(1, maxLeft - 60);
        int hi = maxLeft;
        leftmost = rnd.next(lo, hi);

        pattern = rnd.next(0, 2);
        if (pattern == 2) leftmost = maxLeft;

        nearStone = (rnd.next(0, 9) == 0);
        uniqueRandom = true;

        if (opt<int>("nearStone", -1) != -1) nearStone = (opt<int>("nearStone", 0) != 0);
        if (opt<int>("pattern", -1) != -1) pattern = clampInt(opt<int>("pattern", 0), 0, 2);
    }

    if (k > n / 2) k = n / 2;
    if (k < 1) k = 1;
    int maxLeft = n - k + 1;
    leftmost = clampInt(leftmost, 1, maxLeft);

    if (mode != "non" && mode != "adp") mode = "non";

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

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

    vector<int> gifts = buildGiftIndices(n, k, leftmost, pattern);

    vector<long long> w;
    if (seed == 1) {
        stoneW = 10;
        gmin = 1; gmax = 1;
        w.assign(n + 1, stoneW);
        w[2] = 1;
    } else if (seed == 3) {
        stoneW = max(stoneW, 1000000000LL);
        w = buildWeights(n, gifts, stoneW, 1LL, stoneW - 1, true, false);
    } else {
        w = buildWeights(n, gifts, stoneW, gmin, gmax, nearStone, uniqueRandom);
    }

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


Score : $1400$ points

### Problem Statement

**This is an interactive problem.**

There are $\tbinom{2N}{N}$ cards numbered $1$ to $\tbinom{2N}{N}$ on a desk. Card $i$ $(1 \le i \le \tbinom{2N}{N})$ shows on its front the $i$‑th string in lexicographic order among the strings consisting of $N$ zeros and $N$ ones.

Example
For $N = 2$, the fronts of cards $1$, $2$, $3$, $4$, $5$, $6$ are `0011`, `0101`, `0110`, `1001`, `1010`, `1100`, respectively.

Witch Alice writes one of the first $N$ uppercase letters (for example, `A` or `B` if $N = 2$) on the back of each card, then performs the following **magic** $T$ times.

> **A single magic**
>
> 1. The host announces a letter $s$ among the first $N$ uppercase letters.
> 2. The host writes a length-$2N$ string of all `0` on the blackboard.
> 3. For $i = 1, 2, \dots, N$ in this order, do the following. Here, $a_1, b_1, \dots, a_N, b_N$ are distinct integers from $1$ to $2N$.
>    * First, the host tells Alice integers $a_i$ and $b_i$.
>    * Then, Alice chooses exactly one of the $a_i$-th and $b_i$-th characters of the string on the blackboard, and sets it to `1`.
> 4. Let $x$ be the final string on the blackboard. Exactly one card shows $x$ on its front; look at its back. The magic succeeds if and only if the letter on its back equals $s$.

Note that Alice learns $a_{i+1}$ and $b_{i+1}$ only after choosing which of the $a_i$-th and $b_i$-th characters to set to `1`.

Implement a strategy that makes all $T$ magics succeed. Now, let us begin.

---

### Constraints

* $2 \le N \le 10$
* $1 \le T \le 5\,000$
* The letter $s$ is among the first $N$ uppercase letters.
* $1 \le a_i < b_i \le 2N$
* $a_1, b_1, a_2, b_2, \dots, a_N, b_N$ are distinct.
* $a_1, b_1, a_2, b_2, \dots, a_N, b_N, s$ are fixed before the interaction starts.
* $N, T, a_i, b_i$ are integers.

### Input and Output

First, read the integers $N$ and $T$ given from Standard Input in the following format:

```
$N$ $T$
```

Next, let $c_i$ be the letter written on the back of card $i$, and print those letters in the following format, followed by a newline. Here, $c_i$ must be among the first $N$ uppercase letters.

```
$c_1 c_2 \cdots c_{\tbinom{2N}{N}}$
```

Next, repeat the following process $T$ times. The $t$-th iteration $(1 \leq t \leq T)$ corresponds to the $t$-th magic.

> Read the announced letter $s$ given in the following format:
>
> ```
> $s$
> ```
>
> Then, for $i = 1, 2, \dots, N$ in this order, do the following.
>
> * Read integers $a_i$ and $b_i$ given in the following format:
>
> ```
> $a_i$ $b_i$
> ```
>
> * Print the chosen position $d$ in the following format, followed by a newline. Here, $d$ must be $a_i$ or $b_i$.
>
> ```
> $d$
> ```
>
> If your output was malformed or the previous magic failed, no more input such as $s$ or $(a_i, b_i)$ is given, but `-1` is given from Standard Input. In this case, exit immediately. (If you fail for the first time in the $T$-th magic, or your output was malformed for the first time at $i = N$ in the $T$-th magic, no more input follows.)

### Notes

**Flush after every output.** Otherwise, you may receive a TLE verdict.

If you read `-1`, exit immediately. If you do so, you will receive a WA verdict, but continuing leads to an indeterminate verdict. Unnecessary newlines may be seen as malformed.

The judge is **non‑adaptive**; the values $a_1, b_1, a_2, b_2, \dots, a_N, b_N, s$ are fixed before the interaction starts, and will not be affected by your output.

---

### Sample Interaction

Note that this is just an example of interaction.

| Input | Output | Comment |
| --- | --- | --- |
| `2 2` |  | The integers $N$ and $T$ are given from Standard Input. |
|  | `ABABAB` | Print letters for the backs of the six cards. |
| `A` |  | The first magic begins. The host declares `A`. |
| `1 2` |  | The host tells you $(a_1, b_1) = (1, 2)$. |
|  | `2` | Set the second character to `1`. |
| `3 4` |  | The host tells you $(a_2, b_2) = (3, 4)$. |
|  | `3` | Set the third character to `1`. The final string is `0110`, and the card with `0110` on its front has `A` on the back, so the magic succeeds. |
| `B` |  | The second magic begins. The host declars `B`. |
| `1 3` |  | The host tells you $(a_1, b_1) = (1, 3)$. |
|  | `1` | Set the first character to `1`. |
| `2 4` |  | The host tells you $(a_2, b_2) = (2, 4)$. |
|  | `2` | Set the second character to `1`. The final string is `1100`, and the card with `1100` on its front has `B` on the back, so the magic succeeds. |

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

static long long queries = 0;
static long long query_limit = 0;
static bool finished = false;
static long long C[25][25];

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

    }
}

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

void precompute() {
    for (int i = 0; i <= 22; ++i) {
        C[i][0] = 1;
        for (int j = 1; j <= i; ++j) {
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
        }
    }
}

long long get_rank(int N, const vector<int>& chosen_bits) {
    long long r = 1;
    int zeros = N;
    int ones = N;

    for (int i = 1; i <= 2 * N; ++i) {
        if (chosen_bits[i] == 0) {
            zeros--;
        } else {

            if (zeros > 0) {
                r += C[zeros - 1 + ones][ones];
            }
            ones--;
        }
    }
    return r;
}

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

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

    int N = inf.readInt(2, 10, "N");
    int T = inf.readInt(1, 5000, "T");

    query_limit = T;
    log_metrics();

    cout << N << " " << T << endl;

    long long K = C[2 * N][N];
    string user_S;

    if (!(cin >> user_S)) {
        finish(_pe, "Could not read initial string (EOF)");
    }

    if ((long long)user_S.length() != K) {

        cout << "-1" << endl;
        finish(_wa, format("String length mismatch. Expected %lld, got %d", K, (int)user_S.length()));
    }

    for (int i = 0; i < (int)user_S.length(); ++i) {
        if (user_S[i] < 'A' || user_S[i] >= 'A' + N) {
            cout << "-1" << endl;
            finish(_wa, format("Invalid character '%c' at index %d. Expected 'A'..'%c'",
                               user_S[i], i, (char)('A' + N - 1)));
        }
    }

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

        string s_token = inf.readToken();
        if (s_token.empty()) finish(_fail, "Generator output ended prematurely (reading s)");
        char s_char = s_token[0];

        vector<pair<int, int>> pairs(N);
        for (int i = 0; i < N; ++i) {
            pairs[i].first = inf.readInt(1, 2 * N, "u");
            pairs[i].second = inf.readInt(1, 2 * N, "v");
        }

        cout << s_char << endl;

        vector<int> board(2 * N + 1, 0);
        for (int i = 0; i < N; ++i) {
            int u = pairs[i].first;
            int v = pairs[i].second;

            cout << u << " " << v << endl;

            string token;
            if (!(cin >> token)) {
                finish(_pe, "Unexpected EOF while reading choice");
            }

            if (token == "?" || token == "!") {
                 if (!(cin >> token)) finish(_pe, "Unexpected EOF after special token");
            }

            int d = -1;
            try {
                size_t idx;
                d = stoi(token, &idx);

                if (idx != token.length()) {
                     cout << "-1" << endl;
                     finish(_pe, format("Malformed integer: %s", token.c_str()));
                }
            } catch (...) {
                cout << "-1" << endl;
                finish(_pe, format("Expected integer, got: %s", token.c_str()));
            }

            if (d != u && d != v) {
                cout << "-1" << endl;
                finish(_wa, format("Invalid choice %d. Expected %d or %d", d, u, v));
            }

            board[d] = 1;
        }

        long long rank = get_rank(N, board);
        if (rank < 1 || rank > K) {
             finish(_fail, format("Logic error: Calculated rank %lld out of bounds [1, %lld]", rank, K));
        }

        char user_char = user_S[rank - 1];
        if (user_char != s_char) {
            cout << "-1" << endl;
            finish(_wa, format("Magic %d failed. Target '%c', got '%c' (from rank %lld string)",
                               t, s_char, user_char, rank));
        }

        queries++;

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

    finish(_ok, format("Passed %d magics", T));
    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 = rnd.next(2, 10);
    int T = rnd.next(1, 5000);

    string seed = argv[1];
    if (seed == "1") {
        N = 2; T = 2;
    } else if (seed == "2") {
        N = 10; T = 5;
    } else if (seed == "3") {
        N = 10; T = 5000;
    } else if (seed == "4") {
        N = 5; T = 100;
    } else if (seed == "5") {
        N = 2; T = 5000;
    } else {

        if (rnd.next(3) == 0) N = 10;
        if (rnd.next(3) == 0) T = 5000;
    }

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

    cout << N << " " << T << endl;

    if (mode == "non") {

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

            char s = (char)('A' + rnd.next(N));
            cout << s << endl;

            vector<int> p(2 * N);
            iota(p.begin(), p.end(), 1);
            shuffle(p.begin(), p.end());

            for (int i = 0; i < N; ++i) {
                int u = p[2 * i];
                int v = p[2 * i + 1];
                if (u > v) swap(u, v);
                cout << u << " " << v << endl;
            }
        }
    }

    return 0;
}


### Problem Statement

This is an **interactive problem** (where your program interacts with the judge via input and output).

You are given a positive integer $N$.

The judge has a hidden positive integer $R$ and $N$ integers $A_1, A_2, \dots, A_N$. It is guaranteed that $|A_i|\le R$ and $\left|\displaystyle\sum_{i=1}^{N}A_i\right| \le R$.

There is a blackboard on which you can write integers with absolute values not exceeding $R$. Initially, the blackboard is empty.

The judge has written the values $A_1, A_2, \dots, A_N$ on the blackboard **in this order**. Your task is to make the blackboard contain only one value $\displaystyle\sum_{i=1}^{N}A_i$.

You cannot learn the values of $R$ and $A_i$ directly, but you can interact with the judge up to $25000$ times.

For a positive integer $i$, let $X_i$ be the $i$-th integer written on the blackboard. Specifically, $X_i = A_i$ for $i=1,2,\dots,N$.

In one interaction, you can specify two distinct positive integers $i$ and $j$ and choose one of the following actions:

* Perform addition. The judge will erase $X_i$ and $X_j$ from the blackboard and write $X_i + X_j$ on the blackboard.
  + $|X_i + X_j| \leq R$ must hold.
* Perform comparison. The judge will tell you whether $X_i < X_j$ is true or false.

Here, at the beginning of each interaction, the $i$-th and $j$-th integers written on the blackboard must not have been erased.

Perform the interactions appropriately so that after all interactions, the blackboard contains only one value $\displaystyle\sum_{i=1}^{N}A_i$.

The values of $R$ and $A_i$ are determined before the start of the conversation between your program and the judge.

### Constraints

* $2 \leq N \leq 1000$
* $1 \leq R \leq 10^9$
* $|A_i| \leq R$
* $\left|\displaystyle\sum_{i=1}^{N}A_i\right| \le R$
* $N$, $R$, and $A_i$ are integers.

### Input and Output

This is an **interactive problem** (where your program interacts with the judge via input and output).

First, read $N$ from Standard Input.

```
$N$
```

Next, repeat the interactions until the blackboard contains only one value $\displaystyle\sum_{i=1}^{N}A_i$.

When performing addition, make an output in the following format to Standard Output. Append a newline at the end. Here, $i$ and $j$ are distinct positive integers.

```
+ $i$ $j$
```

The response from the judge will be given from Standard Input in the following format:

```
$P$
```

Here, $P$ is an integer:

* If $P \geq N + 1$, it means that the value $X_i + X_j$ has been written on the blackboard, and it is the $P$-th integer written.
* If $P = -1$, it means that $i$ and $j$ do not satisfy the constraints, or the number of interactions has exceeded $25000$.

When performing comparison, make an output in the following format to Standard Output. Append a newline at the end. Here, $i$ and $j$ are distinct positive integers.

```
? $i$ $j$
```

The response from the judge will be given from Standard Input in the following format:

```
$Q$
```

Here, $Q$ is an integer:

* If $Q = 1$, it means that $X_i < X_j$ is true.
* If $Q = 0$, it means that $X_i < X_j$ is false.
* If $Q = -1$, it means that $i$ and $j$ do not satisfy the constraints, or the number of interactions has exceeded $25000$.

For both types of interactions, if the judge's response is $-1$, your program is already considered incorrect. In this case, terminate your program immediately.

When the blackboard contains only one value $\displaystyle\sum_{i=1}^{N}A_i$, report this to the judge in the following format. This does not count towards the number of interactions. Then, terminate your program immediately.

```
!
```

If you make an output in a format that does not match any of the above, `-1` will be given from Standard Input.

```
-1
```

In this case, your program is already considered incorrect. Terminate your program immediately.

### Notes

* **For each output, append a newline at the end and flush Standard Output. Otherwise, the verdict may be TLE.**
* Terminate your program immediately after outputting the result (or receiving `-1`). Otherwise, the verdict will be indeterminate.
* Extra newlines will be considered as malformed output.

---

### Sample Input and Output

Here is a possible conversation with $N=3, R=10, A_1=-1, A_2=10, A_3=1$.

| Input | Output | Explanation |
| --- | --- | --- |
| `3` |  | First, the integer $N$ is given. |
|  | `? 1 2` | Perform a comparison. |
| `1` |  | The judge returns $1$ because $X_1\lt X_2\ (-1\lt 10)$. |
|  | `+ 1 3` | Perform an addition. |
| `4` |  | The judge erases $X_1 = -1$ and $X_3 = 1$ from the blackboard and writes $X_1 + X_3 = 0$. This is the fourth integer written. |
|  | `+ 2 4` | Perform an addition. |
| `5` |  | The judge erases $X_2 = 10$ and $X_4 = 0$ from the blackboard and writes $X_2 + X_4 = 10$. This is the fifth integer written. |
|  | `!` | The blackboard contains only one value $\displaystyle\sum_{i=1}^{N}A_i$, so report this to the judge. |

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

using namespace std;

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

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, 1000, "N");
    long long R = inf.readLong(1LL, 1000000000LL, "R");

    vector<long long> A(N);
    long long expected_sum = 0;
    for (int i = 0; i < N; ++i) {
        A[i] = inf.readLong(-R, R, format("A[%d]", i));
        expected_sum += A[i];
    }

    if (abs(expected_sum) > R) {
        quitf(_fail, "Test case invalid: Sum of A exceeds R");
    }

    log_metrics();

    cout << N << endl;

    vector<long long> values;
    values.reserve(30000);
    values.push_back(0);
    for (long long x : A) values.push_back(x);

    vector<bool> active(N + 1, true);

    int hard_cap = 30000;

    while (true) {
        string type;

        if (!(cin >> type)) {
            finish(_wa, "Unexpected end of output from contestant");
        }

        if (type == "!") {
            int count_active = 0;
            long long remaining_val = 0;
            for (size_t i = 1; i < active.size(); ++i) {
                if (active[i]) {
                    count_active++;
                    remaining_val = values[i];
                }
            }

            if (count_active == 1) {
                if (remaining_val == expected_sum) {
                    finish(_ok, "Correct: One element remaining matching sum");
                } else {
                    finish(_wa, format("Wrong Answer: Remaining element %lld != expected sum %lld", remaining_val, expected_sum));
                }
            } else {
                finish(_wa, format("Wrong Answer: %d elements remaining (expected 1)", count_active));
            }
        }

        queries++;

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

        if (queries > query_limit) {
            cout << -1 << endl;
            finish(_wa, "Query limit exceeded");
        }

        if (type == "+") {
            int i, j;
            if (!(cin >> i >> j)) {
                finish(_wa, "Malformed addition query");
            }

            if (i <= 0 || i >= (int)values.size() || j <= 0 || j >= (int)values.size()) {
                cout << -1 << endl;
                finish(_wa, format("Index out of bounds: %d %d", i, j));
            }
            if (i == j) {
                cout << -1 << endl;
                finish(_wa, format("Indices must be distinct: %d", i));
            }
            if (!active[i] || !active[j]) {
                cout << -1 << endl;
                finish(_wa, format("Index already erased: %d or %d", i, j));
            }

            long long s = values[i] + values[j];
            if (abs(s) > R) {
                cout << -1 << endl;
                finish(_wa, format("Sum %lld exceeds R=%lld", s, R));
            }

            active[i] = false;
            active[j] = false;
            values.push_back(s);
            active.push_back(true);

            cout << (values.size() - 1) << endl;

        } else if (type == "?") {
            int i, j;
            if (!(cin >> i >> j)) {
                finish(_wa, "Malformed comparison query");
            }

            if (i <= 0 || i >= (int)values.size() || j <= 0 || j >= (int)values.size()) {
                cout << -1 << endl;
                finish(_wa, format("Index out of bounds: %d %d", i, j));
            }
            if (i == j) {
                cout << -1 << endl;
                finish(_wa, format("Indices must be distinct: %d", i));
            }
            if (!active[i] || !active[j]) {
                cout << -1 << endl;
                finish(_wa, format("Index already erased: %d or %d", i, j));
            }

            int res = (values[i] < values[j] ? 1 : 0);
            cout << res << endl;

        } else {

            cout << -1 << endl;
            finish(_wa, format("Unknown query type: %s", type.c_str()));
        }

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

    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 = 0;
    if (argc > 1) {
        seed_val = atoi(argv[1]);
    }

    int N;
    long long R;
    vector<long long> A;

    if (seed_val == 1) {

        N = 2;
        R = 10;
        A = {-5, 5};
    } else if (seed_val == 2) {

        N = 1000;
        R = 1000000000;
        A.resize(N);
        for (int i = 0; i < N; ++i) A[i] = (i % 2 == 0 ? R : -R);
    } else if (seed_val == 3) {

        N = 3;
        R = 10;
        A = {-1, 10, 1};
    } else {

        if (rnd.next(2)) N = rnd.next(900, 1000);
        else N = rnd.next(2, 1000);

        if (rnd.next(4) == 0) R = rnd.next(N + 5, 10000);
        else R = rnd.next(100000000LL, 1000000000LL);

        A.resize(N);
        int type = rnd.next(1, 5);

        if (type == 1) {

            for (int i = 0; i < N; ++i) A[i] = rnd.next(-R, R);
        } else if (type == 2) {

            for (int i = 0; i < N; ++i) {
                long long v = rnd.next(max(1LL, R - R / 50), R);
                if (rnd.next(2)) v = -v;
                A[i] = v;
            }
        } else if (type == 3) {

            long long limit = max(1LL, R / N);
            for (int i = 0; i < N; ++i) A[i] = rnd.next(-limit, limit);
        } else if (type == 4) {

            for (int i = 0; i < N; ++i) {
                long long v = rnd.next(1LL, R);
                if (i % 2 == 1) v = -v;
                A[i] = v;
            }
        } else {

            for (int i = 0; i < N; ++i) {
                if (rnd.next(3) == 0) A[i] = 0;
                else A[i] = rnd.next(-R, R);
            }
        }

        for (int iter = 0; iter < 50000; ++iter) {
            long long current_sum = 0;
            for (long long x : A) current_sum += x;

            if (abs(current_sum) <= R) break;

            int idx = rnd.next(N);

            long long ideal = A[idx] - current_sum;

            if (ideal > R) ideal = R;
            if (ideal < -R) ideal = -R;

            A[idx] = ideal;
        }

        long long final_s = 0;
        for (long long x : A) final_s += x;
        if (abs(final_s) > R) {
            for (int i = 0; i < N; ++i) A[i] = rnd.next(-R/N, R/N);
        }
    }

    shuffle(A.begin(), A.end());

    if (mode == "adp") {

        cout << N << " " << R << endl;
    } else {

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

    return 0;
}


### Problem Statement

This is an **interactive problem** (where your program interacts with the judge via input and output).

You are given a positive integer $N$ and integers $L$ and $R$ such that $0 \leq L \leq R < 2^N$. The judge has a hidden sequence $A = (A_0, A_1, \dots, A_{2^N-1})$ consisting of integers between $0$ and $99$, inclusive.

Your goal is to find the remainder when $A_L + A_{L+1} + \dots + A_R$ is divided by $100$. However, you cannot directly know the values of the elements in the sequence $A$. Instead, you can ask the judge the following question:

* Choose non-negative integers $i$ and $j$ such that $2^i(j+1) \leq 2^N$. Let $l = 2^i j$ and $r = 2^i (j+1) - 1$. Ask for the remainder when $A_l + A_{l+1} + \dots + A_r$ is divided by $100$.

Let $m$ be the minimum number of questions required to determine the remainder when $A_L + A_{L+1} + \dots + A_R$ is divided by $100$ for any sequence $A$. You need to find this remainder within $m$ questions.

### Constraints

* $1 \leq N \leq 18$
* $0 \leq L \leq R \leq 2^N - 1$
* All input values are integers.

### Input and Output

This is an interactive problem (where your program interacts with the judge via input and output).

First, read the integers $N$, $L$, and $R$ from Standard Input:

```
$N$ $L$ $R$
```

Then, repeat asking questions until you can determine the remainder when $A_L + A_{L+1} + \dots + A_R$ is divided by $100$. Each question should be printed in the following format:

```
$?$ $i$ $j$
```

Here, $i$ and $j$ must satisfy the following constraints:

* $i$ and $j$ are non-negative integers.
* $2^i(j+1) \leq 2^N$

The response to the question will be given in the following format from Standard Input:

```
$T$
```

Here, $T$ is the answer to the question, which is the remainder when $A_l + A_{l+1} + \dots + A_r$ is divided by $100$, where $l = 2^i j$ and $r = 2^i (j+1) - 1$.

If $i$ and $j$ do not satisfy the constraints, or if the number of questions exceeds $m$, then $T$ will be `-1`.

If the judge returns `-1`, your program is already considered incorrect. In this case, terminate the program immediately.

Once you have determined the remainder when $A_L + A_{L+1} + \dots + A_R$ is divided by $100$, print the remainder $S$ in the following format and terminate the program immediately:

```
$!$ $S$
```

### Notes

* **At the end of each output, print a newline and flush Standard Output. Otherwise, the verdict may be TLE.**
* **If your output is malformed or your program exits prematurely, the verdict will be indeterminate.**
* After printing the answer, terminate the program immediately. Otherwise, the verdict will be indeterminate.

### Example

Here is an example for $N=3$, $L=1$, $R=5$, and $A=(31, 41, 59, 26, 53, 58, 97, 93)$. In this case, $m=3$, so you can ask up to three questions.

| Input | Output | Description |
| --- | --- | --- |
| `3 1 5` |  | First, the integers $N$, $L$, and $R$ are given. |
|  | `? 0 1` | Ask the question with $(i, j) = (0, 1)$. |
| `41` |  | $l=1$ and $r=1$, so the response is the remainder when $A_1=41$ is divided by $100$, which is $41$. The judge returns this value. |
|  | `? 1 1` | Ask the question with $(i, j) = (1, 1)$. |
| `85` |  | $l=2$ and $r=3$, so the response is the remainder when $A_2 + A_3 = 85$ is divided by $100$, which is $85$. The judge returns this value. |
|  | `? 1 2` | Ask the question with $(i, j) = (1, 2)$. |
| `11` |  | $l=4$ and $r=5$, so the response is the remainder when $A_4 + A_5 = 111$ is divided by $100$, which is $11$. The judge returns this value. |
|  | `! 37` | The answer is $37$, so print this value. |

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

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

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

    }
}

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

int get_min_queries(int N, long long start, long long end) {
    if (start == end) return 0;

    long long max_node = 1LL << N;

    vector<int> dist(max_node + 1, -1);

    queue<long long> q;
    dist[start] = 0;
    q.push(start);

    while (!q.empty()) {
        long long u = q.front();
        q.pop();

        if (u == end) return dist[u];

        for (int i = 0; i <= N; ++i) {
            long long len = 1LL << i;

            if (u % len == 0) {

                long long v1 = u + len;
                if (v1 <= max_node && dist[v1] == -1) {
                    dist[v1] = dist[u] + 1;
                    q.push(v1);
                }

                long long v2 = u - len;
                if (v2 >= 0 && dist[v2] == -1) {
                    dist[v2] = dist[u] + 1;
                    q.push(v2);
                }
            }
        }
    }
    return -1;
}

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

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

    int N = inf.readInt();
    long long L = inf.readLong();
    long long R = inf.readLong();

    long long size = 1LL << N;

    vector<int> A(size);
    vector<long long> P(size + 1, 0);

    for (int i = 0; i < size; ++i) {
        A[i] = inf.readInt();
        P[i+1] = P[i] + A[i];
    }

    int m = get_min_queries(N, L, R + 1);
    query_limit = m;

    log_metrics();

    cout << N << " " << L << " " << R << endl;

    while (true) {

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

            finish(_wa, "Unexpected EOF: contestant did not provide answer");
        }

        if (token == "!") {

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

            long long total_sum = P[R+1] - P[L];
            long long expected = total_sum % 100;
            if (expected < 0) expected += 100;

            if (ans == expected) {
                finish(_ok, "Correct answer");
            } else {
                finish(_wa, format("Wrong answer: expected %lld, found %lld", expected, ans));
            }
        } else {

            long long i, j;
            if (token == "?") {
                if (!(cin >> i >> j)) finish(_wa, "Unexpected EOF reading query parameters");
            } else {

                try {
                    size_t idx;
                    i = stoll(token, &idx);
                    if (idx < token.size()) throw exception();
                } catch (...) {
                    finish(_wa, "Malformed token: expected integer or '?'");
                }
                if (!(cin >> j)) finish(_wa, "Unexpected EOF reading j");
            }

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

            if (i < 0 || j < 0) {
                cout << -1 << endl;
                finish(_wa, format("Invalid query: negative parameters i=%lld j=%lld", i, j));
            }
            if (i > N) {
                cout << -1 << endl;
                finish(_wa, format("Invalid query: i=%lld > N=%d", i, N));
            }

            long long len = 1LL << i;
            long long right_boundary = len * (j + 1);
            long long max_idx = 1LL << N;

            if (right_boundary > max_idx) {
                cout << -1 << endl;
                finish(_wa, format("Invalid query: interval end %lld > 2^N", right_boundary));
            }

            if (queries > query_limit) {
                cout << -1 << endl;
                finish(_wa, format("Query limit exceeded: used %lld, limit %lld", queries, query_limit));
            }

            long long l_idx = len * j;
            long long r_idx = right_boundary - 1;
            long long range_sum = P[r_idx + 1] - P[l_idx];
            long long rem = range_sum % 100;
            if (rem < 0) rem += 100;

            cout << rem << endl;

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

    return 0;
}

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

using namespace std;

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

vector<int> parent;
vector<int> weight_diff;

void init_dsu(int n) {
    parent.resize(n + 1);
    iota(parent.begin(), parent.end(), 0);
    weight_diff.assign(n + 1, 0);
}

pair<int, int> find_set(int i) {
    if (parent[i] == i) return {i, 0};
    pair<int, int> root_res = find_set(parent[i]);
    parent[i] = root_res.first;

    weight_diff[i] = (weight_diff[i] + root_res.second) % 100;
    return {parent[i], weight_diff[i]};
}

bool union_sets(int u, int v, int w) {
    pair<int, int> root_u = find_set(u);
    pair<int, int> root_v = find_set(v);

    int ru = root_u.first;
    int rv = root_v.first;

    if (ru != rv) {

        int diff = (w - root_v.second + root_u.second) % 100;

        int new_weight = (-diff) % 100;
        if (new_weight < 0) new_weight += 100;

        parent[ru] = rv;
        weight_diff[ru] = new_weight;
        return true;
    } else {
        int implied = (root_v.second - root_u.second) % 100;
        if (implied < 0) implied += 100;
        return (implied == w);
    }
}

int get_diff(int u, int v) {
    pair<int, int> root_u = find_set(u);
    pair<int, int> root_v = find_set(v);
    if (root_u.first != root_v.first) return -1;
    int res = (root_v.second - root_u.second) % 100;
    if (res < 0) res += 100;
    return res;
}

long long compute_min_queries(int N, long long L, long long R) {
    long long target = R + 1;
    if (L == target) return 0;

    long long max_node = (1LL << N);
    vector<int> dist(max_node + 1, -1);
    queue<long long> q;

    dist[L] = 0;
    q.push(L);

    while (!q.empty()) {
        long long u = q.front();
        q.pop();

        if (u == target) return dist[u];

        for (int i = 0; i <= N; i++) {
            long long len = (1LL << i);
            if (u % len == 0) {

                long long v1 = u + len;
                if (v1 <= max_node && dist[v1] == -1) {
                    dist[v1] = dist[u] + 1;
                    if (v1 == target) return dist[v1];
                    q.push(v1);
                }

                long long v2 = u - len;
                if (v2 >= 0 && dist[v2] == -1) {
                    dist[v2] = dist[u] + 1;
                    if (v2 == target) return dist[v2];
                    q.push(v2);
                }
            }
        }
    }
    return -1;
}

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();
    long long L = inf.readLong();
    long long R = inf.readLong();

    query_limit = compute_min_queries(N, L, R);

    cout << N << " " << L << " " << R << endl;

    init_dsu(1 << N);

    while (true) {

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

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

        if (type == "!") {
            long long ans;
            if (!(cin >> ans)) finish(_pe, "Expected answer after '!'");

            int needed = get_diff(L, R + 1);
            if (needed == -1) {

                finish(_wa, "Answer provided but remainder not uniquely determined by queries");
            } else {
                if (ans == needed) finish(_ok, "Correct");
                else finish(_wa, "Incorrect remainder");
            }
            break;
        } else if (type == "?") {
            queries++;

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

            if (queries > query_limit) {
                cout << -1 << endl;
                finish(_wa, "Query limit exceeded (m)");
            }

            int i;
            long long j;
            if (!(cin >> i >> j)) finish(_pe, "Invalid query format");

            if (i < 0 || j < 0) finish(_pe, "Indices must be non-negative");
            if (i > N) finish(_pe, "i too large");

            long long two_i = (1LL << i);
            long long limit = (1LL << N);

            if (two_i * (j + 1) > limit) {
                cout << -1 << endl;
                finish(_wa, "Query parameter out of bounds");
            }

            long long u = two_i * j;
            long long v = two_i * (j + 1);

            int diff = get_diff(u, v);
            int reply;
            if (diff != -1) {

                reply = diff;
            } else {

                reply = (int)((u * 10007 + v * 31337 + queries * 1337) % 100);
                union_sets(u, v, reply);
            }

            cout << reply << endl;

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

    return 0;
}

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

using namespace std;

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

    registerGen(argc, argv, 1);

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

    long long seed_num = -1;
    if (argc > 1) {
        string s = argv[1];
        bool is_num = true;
        for (char c : s) {
            if (!isdigit(c)) {
                is_num = false;
                break;
            }
        }
        if (is_num && !s.empty()) {
            try {
                seed_num = stoll(s);
            } catch (...) {
                seed_num = -1;
            }
        }
    }

    int N;
    long long L, R;

    if (seed_num == 1) {

        N = 1;
        L = 0; R = 1;
    } else if (seed_num == 2) {

        N = 18;
        L = 0; R = (1LL << N) - 1;
    } else if (seed_num == 3) {

        N = 18;
        L = (1LL << 17);
        R = L;
    } else {

        int p = rnd.next(1, 100);
        if (p <= 10) N = rnd.next(1, 5);
        else if (p <= 30) N = rnd.next(6, 17);
        else N = 18;

        long long max_cnt = (1LL << N);
        long long max_idx = max_cnt - 1;

        int type = rnd.next(1, 10);
        if (type == 1) {

            L = 0; R = max_idx;
        } else if (type == 2) {

            L = rnd.next(0LL, max_idx);
            R = L;
        } else if (type == 3) {

            L = 0;
            R = rnd.next(0LL, max_idx);
        } else if (type == 4) {

            R = max_idx;
            L = rnd.next(0LL, max_idx);
        } else if (type <= 6) {

            L = rnd.next(0LL, max_idx);
            long long max_len = min(100LL, max_idx - L);
            if (max_len < 0) max_len = 0;
            long long len = rnd.next(0LL, max_len);
            R = L + len;
        } else {

            long long a = rnd.next(0LL, max_idx);
            long long b = rnd.next(0LL, max_idx);
            L = min(a, b);
            R = max(a, b);
        }
    }

    cout << N << " " << L << " " << R << endl;

    if (mode == "non") {
        int size = 1 << N;
        vector<int> A(size);
        for (int i = 0; i < size; i++) {
            A[i] = rnd.next(0, 99);
        }
        for (int i = 0; i < size; i++) {
            if (i > 0) cout << " ";
            cout << A[i];
        }
        cout << endl;
    }

    return 0;
}