This is an interactive problem.

There are $n$ words in a text editor. The $i$-th word has length $l_i$ ($1 \leq l_i \leq 2000$). The array $l$ is hidden and only known by the grader.

The text editor displays words in lines, splitting each two words in a line with at least one space. Note that a line does not have to end with a space. Let the height of the text editor refer to the number of lines used. For the given width, the text editor will display words in such a way that the height is minimized.

More formally, suppose that the text editor has width $w$. Let $a$ be an array of length $k+1$ where $1=a_1 < a_2 < \ldots < a_{k+1}=n+1$. $a$ is a valid array if for all $1 \leq i \leq k$, $l_{a_i}+1+l_{a_i+1}+1+\ldots+1+l_{a_{i+1}-1} \leq w$. Then the height of the text editor is the minimum $k$ over all valid arrays.

Note that if $w < \max(l_i)$, the text editor cannot display all the words properly and will crash, and the height of the text editor will be $0$ instead.

You can ask $n+30$ queries. In one query, you provide a width $w$. Then, the grader will return the height $h_w$ of the text editor when its width is $w$.

Find the minimum area of the text editor, which is the minimum value of $w \cdot h_w$ over all $w$ for which $h_w \neq 0$.

The lengths are fixed in advance. In other words, the interactor is not adaptive.

Input

The first and only line of input contains a single integer $n$ ($1 \leq n \leq 2000$)  — the number of words on the text editor.

It is guaranteed that the hidden lengths $l_i$ satisfy $1 \leq l_i \leq 2000$.

Interaction

Begin the interaction by reading $n$.

To make a query, print "? $w$" (without quotes, $1 \leq w \leq 10^9$). Then you should read our response from standard input, that is, $h_w$.

If your program has made an invalid query or has run out of tries, the interactor will terminate immediately and your program will get a verdict Wrong answer.

To give the final answer, print "! $area$" (without the quotes). Note that giving this answer is not counted towards the limit of $n+30$ queries.

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

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

Example

Input

```
6

0

4

2
```

Output

```
? 1

? 9

? 16

! 32
```

Note

In the first test case, the words are $\{\texttt{glory},\texttt{to},\texttt{ukraine},\texttt{and},\texttt{anton},\texttt{trygub}\}$, so $l=\{5,2,7,3,5,6\}$.

If $w=1$, then the text editor is not able to display all words properly and will crash. The height of the text editor is $h_1=0$, so the grader will return $0$.

If $w=9$, then a possible way that the words will be displayed on the text editor is:

* $\texttt{glory__to}$
* $\texttt{ukraine__}$
* $\texttt{and_anton}$
* $\texttt{__trygub_}$

The height of the text editor is $h_{9}=4$, so the grader will return $4$.

If $w=16$, then a possible way that the words will be displayed on the text editor is:

* $\texttt{glory_to_ukraine}$
* $\texttt{and_anton_trygub}$

The height of the text editor is $h_{16}=2$, so the grader will return $2$.

We have somehow figured out that the minimum area of the text editor is $32$, so we answer it.

#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 calculate_height(const vector<int>& l, long long w, int max_l) {
    if (w < max_l) return 0;

    int lines = 1;
    long long current_len = 0;

    for (int val : l) {
        if (current_len == 0) {

            current_len = val;
        } else {

            if (current_len + 1 + val <= w) {
                current_len += 1 + val;
            } else {

                lines++;
                current_len = val;
            }
        }
    }
    return lines;
}

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

    registerInteraction(argc, argv);

    atexit(log_metrics);

    int n = inf.readInt();
    vector<int> l(n);
    int max_l = 0;
    long long sum_l = 0;
    for (int i = 0; i < n; i++) {
        l[i] = inf.readInt();
        if (l[i] > max_l) max_l = l[i];
        sum_l += l[i];
    }

    query_limit = n + 30;

    log_metrics();

    long long correct_area = -1;
    long long max_possible_w = sum_l + n;

    for (int h = 1; h <= n; h++) {

        long long low = max_l;
        long long high = max_possible_w;
        long long best_w = -1;

        long long est = (sum_l + h - 1) / h;
        if (est > low) low = est;
        if (low < max_l) low = max_l;

        while (low <= high) {
            long long mid = low + (high - low) / 2;
            int res = calculate_height(l, mid, max_l);
            if (res != 0 && res <= h) {
                best_w = mid;
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }

        if (best_w != -1) {

            int actual_h = calculate_height(l, best_w, max_l);
            if (actual_h != 0) {
                long long area = best_w * actual_h;
                if (correct_area == -1 || area < correct_area) {
                    correct_area = area;
                }
            }
        }
    }

    cout << n << endl;

    long long hard_cap = 200000;

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

        string token;
        if (!(cin >> token)) {
            finish(_wa, "Unexpected EOF (did not receive answer)");
        }

        bool is_query = false;
        bool is_ans = false;
        long long val = -1;

        if (token == "?") {
            is_query = true;
            if (!(cin >> val)) finish(_wa, "Expected width after '?'");
        } else if (token == "!") {
            is_ans = true;
            if (!(cin >> val)) finish(_wa, "Expected answer after '!'");
        } else if (!token.empty() && token[0] == '!') {
            is_ans = true;
            try {
                if (token.size() == 1) {
                     if (!(cin >> val)) finish(_wa, "Expected answer after '!'");
                } else {
                     val = stoll(token.substr(1));
                }
            } catch (...) {
                finish(_wa, "Invalid answer format");
            }
        } else if (!token.empty() && token[0] == '?') {
            is_query = true;
            try {
                if (token.size() == 1) {
                     if (!(cin >> val)) finish(_wa, "Expected width after '?'");
                } else {
                     val = stoll(token.substr(1));
                }
            } catch (...) {
                finish(_wa, "Invalid query format");
            }
        } else {

            try {
                val = stoll(token);
                is_query = true;
            } catch (...) {
                finish(_wa, "Invalid token (expected integer or '?'/'!')");
            }
        }

        if (is_ans) {
            if (val == correct_area) {
                finish(_ok, "Correct area found: " + to_string(val));
            } else {
                finish(_wa, "Incorrect area. Expected " + to_string(correct_area) + ", got " + to_string(val));
            }
        } else if (is_query) {

            queries++;

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

            if (val < 1 || val > 1000000000LL) {
                 finish(_wa, "Query width out of bounds [1, 10^9]");
            }

            int h = calculate_height(l, val, max_l);
            cout << h << endl;
        }
    }

    return 0;
}

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

using namespace std;

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

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

    string seedStr = (argc > 1) ? string(argv[1]) : "";

    vector<int> l;
    bool specific = false;

    if (n == -1) {
        if (seedStr == "1") {

            n = 6;
            l = {5, 2, 7, 3, 5, 6};
            specific = true;
        } else if (seedStr == "2") {

            n = 2000;
            l.assign(n, 2000);
            specific = true;
        } else if (seedStr == "3") {

            n = 2000;
            l.assign(n, 1);
            specific = true;
        } else {

            if (rnd.next(10) == 0) {
                n = rnd.next(1, 100);
            } else {
                n = rnd.next(1000, 2000);
            }
        }
    }

    if (!specific) {
        l.resize(n);

        int strat = rnd.next(7);

        if (strat == 0) {
            for (int i = 0; i < n; i++) l[i] = rnd.next(1, 2000);
        } else if (strat == 1) {
            for (int i = 0; i < n; i++) l[i] = rnd.next(1, 10);
        } else if (strat == 2) {
            for (int i = 0; i < n; i++) l[i] = rnd.next(1900, 2000);
        } else if (strat == 3) {
            for (int i = 0; i < n; i++) l[i] = (rnd.next(2) ? 1 : 2000);
        } else if (strat == 4) {
            for (int i = 0; i < n; i++) {
                long long val = 1 + (1999LL * i) / (n > 1 ? n - 1 : 1);
                l[i] = (int)val;
            }
        } else if (strat == 5) {
            for (int i = 0; i < n; i++) {
                long long val = 2000 - (1999LL * i) / (n > 1 ? n - 1 : 1);
                l[i] = (int)val;
            }
        } else {
            int mean = rnd.next(1, 2000);
            int dev = rnd.next(10, 500);
            for (int i = 0; i < n; i++) {

                int val = mean + rnd.next(-dev, dev) + rnd.next(-dev, dev);
                val = max(1, min(2000, val));
                l[i] = val;
            }
        }

        if (rnd.next(5) != 0) {
            shuffle(l.begin(), l.end());
        }
    }

    if (mode == "non") {

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

        cout << n << endl;
    }

    return 0;
}


Gustaw is the chief bank manager in a huge bank. He has unlimited access to the database system of the bank, in a few clicks he can move any amount of money from the bank's reserves to his own private account. However, the bank uses some fancy AI fraud detection system that makes stealing more difficult.

Gustaw knows that the anti-fraud system just detects any operation that exceeds some fixed limit $M$ euros and these operations are checked manually by a number of clerks. Thus, any fraud operation exceeding this limit is detected, while any smaller operation gets unnoticed.

Gustaw doesn't know the limit $M$ and wants to find it out. In one operation, he can choose some integer $X$ and try to move $X$ euros from the bank's reserves to his own account. Then, the following happens.

* If $X \le M$, the operation is unnoticed and Gustaw's account balance raises by $X$ euros.
* Otherwise, if $X > M$, the fraud is detected and cancelled. Moreover, Gustaw has to pay $X$ euros from his own account as a fine. If he has less than $X$ euros on the account, he is fired and taken to the police.

Initially Gustaw has $1$ euro on his account. Help him find the exact value of $M$ in no more than $105$ operations without getting him fired.

Input

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

For each test case, there is no input prior to your first query, but you can be sure that $M$ is integer, and $0 \le M \le 10^{14}$.

Output

For each test case, when you know the exact value of $M$, print a single line with format "! $M$". After that your program should proceed to the next test case or terminate, if it is the last one.

Interaction

