Problem: cf1520_f1
Difficulty: easy
Categories: search
Time limit: 1000 ms, memory limit: 256 MB

This is an interactive problem.

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

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

Polycarp can make no more than $20$ requests of the following type:

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

In this (easy version) of the problem, this paragraph doesn't really make sense since $t=1$ always. To make the game more interesting, each guessed zero turns into one and the game continues on the changed array. More formally, if the position of the $k$-th zero was $x$, then after Polycarp guesses this position, the $x$-th element of the array will be replaced from $0$ to $1$. Of course, this feature affects something only for $t>1$.

Help Polycarp win the game.

Interaction

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

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

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

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

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

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

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

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

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

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

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

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

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

Example

Input

```
6 1
2

2

1

1

0

0
```

Output

```
? 4 6

? 1 1

? 1 2

? 2 2

? 5 5

! 5
```

Note

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

Non-adaptive interactor (C++):
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


Adaptive interactor (C++):

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

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

static NonCase makeNonCaseCorner(int seed) {
    NonCase cs;
    cs.t = 1;
    if (seed == 1) {
        cs.n = 1;
        cs.a = {0};
        cs.k = 1;
        return cs;
    }
    if (seed == 2) {
        cs.n = 200000;
        cs.a.assign(cs.n, 1);
        cs.a.back() = 0; 
        cs.k = 1;
        return cs;
    }
    
    cs.n = 200000;
    cs.a.resize(cs.n);
    
    for (int i = 0; i < cs.n; i++) cs.a[i] = (i % 2 == 0 ? 0 : 1);
    cs.k = cs.n / 2; 
    return cs;
}

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

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

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

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

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

    
    int middleBlocks = B - 2;
    int minMiddleSum = middleBlocks; 
    if (firstLen + lastLen + minMiddleSum > n) {
        
        int maxLastAllowed = n - firstLen - minMiddleSum;
        if (maxLastAllowed < 1) {
            
            firstLen = max(1, n - minMiddleSum - 1);
            maxLastAllowed = n - firstLen - minMiddleSum;
        }
        lastLen = max(1, maxLastAllowed);
    }
    int remaining = n - firstLen - lastLen;
    if (remaining < minMiddleSum) {
        
        firstLen = max(1, n / 2);
        lastLen = max(1, (n - firstLen) / 2);
        remaining = n - firstLen - lastLen;
        middleBlocks = max(1, n - firstLen - lastLen);
        B = middleBlocks + 2;
    }

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

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

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

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

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

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

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

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

static pair<int,int> makeAdpCaseRandom(int nOpt, int kOpt) {
    int n = nOpt;
    n = max(1, min(n, 200000));
    int k;
    if (kOpt > 0) {
        k = max(1, min(kOpt, n));
    } else {
        
        int coin = rnd.next(1, 100);
        if (coin <= 60) k = rnd.next(max(1, n - 5000), n);
        else if (coin <= 90) k = rnd.next(max(1, n / 2 - 5000), min(n, n / 2 + 5000));
        else k = rnd.next(1, n);
    }
    return {n, k};
}

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

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

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

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

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