When you want to make an operation, print a single line with format "? $X$", denoting that you try to move $X$ euros ($1 \le X \le 10^{14}$). As a response, read a single line that can take the following values:

* "Lucky!", if $X \le M$. Your balance raises by $X$.
* "Fraudster!", if $X > M$. Your balance decreases by $X$.
* "Fired!", if $X > M$, but you can't pay $X$ euros of fine. In this case your program must terminate immediately. You also get this response if you exceed the number of queries.

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

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

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

Example

Input

```
1

Lucky!

Lucky!

Lucky!

Lucky!

Lucky!

Fraudster!
```

Output

```
? 1

? 2

? 3

? 4

? 5

? 6

! 5
```

Note

In the example $M = 5$, so the operation with $X = 6$ is detected. At this moment, Gustaw's balance is $16$ euros, so he just pays fine.

#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 parseNonNegLL(const string& s, long long& out) {
    if (s.empty()) return false;
    __int128 v = 0;
    for (char c : s) {
        if (c < '0' || c > '9') return false;
        v = v * 10 + (c - '0');
        if (v > (__int128)LLONG_MAX) return false;
    }
    out = (long long)v;
    return true;
}

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

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

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

    const long long MIN_M = 0;
    const long long MAX_M = 100000000000000LL;
    const long long MIN_X = 1;
    const long long MAX_X = 100000000000000LL;
    const long long PER_CASE_LIMIT = 100000;

    int t = inf.readInt(1, 1000, "t");
    vector<long long> vals;
    while (!inf.seekEof()) {
        vals.push_back(inf.readLong(MIN_M, MAX_M, "val"));
    }

    bool adaptive = false;
    if ((int)vals.size() == t) adaptive = false;
    else if ((int)vals.size() == 2 * t) adaptive = true;
    else {
        query_limit = PER_CASE_LIMIT * 1LL * max(1, t);
        log_metrics();
        finish(_pe, "bad hidden input: expected t numbers (non) or 2*t numbers (adp)");
    }

    query_limit = PER_CASE_LIMIT * 1LL * t;
    log_metrics();

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

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

    for (int tc = 0; tc < t; tc++) {
        long long lo, hi;
        if (!adaptive) {
            lo = hi = vals[tc];
        } else {
            lo = vals[2 * tc];
            hi = vals[2 * tc + 1];
        }

        if (!(MIN_M <= lo && lo <= hi && hi <= MAX_M)) {
            finish(_pe, "bad hidden input interval/value out of range");
        }

        __int128 bal = 1;
        long long used_tc = 0;

        while (true) {
            if (queries > hard_cap) finish(_pe, "too many queries (hard cap exceeded)");

            string tok;
            if (!readToken(tok)) {
                finish(_pe, "unexpected EOF from contestant");
            }

            char type = 0;
            string rest;
            if (!tok.empty() && (tok[0] == '?' || tok[0] == '!')) {
                type = tok[0];
                rest = tok.substr(1);
            } else {
                finish(_pe, "invalid token (expected ? or !)");
            }

            if (type == '?') {
                string numTok;
                if (!rest.empty()) numTok = rest;
                else {
                    if (!readToken(numTok)) finish(_pe, "expected X after ?");
                }

                long long X;
                if (!parseNonNegLL(numTok, X)) finish(_pe, "X is not a non-negative integer");
                if (X < MIN_X || X > MAX_X) finish(_pe, "X out of allowed range");

                used_tc++;
                queries++;
                if (queries > hard_cap) finish(_pe, "too many queries (hard cap exceeded)");

                if (used_tc > PER_CASE_LIMIT) {
                    cout << "Fired!\n";
                    cout.flush();
                    finish(_wa, "query limit exceeded");
                }

                bool mustLucky = (lo >= X);
                bool mustFraud = (hi < X);

                string reply;
                if (mustLucky) {
                    reply = "Lucky!";
                    lo = max(lo, X);
                    bal += (__int128)X;
                } else if (mustFraud) {
                    if (bal < (__int128)X) {
                        cout << "Fired!\n";
                        cout.flush();
                        finish(_wa, "fired: insufficient balance to pay fine");
                    }
                    reply = "Fraudster!";
                    hi = min(hi, X - 1);
                    bal -= (__int128)X;
                } else {

                    if (bal < (__int128)X) {
                        reply = "Lucky!";
                        lo = max(lo, X);
                        bal += (__int128)X;
                    } else {
                        long long loL = max(lo, X), hiL = hi;
                        long long loF = lo, hiF = min(hi, X - 1);

                        __int128 lenL = (loL <= hiL) ? (__int128)(hiL - loL + 1) : 0;
                        __int128 lenF = (loF <= hiF) ? (__int128)(hiF - loF + 1) : 0;

                        bool chooseFraud = false;
                        if (lenF > lenL) chooseFraud = true;
                        else if (lenF < lenL) chooseFraud = false;
                        else chooseFraud = true;

                        if (chooseFraud) {
                            reply = "Fraudster!";
                            hi = hiF;
                            bal -= (__int128)X;
                        } else {
                            reply = "Lucky!";
                            lo = loL;
                            bal += (__int128)X;
                        }
                    }
                }

                if (lo > hi) finish(_pe, "internal error: feasible interval became empty");
                if (bal < 0) finish(_pe, "internal error: negative balance without firing");

                cout << reply << "\n";
                cout.flush();
            } else {
                string numTok;
                if (!rest.empty()) numTok = rest;
                else {
                    if (!readToken(numTok)) finish(_pe, "expected M after !");
                }

                long long ans;
                if (!parseNonNegLL(numTok, ans)) finish(_pe, "answer is not a non-negative integer");
                if (ans < MIN_M || ans > MAX_M) finish(_pe, "answer out of allowed range");

                if (ans < lo || ans > hi) finish(_wa, "wrong answer: not consistent with interaction");
                if (lo != hi) finish(_wa, "wrong answer: M not uniquely determined");
                break;
            }
        }
    }

    finish(_ok, "OK");
}

#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 vector<long long> buildSpecials(long long minM, long long maxM) {
    vector<long long> s;
    auto add = [&](long long x) {
        if (x < minM || x > maxM) return;
        s.push_back(x);
    };

    add(minM);
    add(minM + 1);
    add(minM + 2);
    add(1);
    add(2);
    add(3);
    add(4);
    add(5);
    add(6);
    add(7);
    add(8);
    add(9);
    add(10);

    add(maxM);
    add(maxM - 1);
    add(maxM - 2);
    add(maxM - 3);
    add(maxM - 4);
    add(maxM - 5);

    add(maxM / 2);
    add(maxM / 2 - 1);
    add(maxM / 2 + 1);

    __int128 p10 = 1;
    for (int k = 0; k <= 14; k++) {
        long long v = (long long)p10;
        add(v - 1);
        add(v);
        add(v + 1);
        if (v <= maxM) {
            add(maxM - v);
            add(maxM - v - 1);
            add(maxM - v + 1);
        }
        p10 *= 10;
        if (p10 > (__int128)maxM + 100) break;
    }

    for (int e = 0; e <= 62; e++) {
        __int128 p = (__int128)1 << e;
        if (p > (__int128)maxM + 2) break;
        long long pv = (long long)p;
        add(pv - 2);
        add(pv - 1);
        add(pv);
        add(pv + 1);
        add(pv + 2);
        add(pv * 3 / 2);
        add(pv * 2 - 1);
        add(pv * 2);
        add(pv * 2 + 1);
    }

    add(99999999999999LL);
    add(99999999999998LL);
    add(99999999999997LL);
    add(10000000000000LL);
    add(10000000000001LL);
    add(50000000000000LL);
    add(33333333333333LL);
    add(66666666666666LL);
    add(77777777777777LL);
    add(22222222222222LL);
    add(12345678901234LL);
    add(98765432109876LL);

    add(maxM / 4);
    add(maxM / 4 - 1);
    add(maxM / 4 + 1);
    add((maxM * 3) / 4);
    add((maxM * 3) / 4 - 1);
    add((maxM * 3) / 4 + 1);

    return s;
}

static long long genRandomM(long long minM, long long maxM, const vector<long long>& specials) {
    int type = rnd.next(0, 99);

    auto nearVal = [&](long long center, long long spread) -> long long {
        long long delta = rnd.next(-spread, spread);
        return clampLL(center + delta, minM, maxM);
    };

    if (type < 30) {
        return rnd.next(minM, maxM);
    } else if (type < 45) {

        long long spread = rnd.next(0LL, 2000000LL);
        return clampLL(maxM - spread, minM, maxM);
    } else if (type < 55) {

        long long spread = rnd.next(0LL, 2000000LL);
        return clampLL(minM + spread, minM, maxM);
    } else if (type < 70) {

        int e = rnd.next(0, 47);
        long long p = (e >= 0 && e < 62) ? (1LL << e) : 1LL;
        if (p > maxM) p = maxM;
        long long d = rnd.next(-3LL, 3LL);
        return clampLL(p + d, minM, maxM);
    } else if (type < 82) {

        int k = rnd.next(0, 14);
        __int128 p10 = 1;
        for (int i = 0; i < k; i++) p10 *= 10;
        long long base = (p10 > (__int128)maxM) ? maxM : (long long)p10;
        long long d = rnd.next(-5LL, 5LL);
        return clampLL(base + d, minM, maxM);
    } else if (type < 90) {

        int e = rnd.next(0, 47);
        long long base = (e == 0) ? 0LL : ((1LL << e) - 1);
        if (base > maxM) base = maxM;
        long long room = maxM - base;
        long long extra = 0;
        if (room > 0) {
            long long lim = min(room, (1LL << min(20, e)) - 1);
            extra = rnd.next(0LL, lim);
        }
        return clampLL(base + extra, minM, maxM);
    } else {

        long long pick = specials.empty() ? rnd.next(minM, maxM) : specials[rnd.next(0, (int)specials.size() - 1)];
        long long spread = rnd.next(0LL, 10000000LL);
        return nearVal(pick, spread);
    }
}

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

    string mode = opt<string>("mode", "non");
    int t = opt<int>("t", 1000);
    long long minM = opt<long long>("minM", 0LL);
    long long maxM = opt<long long>("maxM", 100000000000000LL);

    ensuref(1 <= t && t <= 1000, "t must be in [1..1000]");
    ensuref(0LL <= minM && minM <= maxM, "require 0 <= minM <= maxM");
    ensuref(maxM <= 100000000000000LL, "maxM must be <= 1e14");

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

    vector<long long> specials = buildSpecials(minM, maxM);

    cout << t << "\n";

    if (mode == "non") {
        vector<long long> M(t, minM);

        int offset = 0;
        if (!specials.empty()) offset = (int)(seed % (long long)specials.size());

        for (int i = 0; i < t; i++) {
            if (seed == 1) {

                if (i % 50 == 0) M[i] = 0;
                else if (i % 50 == 1) M[i] = 1;
                else if (i % 50 == 2) M[i] = maxM;
                else if (i % 50 == 3) M[i] = maxM - 1;
                else if (i < (int)specials.size()) M[i] = specials[(i + offset) % specials.size()];
                else M[i] = genRandomM(minM, maxM, specials);
            } else if (seed == 2) {

                if (i < 25) M[i] = clampLL(i, minM, maxM);
                else if (i % 40 == 0) M[i] = 0;
                else if (i % 40 == 1) M[i] = 2;
                else if (i % 40 == 2) M[i] = 3;
                else if (i % 40 == 3) M[i] = 4;
                else if (i % 40 == 4) M[i] = 7;
                else if (i % 40 == 5) M[i] = 8;
                else if (i % 40 == 6) M[i] = 15;
                else if (i % 40 == 7) M[i] = 16;
                else if (i % 40 == 8) M[i] = 31;
                else if (i % 40 == 9) M[i] = 32;
                else if (i < (int)specials.size()) M[i] = specials[(i * 7 + offset) % specials.size()];
                else M[i] = genRandomM(minM, maxM, specials);
            } else if (seed == 3) {

                if (i < 60) M[i] = clampLL(maxM - i, minM, maxM);
                else if (i % 37 == 0) M[i] = maxM;
                else if (i % 37 == 1) M[i] = maxM - 1;
                else if (i % 37 == 2) M[i] = maxM / 2;
                else if (i % 37 == 3) M[i] = (1LL << 46) - 1;
                else if (i % 37 == 4) M[i] = (1LL << 46);
                else if (i % 37 == 5) M[i] = (1LL << 45) - 1;
                else if (i < (int)specials.size()) M[i] = specials[(i * 13 + offset) % specials.size()];
                else M[i] = genRandomM(minM, maxM, specials);
            } else {

                if (!specials.empty() && i < (int)specials.size() / 2) {
                    M[i] = specials[(i + offset) % specials.size()];
                } else if (i % 64 == 0) {
                    M[i] = 0;
                } else if (i % 64 == 1) {
                    M[i] = maxM;
                } else if (i % 64 == 2) {
                    M[i] = maxM - 1;
                } else if (i % 64 == 3) {
                    M[i] = maxM / 2;
                } else {
                    M[i] = genRandomM(minM, maxM, specials);
                }
            }
        }

        for (int i = 0; i < t; i++) {
            cout << M[i] << "\n";
        }
    } else if (mode == "adp") {

        for (int i = 0; i < t; i++) {
            long long L = minM, R = maxM;

            if (seed == 1) {
                if (i == 0) { L = 0; R = 0; }
                else if (i == 1) { L = maxM; R = maxM; }
                else if (i == 2) { L = 0; R = 1; }
                else if (i == 3) { L = maxM - 1; R = maxM; }
                else if (i == 4) { L = maxM / 2; R = maxM / 2; }
                else if (i % 20 == 0) { L = 0; R = maxM; }
                else {
                    long long c = specials.empty() ? rnd.next(minM, maxM) : specials[(i * 11) % (int)specials.size()];
                    long long w = rnd.next(0LL, 2000LL);
                    L = clampLL(c - w, minM, maxM);
                    R = clampLL(c + w, minM, maxM);
                }
            } else if (seed == 2) {
                if (i < 10) { L = i; R = i; }
                else if (i % 25 == 0) { L = 0; R = maxM; }
                else {
                    long long c = rnd.next(minM, maxM);
                    long long w = rnd.next(0LL, 100000LL);
                    L = clampLL(c - w, minM, maxM);
                    R = clampLL(c + w, minM, maxM);
                }
            } else if (seed == 3) {
                if (i < 10) { L = clampLL(maxM - i, minM, maxM); R = L; }
                else if (i % 30 == 0) { L = 0; R = maxM; }
                else {
                    long long c = clampLL(maxM - rnd.next(0LL, 5000000LL), minM, maxM);
                    long long w = rnd.next(0LL, 5000LL);
                    L = clampLL(c - w, minM, maxM);
                    R = clampLL(c + w, minM, maxM);
                }
            } else {

                int roll = rnd.next(0, 99);
                if (roll < 80) {
                    L = minM; R = maxM;
                } else if (roll < 90) {
                    long long c = specials.empty() ? rnd.next(minM, maxM) : specials[rnd.next(0, (int)specials.size() - 1)];
                    long long w = rnd.next(0LL, 50000LL);
                    L = clampLL(c - w, minM, maxM);
                    R = clampLL(c + w, minM, maxM);
                } else {

                    long long c = genRandomM(minM, maxM, specials);
                    L = c; R = c;
                }
            }

            if (L > R) swap(L, R);
            cout << L << " " << R << "\n";
        }
    } else {
        quitf(_fail, "Unknown --mode value: %s", mode.c_str());
    }

    return 0;
}


This is an interactive problem!

An arithmetic progression or arithmetic sequence is a sequence of integers such that the subtraction of element with its previous element ($x_i - x_{i - 1}$, where $i \ge 2$) is constant — such difference is called a common difference of the sequence.

That is, an arithmetic progression is a sequence of form $x_i = x_1 + (i - 1) d$, where $d$ is a common difference of the sequence.

There is a secret list of $n$ integers $a_1, a_2, \ldots, a_n$.

It is guaranteed that all elements $a_1, a_2, \ldots, a_n$ are between $0$ and $10^9$, inclusive.

This list is special: if sorted in increasing order, it will form an arithmetic progression with positive common difference ($d > 0$). For example, the list $[14, 24, 9, 19]$ satisfies this requirement, after sorting it makes a list $[9, 14, 19, 24]$, which can be produced as $x_n = 9 + 5 \cdot (n - 1)$.

Also you are also given a device, which has a quite discharged battery, thus you can only use it to perform at most $60$ queries of following two types:

* Given a value $i$ ($1 \le i \le n$), the device will show the value of the $a_i$.
* Given a value $x$ ($0 \le x \le 10^9$), the device will return $1$ if an element with a value strictly greater than $x$ exists, and it will return $0$ otherwise.

Your can use this special device for at most $60$ queries. Could you please find out the smallest element and the common difference of the sequence? That is, values $x_1$ and $d$ in the definition of the arithmetic progression. Note that the array $a$ is not sorted.

Interaction

The interaction starts with a single integer $n$ ($2 \le n \le 10^6$), the size of the list of integers.

Then you can make queries of two types:

* "? i" ($1 \le i \le n$) — to get the value of $a_i$.
* "> x" ($0 \le x \le 10^9$) — to check whether there exists an element greater than $x$

After the query read its result $r$ as an integer.

* For the first query type, the $r$ satisfies $0 \le r \le 10^9$.
* For the second query type, the $r$ is either $0$ or $1$.
* In case you make more than $60$ queries or violated the number range in the queries, you will get a $r = -1$.
* If you terminate after receiving the -1, you will get the "Wrong answer" verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.

When you find out what the smallest element $x_1$ and common difference $d$, print

* "! $x_1$ $d$"

And quit after that. This query is not counted towards the $60$ queries limit.

After printing any query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:

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

Example

Input

```
4

0

1

14

24

9

19
```

Output

```
> 25

> 15

? 1

? 2

? 3

? 4

! 9 5
```

Note

Note that the example interaction contains extra empty lines so that it's easier to read. The real interaction doesn't contain any empty lines and you shouldn't print any extra empty lines as well.

The list in the example test is $[14, 24, 9, 19]$.

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

using namespace std;

static long long queries = 0;

static const long long query_limit = 60;

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

    if (n < 2) {
        finish(_fail, "Generator error: n < 2");
    }

    vector<long long> a(n);
    long long min_val = -1;
    long long max_val = -1;

    for (int i = 0; i < n; ++i) {
        a[i] = inf.readLong();

        if (i == 0) {
            min_val = a[i];
            max_val = a[i];
        } else {
            if (a[i] < min_val) min_val = a[i];
            if (a[i] > max_val) max_val = a[i];
        }
    }

    long long true_x1 = min_val;
    long long true_d = (max_val - min_val) / (n - 1);

    cout << n << endl;

    long long hard_cap = 500;

    while (true) {

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

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

            finish(_pe, "Unexpected EOF: expected query or answer");
        }

        if (type == "!") {

            long long ans_x1, ans_d;
            if (!(cin >> ans_x1 >> ans_d)) {
                finish(_pe, "Invalid final answer format");
            }

            if (ans_x1 == true_x1 && ans_d == true_d) {
                finish(_ok, "Correct");
            } else {
                string msg = "Expected " + to_string(true_x1) + " " + to_string(true_d) +
                             ", got " + to_string(ans_x1) + " " + to_string(ans_d);
                finish(_wa, msg);
            }
        } else if (type == "?") {

            int i;
            if (!(cin >> i)) {
                finish(_pe, "Invalid format for '?' query");
            }
            queries++;

            if (i < 1 || i > n) {
                finish(_wa, "Index out of range: " + to_string(i));
            }

            cout << a[i-1] << endl;
        } else if (type == ">") {

            long long x;
            if (!(cin >> x)) {
                finish(_pe, "Invalid format for '>' query");
            }
            queries++;

            if (x < 0 || x > 1000000000LL) {
                finish(_wa, "Value out of range: " + to_string(x));
            }

            cout << (max_val > x ? 1 : 0) << endl;
        } else {
            finish(_pe, "Unknown token: " + type);
        }

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

    return 0;
}

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

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

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

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

    atexit(log_metrics);

    int n = inf.readInt();

    char sep = inf.readChar();

    if (sep == '\r') {
        inf.readChar();
        sep = '\n';
    }

    bool is_adaptive = (sep == ' ');

    vector<long long> a;
    long long x1_secret, d_secret;

    if (is_adaptive) {

        x1_secret = inf.readLong();
        d_secret = inf.readLong();

        a.resize(n);
        for(int i=0; i<n; ++i) {
            a[i] = x1_secret + (long long)i * d_secret;
        }

        shuffle(a.begin(), a.end());
    } else {

        a.resize(n);
        for(int i=0; i<n; ++i) {
            a[i] = inf.readLong();
        }

        vector<long long> sorted_a = a;
        sort(sorted_a.begin(), sorted_a.end());
        x1_secret = sorted_a[0];

        d_secret = sorted_a[1] - sorted_a[0];
    }

    long long max_val = -1;
    for (long long x : a) {
        if (x > max_val) max_val = x;
    }

    cout << n << endl;
    log_metrics();

    while (true) {

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

        string type;
        if (!(cin >> type)) {
            finish(_wa, "Unexpected EOF from solution");
        }

        if (type == "!") {

            long long ans_x1, ans_d;
            if (!(cin >> ans_x1 >> ans_d)) {
                finish(_pe, "Invalid answer format");
            }

            if (ans_x1 == x1_secret && ans_d == d_secret) {
                finish(_ok, "Correct");
            } else {
                finish(_wa, format("Expected x1=%lld d=%lld, but found x1=%lld d=%lld",
                                   x1_secret, d_secret, ans_x1, ans_d));
            }
        } else if (type == "?") {

            queries++;

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

            int i;
            if (!(cin >> i)) finish(_pe, "Invalid index format");

            if (i < 1 || i > n) {
                cout << -1 << endl;
                finish(_wa, "Index out of range");
            }

            cout << a[i-1] << endl;
        } else if (type == ">") {

            queries++;

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

            long long x;
            if (!(cin >> x)) finish(_pe, "Invalid value format");

            if (x < 0 || x > 1000000000LL) {
                cout << -1 << endl;
                finish(_wa, "Value out of range");
            }

            cout << (max_val > x ? 1 : 0) << endl;
        } else {
            finish(_pe, "Unknown query type: " + type);
        }

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

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

using namespace std;

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

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

    int seed_val = atoi(argv[1]);

    long long n, x1, d;

    if (seed_val == 1) {

        n = 2;
        d = 1000000000;
        x1 = 0;

    } else if (seed_val == 2) {

        n = 1000000;
        d = 1;
        x1 = 0;

    } else if (seed_val == 3) {

        n = 1000000;

        d = 1000;

        x1 = 1000000000LL - (n - 1) * d;
    } else {

        int n_type = rnd.next(1, 10);
        if (n_type <= 3) {

            n = rnd.next(2, 100);
        } else if (n_type <= 6) {

            n = rnd.next(101, 50000);
        } else {

            n = rnd.next(50001, 1000000);
        }

        long long max_d = 1000000000LL / (n - 1);
        if (max_d < 1) max_d = 1;

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

            d = rnd.next(1LL, max_d);
        } else {

            d = rnd.next(1LL, min(max_d, 2000LL));
        }

        long long max_x1 = 1000000000LL - (n - 1) * d;
        int x1_type = rnd.next(1, 5);
        if (x1_type == 1) {
            x1 = 0;
        } else if (x1_type == 2) {
            x1 = max_x1;
        } else {
            x1 = rnd.next(0LL, max_x1);
        }
    }

    if (mode == "non") {

        cout << n << "\n";
        vector<long long> a(n);
        for (int i = 0; i < n; i++) {
            a[i] = x1 + (long long)i * d;
        }

        shuffle(a.begin(), a.end());
        println(a);
    } else {

        cout << n << " " << x1 << " " << d << "\n";
    }

    return 0;
}


D. Something with XOR Queries

This is an interactive problem.

Jury has hidden a permutation *p* of integers from 0 to *n* - 1. You know only the length *n*. Remind that in permutation all integers are distinct.

Let *b* be the inverse permutation for *p*, i.e. *p**b**i* = *i* for all *i*. The only thing you can do is to ask xor of elements *p**i* and *b**j*, printing two indices *i* and *j* (not necessarily distinct). As a result of the query with indices *i* and *j* you'll get the value![](https://espresso.codeforces.com/5dae53b8ed0e62c9af6c21130fc022b384e359ff.png), where![](https://espresso.codeforces.com/c4b7092c0f7ce6535f2574569c98f7b3c2fe2c5f.png) denotes the xor operation. You can find the description of xor operation in notes.

Note that some permutations can remain indistinguishable from the hidden one, even if you make all possible *n*2 queries. You have to compute the number of permutations indistinguishable from the hidden one, and print one of such permutations, making no more than 2*n* queries.

The hidden permutation does not depend on your queries.

Input

The first line contains single integer *n* (1 ≤ *n* ≤ 5000) — the length of the hidden permutation. You should read this integer first.

Output

When your program is ready to print the answer, print three lines.

In the first line print "!".

In the second line print single integer *answers*\_*cnt* — the number of permutations indistinguishable from the hidden one, including the hidden one.

In the third line print *n* integers *p*0, *p*1,..., *p**n* - 1 (0 ≤ *p**i* < *n*, all *p**i* should be distinct) — one of the permutations indistinguishable from the hidden one.

Your program should terminate after printing the answer.

Interaction

To ask about xor of two elements, print a string "? i j", where *i* and *j* — are integers from 0 to *n* - 1 — the index of the permutation element and the index of the inverse permutation element you want to know the xor-sum for. After that print a line break and make flush operation.

After printing the query your program should read single integer — the value of![](https://espresso.codeforces.com/5dae53b8ed0e62c9af6c21130fc022b384e359ff.png).

For a permutation of length *n* your program should make no more than 2*n* queries about xor-sum. Note that printing answer doesn't count as a query. Note that you can't ask more than 2*n* questions. If you ask more than 2*n* questions or at least one incorrect question, your solution will get "Wrong answer".

If at some moment your program reads -1 as an answer, it should immediately exit (for example, by calling exit(0)). You will get "Wrong answer" in this case, it means that you asked more than 2*n* questions, or asked an invalid question. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.

Your solution will get "Idleness Limit Exceeded", if you don't print anything or forget to flush the output, including for the final answer.

To flush you can use (just after printing line break):

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

Examples

Input

```
3
0
0
3
2
3
2
```

Output

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

Input

```
4
2
3
2
0
2
3
2
0
```

Output

```? 0 1? 1 2? 2 3? 3 3? 3 2? 2 1? 1 0? 0 0!
2
3 1 2 0
```

Note

xor operation, or bitwise exclusive OR, is an operation performed over two integers, in which the *i*-th digit in binary representation of the result is equal to 1 if and only if exactly one of the two integers has the *i*-th digit in binary representation equal to 1. For more information, see here.

In the first example *p* = [0, 1, 2], thus *b* = [0, 1, 2], the values![](https://espresso.codeforces.com/5dae53b8ed0e62c9af6c21130fc022b384e359ff.png) are correct for the given *i*, *j*. There are no other permutations that give the same answers for the given queries.

The answers for the queries are:

*![](https://espresso.codeforces.com/b36cf4ccf629eaa3a225cda06a5697eb030eb4d7.png),
*![](https://espresso.codeforces.com/88e848d2e69ecfb3b8c8d63fdc8949c7cc1e9f28.png),
*![](https://espresso.codeforces.com/233e40a031e99efe33bdf68f4a383163a23e1e7b.png),
*![](https://espresso.codeforces.com/3ec81fca9911a6bde9c2c7cae6c189514105085f.png),
*![](https://espresso.codeforces.com/be5d5595e56564765e3db6b865de2219cdadadeb.png),
*![](https://espresso.codeforces.com/3355af6093e240986c338bf13071b479e2604ca9.png).

In the second example *p* = [3, 1, 2, 0], and *b* = [3, 1, 2, 0], the values![](https://espresso.codeforces.com/5dae53b8ed0e62c9af6c21130fc022b384e359ff.png) match for all pairs *i*, *j*. But there is one more suitable permutation *p* = [0, 2, 1, 3], *b* = [0, 2, 1, 3] that matches all *n*2 possible queries as well. All other permutations do not match even the shown queries.

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

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

static int n;
static vector<int> p;
static vector<int> b;

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

bool is_valid_X(int X) {
    for (int k = 0; k < n; ++k) {

        int idx = b[k] ^ X;
        if (idx < 0 || idx >= n) return false;

        if ((p[idx] ^ X) != k) return false;
    }
    return true;
}

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

    n = inf.readInt();
    p.resize(n);
    b.resize(n);
    for (int i = 0; i < n; ++i) {
        p[i] = inf.readInt();

        if (p[i] < 0 || p[i] >= n) quitf(_fail, "Hidden permutation value out of range");
        b[p[i]] = i;
    }

    query_limit = 2LL * n;

    vector<int> valid_Xs;
    for (int X = 0; X < n; ++X) {
        if (is_valid_X(X)) {
            valid_Xs.push_back(X);
        }
    }
    int real_cnt = (int)valid_Xs.size();

    cout << n << endl;

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

    while (true) {
        string token;
        if (!(cin >> token)) {
            finish(_wa, "Unexpected end of output (expected query or answer)");
        }

        if (token == "!") {

            int user_cnt;
            if (!(cin >> user_cnt)) finish(_wa, "Expected integer count after '!'");

            vector<int> user_p(n);
            vector<bool> seen(n, false);
            for (int i = 0; i < n; ++i) {
                if (!(cin >> user_p[i])) finish(_wa, "Expected permutation element");
                if (user_p[i] < 0 || user_p[i] >= n) finish(_wa, "Permutation element out of bounds");
                if (seen[user_p[i]]) finish(_wa, "Duplicate element in permutation");
                seen[user_p[i]] = true;
            }

            if (user_cnt != real_cnt) {
                finish(_wa, format("Incorrect count: expected %d, got %d", real_cnt, user_cnt));
            }

            int X = user_p[0] ^ p[0];

            bool X_valid = false;
            for (int v : valid_Xs) {
                if (v == X) {
                    X_valid = true;
                    break;
                }
            }

            if (!X_valid) {
                finish(_wa, format("Permutation corresponds to invalid X=%d", X));
            }

            for (int i = 0; i < n; ++i) {
                if (user_p[i] != (p[i] ^ X)) {
                    finish(_wa, "Permutation inconsistent with derived X");
                }
            }

            finish(_ok, format("Correct! Count=%d, X=%d", real_cnt, X));
        }

        int i, j;
        if (token == "?") {
            if (!(cin >> i >> j)) finish(_wa, "Expected two integers after '?'");
        } else {

            try {
                size_t idx;
                i = stoi(token, &idx);
                if (idx != token.size()) finish(_wa, "Invalid query token (trailing chars)");
                if (!(cin >> j)) finish(_wa, "Expected second integer for query");
            } catch (...) {
                finish(_wa, "Invalid query format");
            }
        }

        queries++;

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

        if (i < 0 || i >= n || j < 0 || j >= n) {
            finish(_wa, format("Query indices out of bounds: %d %d", i, j));
        }

        int ans = p[i] ^ b[j];
        cout << ans << endl;

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

    return 0;
}

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

using namespace std;

static int n_val = 0;
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());
}

vector<int> p_hidden;
vector<int> b_hidden;

struct Query {
    int i, j, ans;
};
vector<Query> history_log;

long long count_solutions() {

    vector<vector<pair<int, int>>> adj_p(n_val);
    vector<vector<pair<int, int>>> adj_b(n_val);

    for (const auto& q : history_log) {
        adj_p[q.i].push_back({q.j, q.ans});
        adj_b[q.j].push_back({q.i, q.ans});
    }

    {
        int visited_nodes = 0;
        vector<bool> vis_p(n_val, false);
        vector<bool> vis_b(n_val, false);
        queue<pair<int, int>> q;

        q.push({0, 0});
        vis_p[0] = true;
        visited_nodes++;

        while(!q.empty()){
            auto [type, u] = q.front(); q.pop();
            if (type == 0) {
                for (auto& edge : adj_p[u]) {
                    int v = edge.first;
                    if (!vis_b[v]) {
                        vis_b[v] = true;
                        visited_nodes++;
                        q.push({1, v});
                    }
                }
            } else {
                for (auto& edge : adj_b[u]) {
                    int v = edge.first;
                    if (!vis_p[v]) {
                        vis_p[v] = true;
                        visited_nodes++;
                        q.push({0, v});
                    }
                }
            }
        }

        if (visited_nodes < 2 * n_val) {
             return -1;
        }
    }

    long long cnt = 0;
    vector<int> cur_p(n_val);
    vector<int> cur_b(n_val);
    vector<int> q_bfs; q_bfs.reserve(2 * n_val);
    static vector<bool> seen_vals;
    if ((int)seen_vals.size() != n_val) seen_vals.resize(n_val);

    for (int start_val = 0; start_val < n_val; start_val++) {
        fill(cur_p.begin(), cur_p.end(), -1);
        fill(cur_b.begin(), cur_b.end(), -1);

        bool possible = true;

        q_bfs.clear();
        cur_p[0] = start_val;
        q_bfs.push_back(0);

        int head = 0;
        while(head < (int)q_bfs.size()) {
            int u = q_bfs[head++];

            if (u < n_val) {
                int p_val = cur_p[u];
                for (auto& edge : adj_p[u]) {
                    int j = edge.first;
                    int target_val = p_val ^ edge.second;
                    if (cur_b[j] == -1) {
                        if (target_val < 0 || target_val >= n_val) { possible = false; break; }
                        cur_b[j] = target_val;
                        q_bfs.push_back(j + n_val);
                    } else {
                        if (cur_b[j] != target_val) { possible = false; break; }
                    }
                }
            } else {
                int j = u - n_val;
                int b_val = cur_b[j];
                for (auto& edge : adj_b[j]) {
                    int i = edge.first;
                    int target_val = b_val ^ edge.second;
                    if (cur_p[i] == -1) {
                        if (target_val < 0 || target_val >= n_val) { possible = false; break; }
                        cur_p[i] = target_val;
                        q_bfs.push_back(i);
                    } else {
                        if (cur_p[i] != target_val) { possible = false; break; }
                    }
                }
            }
            if (!possible) break;
        }

        if (possible) {

            fill(seen_vals.begin(), seen_vals.end(), false);
            bool distinct = true;
            for (int x : cur_p) {
                if (x < 0) { distinct = false; break; }
                if (seen_vals[x]) { distinct = false; break; }
                seen_vals[x] = true;
            }

            if (distinct) {

                bool inverse_ok = true;
                for (int j = 0; j < n_val; j++) {
                    if (cur_b[j] < 0 || cur_p[cur_b[j]] != j) { inverse_ok = false; break; }
                }
                if (inverse_ok) cnt++;
            }
        }
    }

    return cnt;
}

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

    atexit(log_metrics);

    n_val = inf.readInt();
    query_limit = 2LL * n_val;

    log_metrics();

    cout << n_val << endl;

    p_hidden.resize(n_val);
    bool has_fixed = false;

    if (!inf.seekEof()) {
        try {
             for(int i=0; i<n_val; ++i) {
                 p_hidden[i] = inf.readInt();
             }
             has_fixed = true;
        } catch (...) {
             has_fixed = false;
        }
    }

    if (!has_fixed) {

        mt19937 rng(n_val * 1337 + 42);
        iota(p_hidden.begin(), p_hidden.end(), 0);
        shuffle(p_hidden.begin(), p_hidden.end(), rng);
    }

    b_hidden.resize(n_val);
    for(int i=0; i<n_val; ++i) b_hidden[p_hidden[i]] = i;

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

            long long user_cnt;
            if (!(cin >> user_cnt)) finish(_pe, "Expected answer count after '!'");

            vector<int> user_p(n_val);
            vector<bool> seen(n_val, false);
            for (int i=0; i<n_val; ++i) {
                if (!(cin >> user_p[i])) finish(_pe, "Expected permutation");
                if (user_p[i] < 0 || user_p[i] >= n_val) finish(_wa, "Permutation element out of range");
                if (seen[user_p[i]]) finish(_wa, "Permutation elements not distinct");
                seen[user_p[i]] = true;
            }

            vector<int> user_b(n_val);
            for(int i=0; i<n_val; ++i) user_b[user_p[i]] = i;

            for (const auto& q : history_log) {
                if ((user_p[q.i] ^ user_b[q.j]) != q.ans) {
                    finish(_wa, "Output permutation not consistent with query history");
                }
            }

            long long real_cnt = count_solutions();

            if (real_cnt == -1) {

                if (user_cnt < 1) finish(_wa, "Count must be at least 1 (solution exists)");
                finish(_ok, "Correct (Soft verify: Graph disconnected)");
            } else {
                if (user_cnt != real_cnt) {
                    finish(_wa, "Incorrect number of indistinguishable permutations. Expected " + to_string(real_cnt) + ", found " + to_string(user_cnt));
                }
                finish(_ok, "Correct");
            }

            break;
        } else if (token == "?") {

            queries++;

            if (queries > max(200000LL, 10 * query_limit)) {
                finish(_pe, "Too many queries (hard cap)");
            }

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

            if (i < 0 || i >= n_val || j < 0 || j >= n_val) {
                cout << -1 << endl;
                finish(_wa, "Invalid query indices");
            }

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

            int ans = p_hidden[i] ^ b_hidden[j];
            history_log.push_back({i, j, ans});

            cout << ans << endl;

            if (queries % 100 == 0) log_metrics();
        } else {
            finish(_pe, "Unexpected token " + token);
        }
    }

    finish(_pe, "Unexpected EOF");

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

    int n;
    vector<int> p;

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

    bool manual = (n_arg == 0 && seed >= 1 && seed <= 5);

    if (n_arg > 0) {
        n = n_arg;
        p.resize(n);
        iota(p.begin(), p.end(), 0);
        shuffle(p.begin(), p.end());
    } else if (manual) {
        if (seed == 1) {

            n = 3;
            p = {0, 1, 2};
        } else if (seed == 2) {

            n = 4;
            p = {3, 1, 2, 0};
        } else if (seed == 3) {

            n = 4;
            p = {0, 1, 2, 3};
        } else if (seed == 4) {

            n = 5000;
            p.resize(n);
            iota(p.begin(), p.end(), 0);
            shuffle(p.begin(), p.end());
        } else if (seed == 5) {

            n = 5000;
            p.resize(n);
            iota(p.begin(), p.end(), 0);
        }
    } else {

        n = rnd.next(1, 5000);
        p.resize(n);
        iota(p.begin(), p.end(), 0);

        if (rnd.next(100) >= 10) {
            shuffle(p.begin(), p.end());
        }
    }

    if (mode == "adp") {

        cout << n << endl;
    } else {

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

    return 0;
}


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

This is an interactive problem.

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

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

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

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

Interaction

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

To make a query, you should output

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

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

To give the answer, you should output

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

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

After printing a query or the answer, do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

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

Example

Input

```
5

2

2

1

3
```

Output

```
? 1 3 4

? 3 5 3

? 3 4 5

? 3 5 2

! 4
```

Note

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

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

In this interaction process:

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

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

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

using namespace std;

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

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(3, 1024, "n");

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

    {
        vector<int> temp;
        temp.reserve(n);
        for(int i = 1; i <= n; i++) temp.push_back(p[i]);
        sort(temp.begin(), temp.end());
        for(int i = 0; i < n; i++) {
            if (temp[i] != i + 1) {
                quitf(_fail, "Input array is not a permutation of 1..n");
            }
        }
    }

    log_metrics();

    cout << n << endl;

    long long hard_cap = 2000;

    while (true) {
        string token;

        if (!(cin >> token)) {
            finish(_wa, "Unexpected end of stream (expected '?' or '!')");
        }

        if (token == "!") {

            int y;
            if (!(cin >> y)) {
                finish(_wa, "Expected integer index after '!'");
            }

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

            if (p[y] == 1) {
                finish(_ok, format("Correct! p[%d] = 1. Queries used: %lld", y, queries));
            } else {
                finish(_wa, format("Wrong answer. p[%d] = %d, expected 1", y, p[y]));
            }

        } else {

            int l, r, k;

            if (token == "?") {
                if (!(cin >> l >> r >> k)) {
                    finish(_wa, "Expected 3 integers (l r k) after '?'");
                }
            } else {

                try {
                    l = stoi(token);
                } catch (...) {
                    finish(_wa, format("Expected '?' or integer, found '%s'", token.c_str()));
                }
                if (!(cin >> r >> k)) {
                    finish(_wa, "Expected r and k");
                }
            }

            if (l < 1 || l > r || r > n) {
                finish(_wa, format("Invalid query range: l=%d, r=%d (n=%d)", l, r, n));
            }
            if (k < 1 || k > n) {
                finish(_wa, format("Invalid k: %d (n=%d)", k, n));
            }

            queries++;

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

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

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

            sort(values.begin(), values.end());
            int ans = (int)(unique(values.begin(), values.end()) - values.begin());

            cout << ans << endl;
        }
    }

    return 0;
}

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

using namespace std;

static long long queries = 0;
static long long query_limit = 20;
static int n;
static vector<int> p;

static void log_metrics() {
    try {

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

    }
}

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

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

    static vector<int> vals;
    vals.clear();
    vals.reserve(r - l + 1);

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

    if (vals.empty()) return 0;
    sort(vals.begin(), vals.end());

    int cnt = 1;
    for (size_t i = 1; i < vals.size(); ++i) {
        if (vals[i] != vals[i - 1]) {
            cnt++;
        }
    }
    return cnt;
}

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

    registerInteraction(argc, argv);

    atexit(log_metrics);

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

    if (inf.seekEof()) {
        p.resize(n);
        iota(p.begin(), p.end(), 1);

        ::shuffle(p.begin(), p.end());
    } else {
        p.resize(n);
        for (int i = 0; i < n; ++i) {
            p[i] = inf.readInt(1, n, format("p[%d]", i + 1));
        }

    }

    cout << n << endl;

    query_limit = 20;
    log_metrics();

    int hard_cap = 200;

    while (true) {

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

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

        if (type == "!") {
            int y;
            if (!(cin >> y)) {
                finish(_pe, "Expected integer after '!'");
            }

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

            if (p[y - 1] == 1) {
                finish(_ok, format("Correct! Found 1 at index %d in %lld queries", y, queries));
            } else {
                int correct = -1;
                for (int i = 0; i < n; ++i) {
                    if (p[i] == 1) correct = i + 1;
                }
                finish(_wa, format("Wrong answer. Guess %d, but p[%d]=%d. Correct index is %d.", y, y, p[y - 1], correct));
            }
        } else if (type == "?") {
            int l, r, k;
            if (!(cin >> l >> r >> k)) {
                finish(_pe, "Invalid query format");
            }

            if (l < 1 || l > n || r < 1 || r > n || l > r) {
                finish(_pe, format("Invalid range l=%d, r=%d (n=%d)", l, r, n));
            }
            if (k < 1 || k > n) {
                finish(_pe, format("Invalid k=%d (n=%d)", k, n));
            }

            queries++;

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

            int ans = solve_query(l - 1, r - 1, k);
            cout << ans << endl;
        } else {
            finish(_pe, format("Unknown token '%s', expected '?' or '!'", type.c_str()));
        }
    }

    return 0;
}

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

using namespace std;

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

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

    long long seedVal = 0;
    if (argc > 1) {
        string s = argv[1];
        if (!s.empty() && all_of(s.begin(), s.end(), ::isdigit)) {
            seedVal = atoll(s.c_str());
        }
    }

    if (n == 0) {
        if (seedVal == 1) n = 3;
        else if (seedVal >= 2 && seedVal <= 7) n = 1024;
        else if (seedVal == 8) n = 1023;
        else {

            if (rnd.next(3) == 0) n = rnd.next(3, 1024);
            else n = 1024;
        }
    }

    cout << n << endl;

    if (mode == "adp") {
        return 0;
    }

    vector<int> p(n);
    iota(p.begin(), p.end(), 1);

    if (seedVal == 6) {
        reverse(p.begin(), p.end());
    } else if (seedVal == 7) {

    } else {
        shuffle(p.begin(), p.end());

        if (seedVal == 3) {

            iter_swap(p.begin(), find(p.begin(), p.end(), 1));
        } else if (seedVal == 4) {

            iter_swap(p.end() - 1, find(p.begin(), p.end(), 1));
        } else if (seedVal == 5) {

            iter_swap(p.begin() + n / 2, find(p.begin(), p.end(), 1));
        }
    }

    println(p);

    return 0;
}


Don't you tell me what you think that I can be

If you say that Arkady is a bit old-fashioned playing checkers, you won't be right. There is also a modern computer game Arkady and his friends are keen on. We won't discuss its rules, the only feature important to this problem is that each player has to pick a distinct hero in the beginning of the game.

There are $2$ teams each having $n$ players and $2n$ heroes to distribute between the teams. The teams take turns picking heroes: at first, the first team chooses a hero in its team, after that the second team chooses a hero and so on. Note that after a hero is chosen it becomes unavailable to both teams.

The friends estimate the power of the $i$-th of the heroes as $p_i$. Each team wants to maximize the total power of its heroes. However, there is one exception: there are $m$ pairs of heroes that are especially strong against each other, so when any team chooses a hero from such a pair, the other team must choose the other one on its turn. Each hero is in at most one such pair.

This is an interactive problem. You are to write a program that will optimally choose the heroes for one team, while the jury's program will play for the other team. Note that the jury's program may behave inefficiently, in this case you have to take the opportunity and still maximize the total power of your team. Formally, if you ever have chance to reach the total power of $q$ or greater regardless of jury's program choices, you must get $q$ or greater to pass a test.

Input

The first line contains two integers $n$ and $m$ ($1 \le n \le 10^3$, $0 \le m \le n$) — the number of players in one team and the number of special pairs of heroes.

The second line contains $2n$ integers $p_1, p_2, \ldots, p_{2n}$ ($1 \le p_i \le 10^3$) — the powers of the heroes.

Each of the next $m$ lines contains two integer $a$ and $b$ ($1 \le a, b \le 2n$, $a \ne b$) — a pair of heroes that are especially strong against each other. It is guaranteed that each hero appears at most once in this list.

The next line contains a single integer $t$ ($1 \le t \le 2$) — the team you are to play for. If $t = 1$, the first turn is yours, otherwise you have the second turn.

Interaction

When it is your turn, print a single integer $x$ ($1 \le x \le 2n$) — the index of the hero chosen by you. Note that you can't choose a hero previously chosen by either you of the other player, and you must follow the rules about special pairs of heroes.

When it is the other team's turn, read a line containing a single integer $x$ ($1 \le x \le 2n$) — the index of the hero chosen by the other team. It is guaranteed that this index is not chosen before and that the other team also follows the rules about special pairs of heroes.

After the last turn you should terminate without printing anything.

After printing your choice do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:

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

Jury's answer $-1$ instead of a valid choice means that you made an invalid turn. Exit immediately after receiving $-1$ and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.

Examples

Input

```
3 1
1 2 3 4 5 6
2 6
1

2

4

1
```

Output

```
6

5

3
```

Input

```
3 1
1 2 3 4 5 6
1 5
2
6

1

3
```

Output

```
5

4

2
```

Note

In the first example the first turn is yours. In example, you choose $6$, the other team is forced to reply with $2$. You choose $5$, the other team chooses $4$. Finally, you choose $3$ and the other team choose $1$.

In the second example you have the second turn. The other team chooses $6$, you choose $5$, forcing the other team to choose $1$. Now you choose $4$, the other team chooses $3$ and you choose $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 parseIntToken(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) {
        if (s[i] < '0' || s[i] > '9') 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;
}

struct PairEntry {
    int powerHi;
    int hi;
    int lo;
    bool operator<(const PairEntry& other) const {
        if (powerHi != other.powerHi) return powerHi < other.powerHi;
        if (hi != other.hi) return hi < other.hi;
        return lo < other.lo;
    }
};

struct SingleEntry {
    int power;
    int idx;
    bool operator<(const SingleEntry& other) const {
        if (power != other.power) return power < other.power;
        return idx < other.idx;
    }
};

struct Heaps {
    priority_queue<PairEntry> pairs;
    priority_queue<SingleEntry> singles;
};

static Heaps buildHeaps(int n2,
                        const vector<int>& p,
                        const vector<int>& mate,
                        const vector<pair<int,int>>& pairList) {
    Heaps h;
    for (auto [a, b] : pairList) {
        int hi = (p[a] >= p[b]) ? a : b;
        int lo = (hi == a) ? b : a;
        h.pairs.push(PairEntry{p[hi], hi, lo});
    }
    for (int i = 1; i <= n2; ++i) {
        if (mate[i] == 0) h.singles.push(SingleEntry{p[i], i});
    }
    return h;
}

static int cleanPeekBestSingle(priority_queue<SingleEntry>& pq, const vector<char>& used) {
    while (!pq.empty() && used[pq.top().idx]) pq.pop();
    return pq.empty() ? 0 : pq.top().idx;
}

static int cleanPeekBestPairHi(priority_queue<PairEntry>& pq, const vector<char>& used) {
    while (!pq.empty() && (used[pq.top().hi] || used[pq.top().lo])) pq.pop();
    return pq.empty() ? 0 : pq.top().hi;
}

static int selectSingle(priority_queue<SingleEntry>& pq, const vector<char>& used) {
    while (!pq.empty() && used[pq.top().idx]) pq.pop();
    if (pq.empty()) return 0;
    int idx = pq.top().idx;
    pq.pop();
    return idx;
}

static PairEntry selectPair(priority_queue<PairEntry>& pq, const vector<char>& used) {
    while (!pq.empty() && (used[pq.top().hi] || used[pq.top().lo])) pq.pop();
    if (pq.empty()) return PairEntry{-1, -1, -1};
    PairEntry e = pq.top();
    pq.pop();
    return e;
}

static int selectFreeMoveGreedy(Heaps& h, const vector<int>& p, const vector<char>& used) {
    int bestSingle = cleanPeekBestSingle(h.singles, used);
    int bestPairHi = cleanPeekBestPairHi(h.pairs, used);

    int bestSinglePower = bestSingle ? p[bestSingle] : -1;
    int bestPairPower = bestPairHi ? p[bestPairHi] : -1;

    if (bestPairHi && (bestPairPower > bestSinglePower || !bestSingle)) {
        PairEntry e = selectPair(h.pairs, used);
        if (e.hi <= 0) return 0;
        return e.hi;
    } else {
        return selectSingle(h.singles, used);
    }
}

static long long simulateValue(int n,
                              int tContestant,
                              const vector<int>& p,
                              const vector<int>& mate,
                              const vector<pair<int,int>>& pairList) {
    int n2 = 2 * n;
    vector<char> used(n2 + 1, 0);
    Heaps h = buildHeaps(n2, p, mate, pairList);

    long long sum1 = 0, sum2 = 0;
    int forced[3] = {0, 0, 0};
    int curTeam = 1;

    for (int turn = 0; turn < 2 * n; ++turn) {
        int pick = 0;
        if (forced[curTeam]) {
            pick = forced[curTeam];
            forced[curTeam] = 0;
        } else {
            pick = selectFreeMoveGreedy(h, p, used);
        }
        if (pick <= 0 || pick > n2 || used[pick]) break;

        used[pick] = 1;
        if (curTeam == 1) sum1 += p[pick];
        else sum2 += p[pick];

        int partner = mate[pick];
        if (partner && !used[partner]) forced[3 - curTeam] = partner;

        curTeam = 3 - curTeam;
    }
    return (tContestant == 1) ? sum1 : sum2;
}

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

    int n = inf.readInt(1, 1000, "n");
    int m = inf.readInt(0, n, "m");
    int n2 = 2 * n;

    vector<int> p(n2 + 1, 0);
    for (int i = 1; i <= n2; ++i) p[i] = inf.readInt(1, 1000, ("p[" + to_string(i) + "]").c_str());

    vector<int> mate(n2 + 1, 0);
    vector<pair<int,int>> pairs;
    pairs.reserve(m);
    vector<char> seen(n2 + 1, 0);
    for (int i = 0; i < m; ++i) {
        int a = inf.readInt(1, n2, "a");
        int b = inf.readInt(1, n2, "b");
        if (a == b) finish(_pe, "invalid hidden input: a==b");
        if (seen[a] || seen[b]) finish(_pe, "invalid hidden input: hero appears in more than one pair");
        seen[a] = seen[b] = 1;
        mate[a] = b;
        mate[b] = a;
        pairs.push_back({a, b});
    }

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

    query_limit = n;
    log_metrics();

    const long long required_min = simulateValue(n, t, p, mate, pairs);

    cout << n << " " << m << "\n";
    for (int i = 1; i <= n2; ++i) {
        cout << p[i] << (i == n2 ? '\n' : ' ');
    }
    for (auto [a, b] : pairs) cout << a << " " << b << "\n";
    cout << t << "\n";
    cout.flush();

    vector<char> used(n2 + 1, 0);
    Heaps heaps = buildHeaps(n2, p, mate, pairs);

    int forcedForContestant = 0;
    int forcedForInteractor = 0;

    long long sumContestant = 0, sumInteractor = 0;

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

    auto applyPick = [&](int who, int x) {
        used[x] = 1;
        if (who == t) sumContestant += p[x];
        else sumInteractor += p[x];
    };

    auto onPickSetsForced = [&](int who, int x) {
        int partner = mate[x];
        if (partner && !used[partner]) {
            if (who == t) {
                if (forcedForInteractor != 0) finish(_wa, "internal state: forcedForInteractor already set");
                forcedForInteractor = partner;
            } else {
                if (forcedForContestant != 0) finish(_wa, "internal state: forcedForContestant already set");
                forcedForContestant = partner;
            }
        }
    };

    int curTeam = 1;
    for (int turn = 0; turn < 2 * n; ++turn) {
        if (curTeam == t) {
            if (queries >= hard_cap) finish(_pe, "hard cap exceeded (too many contestant moves)");
            string tok;
            if (!(cin >> tok)) finish(_pe, "contestant output ended early");
            long long xll = 0;
            if (!parseIntToken(tok, xll)) finish(_pe, "non-integer contestant token");
            if (xll == -1) finish(_wa, "contestant output -1");
            if (xll < 1 || xll > n2) {
                cout << -1 << "\n";
                cout.flush();
                finish(_wa, "contestant chose out-of-range hero");
            }
            int x = (int)xll;

            ++queries;
            log_metrics();

            if (used[x]) {
                cout << -1 << "\n";
                cout.flush();
                finish(_wa, "contestant chose an already used hero");
            }
            if (forcedForContestant != 0 && x != forcedForContestant) {
                cout << -1 << "\n";
                cout.flush();
                finish(_wa, "contestant violated forced pair rule");
            }
            forcedForContestant = 0;

            applyPick(t, x);
            onPickSetsForced(t, x);
        } else {
            int x = 0;
            if (forcedForInteractor != 0) {
                x = forcedForInteractor;
                forcedForInteractor = 0;
                if (x < 1 || x > n2 || used[x]) finish(_wa, "interactor forced move invalid (internal error)");
            } else {
                x = selectFreeMoveGreedy(heaps, p, used);
                if (x == 0) finish(_wa, "interactor has no valid move (internal error)");
                if (used[x]) finish(_wa, "interactor selected used hero (internal error)");
            }

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

            applyPick(3 - t, x);
            onPickSetsForced(3 - t, x);
        }

        curTeam = 3 - curTeam;
    }

    if (sumContestant + sumInteractor != accumulate(p.begin(), p.end(), 0LL)) {

    }

    if (sumContestant >= required_min) {
        finish(_ok, "ok");
    } else {
        finish(_wa, "suboptimal total power");
    }
}

#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 readLongLongToken(long long& out) {
    string s;
    if (!(cin >> s)) return false;
    if (s.empty()) return false;
    int i = 0;
    bool neg = false;
    if (s[0] == '-') {
        neg = true;
        i = 1;
        if ((int)s.size() == 1) return false;
    }
    for (; i < (int)s.size(); ++i) {
        if (s[i] < '0' || s[i] > '9') return false;
    }
    try {
        out = stoll(s);
    } catch (...) {
        return false;
    }
    return true;
}

struct PairNode {
    int sum = 0;
    int hiVal = 0, loVal = 0;
    int hiIdx = 0, loIdx = 0;
    int id = -1;

    bool operator<(const PairNode& other) const {
        if (sum != other.sum) return sum < other.sum;
        if (hiVal != other.hiVal) return hiVal < other.hiVal;
        if (loVal != other.loVal) return loVal > other.loVal;
        if (hiIdx != other.hiIdx) return hiIdx > other.hiIdx;
        return id > other.id;
    }
};

struct SingleCmp {
    bool operator()(const pair<int,int>& a, const pair<int,int>& b) const {
        if (a.first != b.first) return a.first > b.first;
        return a.second < b.second;
    }
};

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

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

    int n = 0, m = 0, t = 0;
    vector<int> p;
    vector<int> partner;
    vector<int> pairId;
    vector<pair<int,int>> pairs;
    vector<bool> alivePair;
    vector<bool> used;

    multiset<pair<int,int>, SingleCmp> singles;
    priority_queue<PairNode> pq;

    auto bad_input = [&](const string& msg) {
        finish(_pe, "bad hidden input: " + msg);
    };

    try {
        n = inf.readInt(1, 1000, "n");
        m = inf.readInt(0, n, "m");
        p.assign(2 * n + 1, 0);
        for (int i = 1; i <= 2 * n; ++i) p[i] = inf.readInt(1, 1000, "p_i");

        partner.assign(2 * n + 1, 0);
        pairId.assign(2 * n + 1, -1);
        pairs.reserve(m);

        for (int i = 0; i < m; ++i) {
            int a = inf.readInt(1, 2 * n, "a");
            int b = inf.readInt(1, 2 * n, "b");
            if (a == b) bad_input("pair endpoints equal");
            if (partner[a] != 0 || partner[b] != 0) bad_input("hero appears in multiple pairs");
            partner[a] = b;
            partner[b] = a;
            pairId[a] = i;
            pairId[b] = i;
            pairs.push_back({a, b});
        }

        t = inf.readInt(1, 2, "t");
    } catch (...) {
        bad_input("exception while reading");
    }

    cout << n << " " << m << "\n";
    for (int i = 1; i <= 2 * n; ++i) {
        cout << p[i] << (i == 2 * n ? '\n' : ' ');
    }
    for (auto [a, b] : pairs) {
        cout << a << " " << b << "\n";
    }
    cout << t << "\n";
    cout.flush();

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

    used.assign(2 * n + 1, false);
    alivePair.assign(m, true);

    for (int i = 1; i <= 2 * n; ++i) {
        if (partner[i] == 0) singles.insert({p[i], i});
    }
    for (int i = 0; i < m; ++i) {
        int a = pairs[i].first;
        int b = pairs[i].second;
        int hiIdx = a, loIdx = b;
        int hiVal = p[a], loVal = p[b];
        if (hiVal < loVal || (hiVal == loVal && hiIdx > loIdx)) {
            swap(hiIdx, loIdx);
            swap(hiVal, loVal);
        }
        PairNode node;
        node.sum = hiVal + loVal;
        node.hiVal = hiVal;
        node.loVal = loVal;
        node.hiIdx = hiIdx;
        node.loIdx = loIdx;
        node.id = i;
        pq.push(node);
    }

    auto consume_pick = [&](int idx) {
        used[idx] = true;
        if (partner[idx] == 0) {
            auto it = singles.find({p[idx], idx});
            if (it != singles.end()) singles.erase(it);
        } else {
            int id = pairId[idx];
            if (id >= 0 && id < m && alivePair[id]) alivePair[id] = false;
        }
    };

    auto pick_free = [&]() -> int {
        while (!pq.empty()) {
            const auto& top = pq.top();
            if (top.id < 0 || top.id >= m) { pq.pop(); continue; }
            if (!alivePair[top.id]) { pq.pop(); continue; }
            if (used[top.hiIdx] || used[top.loIdx]) { pq.pop(); continue; }
            break;
        }

        bool hasPair = !pq.empty();
        bool hasSingle = !singles.empty();
        if (!hasPair && !hasSingle) return 0;

        if (hasPair) {
            const auto& top = pq.top();
            int bestSingle = hasSingle ? singles.begin()->first : -1;
            if (!hasSingle || top.sum > bestSingle) {
                return top.hiIdx;
            }
        }
        return singles.begin()->second;
    };

    int contestantTeam = t;
    int judgeTeam = 3 - t;
    long long score[3] = {0, 0, 0};
    int forcedFor[3] = {0, 0, 0};

    for (int turn = 1; turn <= 2 * n; ++turn) {
        int teamToMove = (turn % 2 == 1) ? 1 : 2;

        if (teamToMove == contestantTeam) {
            long long xll = 0;
            if (!readLongLongToken(xll)) finish(_pe, "unexpected EOF / non-integer from contestant");
            ++queries;
            if (queries > hard_cap) finish(_pe, "too many moves from contestant");

            if (xll == -1) finish(_wa, "contestant printed -1");
            if (xll < 1 || xll > 2LL * n) finish(_wa, "hero index out of range");

            int x = (int)xll;
            if (used[x]) finish(_wa, "hero already chosen");
            if (forcedFor[teamToMove] != 0 && x != forcedFor[teamToMove]) finish(_wa, "did not follow forced pair rule");

            forcedFor[teamToMove] = 0;
            consume_pick(x);
            score[teamToMove] += p[x];

            int y = partner[x];
            if (y != 0 && !used[y]) forcedFor[3 - teamToMove] = y;
            else forcedFor[3 - teamToMove] = 0;
        } else {
            int move = 0;
            if (forcedFor[teamToMove] != 0) {
                move = forcedFor[teamToMove];
                if (move < 1 || move > 2 * n || used[move]) finish(_pe, "internal forced move invalid");
            } else {
                move = pick_free();
                if (move == 0) finish(_pe, "internal: no legal move available");
                if (used[move]) finish(_pe, "internal: selected already used move");
            }

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

            forcedFor[teamToMove] = 0;
            consume_pick(move);
            score[teamToMove] += p[move];

            int y = partner[move];
            if (y != 0 && !used[y]) forcedFor[3 - teamToMove] = y;
            else forcedFor[3 - teamToMove] = 0;
        }
    }

    finish(_ok, ("finished: contestant=" + to_string(score[contestantTeam]) + " judge=" + to_string(score[judgeTeam])).c_str());
}

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

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

struct GenCase {
    int n = 0, m = 0, t = 1;
    vector<int> p;
    vector<pair<int,int>> pairs;
};

static GenCase makeCorner1() {
    GenCase c;
    c.n = 1;
    c.m = 0;
    c.t = 1;
    c.p.assign(2 * c.n + 1, 0);
    c.p[1] = 1;
    c.p[2] = 1000;
    return c;
}

static GenCase makeCorner2() {
    GenCase c;
    c.n = 1;
    c.m = 1;
    c.t = 2;
    c.p.assign(2 * c.n + 1, 0);
    c.p[1] = 1000;
    c.p[2] = 1;
    c.pairs.push_back({1, 2});
    return c;
}

static GenCase makeCorner3() {
    GenCase c;
    c.n = 3;
    c.m = 2;
    c.t = 2;
    c.p.assign(2 * c.n + 1, 0);

    c.p[1] = 1000; c.p[2] = 1;
    c.p[3] = 900;  c.p[4] = 800;
    c.p[5] = 999;
    c.p[6] = 2;
    c.pairs.push_back({1, 2});
    c.pairs.push_back({3, 4});
    return c;
}

static GenCase makeRandomCase(long long seedVal, int nDefault, int mOpt, int maxP, int tOpt) {
    GenCase c;
    c.n = nDefault;
    int n = c.n;

    int m;
    if (mOpt >= 0) {
        m = min(mOpt, n);
    } else {

        int dec = rnd.next(0, max(1, n / 25));
        m = n - dec;
        if (rnd.next(0, 9) == 0) m = n;
    }
    c.m = m;

    if (tOpt == 1 || tOpt == 2) c.t = tOpt;
    else c.t = rnd.next(1, 2);

    c.p.assign(2 * n + 1, 0);

    vector<int> all(2 * n);
    for (int i = 0; i < 2 * n; ++i) all[i] = i + 1;
    rndShuffle(all);

    vector<int> pairedIdx;
    pairedIdx.reserve(2 * m);
    for (int i = 0; i < 2 * m; ++i) pairedIdx.push_back(all[i]);

    vector<int> singleIdx;
    for (int i = 2 * m; i < 2 * n; ++i) singleIdx.push_back(all[i]);

    int phase = (int)(seedVal % 11);
    for (int i = 0; i < m; ++i) {
        int a = pairedIdx[2 * i];
        int b = pairedIdx[2 * i + 1];

        int type = (i + phase) % 6;
        int x = 1, y = 1;

        if (type == 0) {
            x = maxP;
            y = rnd.next(1, max(1, maxP / 100));
        } else if (type == 1) {
            x = maxP - rnd.next(0, 3);
            y = maxP - rnd.next(8, 25);
        } else if (type == 2) {
            x = rnd.next(maxP * 2 / 3, maxP);
            y = rnd.next(1, maxP / 3);
        } else if (type == 3) {
            int base = rnd.next(maxP / 2, maxP * 3 / 4);
            x = base;
            y = base + rnd.next(-3, 3);
            y = max(1, min(maxP, y));
        } else if (type == 4) {
            x = rnd.next(maxP / 3, maxP * 2 / 3);
            y = rnd.next(maxP / 3, maxP * 2 / 3);
        } else {
            x = rnd.next(1, max(1, maxP / 4));
            y = rnd.next(1, max(1, maxP / 4));
        }

        if (rnd.next(0, 1) == 1) swap(x, y);

        c.p[a] = x;
        c.p[b] = y;
        c.pairs.push_back({a, b});
    }

    rndShuffle(singleIdx);
    int k = (int)singleIdx.size();
    int topBait = min(12, k);
    for (int i = 0; i < k; ++i) {
        int idx = singleIdx[i];
        if (i < topBait) {
            c.p[idx] = maxP - rnd.next(0, 2);
        } else if (i < min(k, 80)) {
            c.p[idx] = rnd.next(max(1, maxP / 2), maxP);
        } else {
            c.p[idx] = rnd.next(1, maxP);
        }
    }

    for (int i = 1; i <= 2 * n; ++i) {
        if (c.p[i] == 0) c.p[i] = rnd.next(1, maxP);
    }

    for (int i = (int)c.pairs.size() - 1; i > 0; --i) {
        int j = rnd.next(0, i);
        swap(c.pairs[i], c.pairs[j]);
    }

    return c;
}

static void outputNon(const GenCase& c) {
    cout << c.n << " " << c.m << "\n";
    for (int i = 1; i <= 2 * c.n; ++i) {
        cout << c.p[i] << (i == 2 * c.n ? '\n' : ' ');
    }
    for (auto [a, b] : c.pairs) {
        cout << a << " " << b << "\n";
    }
    cout << c.t << "\n";
}

static void outputAdp(const GenCase& c) {

    cout << c.n << " " << c.m << "\n";
    for (int i = 1; i <= 2 * c.n; ++i) {
        cout << c.p[i] << (i == 2 * c.n ? '\n' : ' ');
    }
    for (auto [a, b] : c.pairs) {
        cout << a << " " << b << "\n";
    }
    cout << c.t << "\n";
}

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

    string mode = opt<string>("mode", "non");
    int nDefault = opt<int>("n", 1000);
    int mOpt = opt<int>("m", -1);
    int maxP = opt<int>("maxP", 1000);
    int tOpt = opt<int>("t", 0);

    nDefault = max(1, min(1000, nDefault));
    maxP = max(1, min(1000, maxP));

    long long seedVal = atoll(argv[1]);

    GenCase c;
    if (seedVal == 1) c = makeCorner1();
    else if (seedVal == 2) c = makeCorner2();
    else if (seedVal == 3) c = makeCorner3();
    else c = makeRandomCase(seedVal, nDefault, mOpt, maxP, tOpt);

    if (mode == "non") {
        outputNon(c);
    } else if (mode == "adp") {
        outputAdp(c);
    } else {
        ensuref(false, "Unknown --mode, expected 'non' or 'adp'");
    }
    return 0;
}