Problem: cf1081_f
Difficulty: easy
Categories: bit, math
Time limit: 1000 ms, memory limit: 256 MB

This is an interactive problem.

Chouti was tired of studying, so he opened the computer and started playing a puzzle game.

Long long ago, the boy found a sequence $s_1, s_2, \ldots, s_n$ of length $n$, kept by a tricky interactor. It consisted of $0$s and $1$s only and the number of $1$s is $t$. The boy knows nothing about this sequence except $n$ and $t$, but he can try to find it out with some queries with the interactor.

We define an operation called flipping. Flipping $[l,r]$ ($1 \leq l \leq r \leq n$) means for each $x \in [l,r]$, changing $s_x$ to $1-s_x$.

In each query, the boy can give the interactor two integers $l,r$ satisfying $1 \leq l \leq r \leq n$ and the interactor will either flip $[1,r]$ or $[l,n]$ (both outcomes have the same probability and all decisions made by interactor are independent from each other, see Notes section for more details). The interactor will tell the current number of $1$s after each operation. Note, that the sequence won't be restored after each operation.

Help the boy to find the original sequence in no more than $10000$ interactions.

"Weird legend, dumb game." he thought. However, after several tries, he is still stuck with it. Can you help him beat this game?

Interaction

The interaction starts with a line containing two integers $n$ and $t$ ($1 \leq n \leq 300$, $0 \leq t \leq n$) — the length of the sequence and the number of $1$s in it.

After that, you can make queries.

To make a query, print a line "? l r" ($1 \leq l \leq r \leq n$), then flush the output.

After each query, read a single integer $t$ ($-1 \leq t \leq n$).

* If $t=-1$, it means that you're out of queries, you should terminate your program immediately, then you will get Wrong Answer, otherwise the judging result would be undefined because you will interact with a closed stream.
* If $t \geq 0$, it represents the current number of $1$s in the sequence.

When you found the original sequence, print a line "! s", flush the output and terminate. Print $s_1, s_2, \ldots, s_n$ as a binary string and do not print spaces in between.

Your solution will get Idleness Limit Exceeded if you don't print anything or forget to flush the output.

To flush you need to do the following right after printing a query and a line end:

* 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 2  
2  
2  
0
```

Output

```? 1 1? 1 1? 3 4! 0011
```

Note

For first query $1,1$, the interactor should flip $[1,1]$ or $[1,4]$. It chose to flip $[1,4]$, so the sequence became 1100.

For second query $1,1$, the interactor should flip $[1,1]$ or $[1,4]$. It again chose to flip $[1,4]$, so the sequence became 0011.

For third query $3,4$, the interactor should flip $[1,4]$ or $[3,4]$. It chose to flip $[3,4]$, so the sequence became 0000.

Q: How does interactor choose between $[1,r]$ and $[l,n]$? Is it really random?

A: The interactor will use a secret pseudorandom number generator. Only $s$ and your queries will be hashed and used as the seed. So if you give the same sequence of queries twice for the same secret string, you will get the same results. Except this, you can consider the choices fully random, like flipping a fair coin. You needn't (and shouldn't) exploit the exact generator to pass this problem.

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 parseLL(const string& s, long long& out) {
    if (s.empty()) return false;
    int i = 0;
    bool neg = false;
    if (s[0] == '-') {
        neg = true;
        i = 1;
        if ((int)s.size() == 1) 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;
}

static uint64_t splitmix64_next(uint64_t& x) {
    x += 0x9e3779b97f4a7c15ULL;
    uint64_t z = x;
    z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL;
    z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL;
    return z ^ (z >> 31);
}

static uint64_t hashString64(const string& s) {
    uint64_t h = 1469598103934665603ULL; 
    for (unsigned char c : s) {
        h ^= (uint64_t)c;
        h *= 1099511628211ULL;
    }
    uint64_t x = h ^ 0x9e3779b97f4a7c15ULL;
    
    (void)splitmix64_next(x);
    return x;
}

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

    try {
        int n = inf.readInt(1, 300, "n");
        string secret = inf.readToken();
        if ((int)secret.size() != n) finish(_pe, "Invalid hidden input: secret length mismatch");
        for (char c : secret) {
            if (c != '0' && c != '1') finish(_pe, "Invalid hidden input: non-binary character");
        }

        vector<int> cur(n, 0);
        int curOnes = 0;
        for (int i = 0; i < n; i++) {
            cur[i] = (secret[i] == '1') ? 1 : 0;
            curOnes += cur[i];
        }

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

        
        log_metrics();

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

        uint64_t rng_state = hashString64(secret) ^ (uint64_t)n ^ ((uint64_t)curOnes << 16);

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

            if (cmd == "?") {
                string sl, sr;
                if (!(cin >> sl >> sr)) finish(_pe, "Malformed query: expected two integers");
                long long l, r;
                if (!parseLL(sl, l) || !parseLL(sr, r)) finish(_pe, "Malformed query: non-integer l/r");
                if (!(1 <= l && l <= r && r <= n)) finish(_pe, "Query out of range");

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

                
                rng_state ^= (uint64_t)queries * 0x9e3779b97f4a7c15ULL;
                rng_state ^= (uint64_t)l * 0xbf58476d1ce4e5b9ULL;
                rng_state ^= (uint64_t)r * 0x94d049bb133111ebULL;
                uint64_t coin = splitmix64_next(rng_state) & 1ULL;

                if (coin == 0) {
                    
                    int R = (int)r;
                    for (int i = 0; i < R; i++) {
                        if (cur[i]) curOnes--;
                        else curOnes++;
                        cur[i] ^= 1;
                    }
                } else {
                    
                    int L = (int)l - 1;
                    for (int i = L; i < n; i++) {
                        if (cur[i]) curOnes--;
                        else curOnes++;
                        cur[i] ^= 1;
                    }
                }

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

                
                

            } else if (cmd == "!") {
                string ans;
                if (!(cin >> ans)) finish(_pe, "Malformed answer: expected a binary string");
                if ((int)ans.size() != n) finish(_wa, "Wrong answer: length mismatch");
                for (char c : ans) {
                    if (c != '0' && c != '1') finish(_pe, "Malformed answer: non-binary character");
                }
                if (ans == secret) finish(_ok, "OK");
                finish(_wa, "Wrong answer");
            } else {
                finish(_pe, "Invalid command token");
            }
        }
    } catch (const std::exception& e) {
        finish(_pe, string("Interactor exception: ") + e.what());
    } catch (...) {
        finish(_pe, "Interactor unknown exception");
    }
    return 0;
}


Adaptive interactor (C++):

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

static string makeBalancedBothEnds(int n, int t, int maxDiscrepancyStart = 1) {
    vector<int> a(n, -1);
    int l = 0, r = n - 1;
    int leftLen = 0, leftOnes = 0;
    int rightLen = 0, rightOnes = 0;
    int onesLeft = t;

    int D = maxDiscrepancyStart;
    const int D_LIMIT = 12;

    auto okPlace = [&](int side, int bit) -> bool {
        if (bit == 1 && onesLeft <= 0) return false;
        int placed = leftLen + rightLen;
        int remSlotsAfter = n - placed - 1;
        int onesAfter = onesLeft - bit;
        if (onesAfter < 0 || onesAfter > remSlotsAfter) return false;

        if (side == 0) {
            int newLen = leftLen + 1;
            int newOnes = leftOnes + bit;
            if (abs(newOnes * 2 - newLen) > D) return false;
        } else {
            int newLen = rightLen + 1;
            int newOnes = rightOnes + bit;
            if (abs(newOnes * 2 - newLen) > D) return false;
        }
        return true;
    };

    while (l <= r) {
        struct Cand {
            int side;
            int bit;
            int disc;
            int bias;
        };
        vector<Cand> cands;
        for (int side = 0; side < 2; side++) {
            if (l == r && side == 1) continue;
            for (int bit = 0; bit <= 1; bit++) {
                if (!okPlace(side, bit)) continue;
                int disc = 0;
                if (side == 0) {
                    disc = abs((leftOnes + bit) * 2 - (leftLen + 1));
                } else {
                    disc = abs((rightOnes + bit) * 2 - (rightLen + 1));
                }
                int placed = leftLen + rightLen;
                int remSlotsAfter = n - placed - 1;
                int onesAfter = onesLeft - bit;
                double need = (remSlotsAfter == 0 ? 0.0 : (double)onesAfter / (double)remSlotsAfter);
                int bias = (int)llround(fabs(need - 0.5) * 1000.0);
                cands.push_back({side, bit, disc, bias});
            }
        }

        if (cands.empty()) {
            if (D < D_LIMIT) {
                D++;
                continue;
            }
            
            for (int side = 0; side < 2; side++) {
                if (l == r && side == 1) continue;
                for (int bit = 0; bit <= 1; bit++) {
                    if (bit == 1 && onesLeft <= 0) continue;
                    int placed = leftLen + rightLen;
                    int remSlotsAfter = n - placed - 1;
                    int onesAfter = onesLeft - bit;
                    if (onesAfter < 0 || onesAfter > remSlotsAfter) continue;
                    int disc = 0;
                    cands.push_back({side, bit, disc, 0});
                }
            }
            if (cands.empty()) break;
        }

        int bestDisc = INT_MAX;
        for (auto &c : cands) bestDisc = min(bestDisc, c.disc);
        vector<Cand> best;
        for (auto &c : cands) if (c.disc == bestDisc) best.push_back(c);

        
        int bestBias = INT_MAX;
        for (auto &c : best) bestBias = min(bestBias, c.bias);
        vector<Cand> best2;
        for (auto &c : best) if (c.bias == bestBias) best2.push_back(c);

        Cand pick = best2[rnd.next(0, (int)best2.size() - 1)];
        if (pick.side == 0) {
            a[l++] = pick.bit;
            leftLen++;
            leftOnes += pick.bit;
        } else {
            a[r--] = pick.bit;
            rightLen++;
            rightOnes += pick.bit;
        }
        onesLeft -= pick.bit;
    }

    
    for (int i = 0; i < n; i++) {
        if (a[i] == -1) {
            int bit = (onesLeft > 0 ? 1 : 0);
            a[i] = bit;
            onesLeft -= bit;
        }
    }
    if (onesLeft != 0) {
        
        for (int i = 0; i < n && onesLeft != 0; i++) {
            if (onesLeft > 0 && a[i] == 0) {
                a[i] = 1;
                onesLeft--;
            } else if (onesLeft < 0 && a[i] == 1) {
                a[i] = 0;
                onesLeft++;
            }
        }
    }

    string s;
    s.reserve(n);
    for (int i = 0; i < n; i++) s.push_back(char('0' + a[i]));
    return s;
}

static int countOnes(const string &s) {
    int c = 0;
    for (char ch : s) c += (ch == '1');
    return c;
}

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

    string mode = opt<string>("mode", "non");
    int nOpt = opt<int>("n", 300);
    int tOpt = opt<int>("t", -1);
    int Dopt = opt<int>("D", 1);

    if (mode != "non" && mode != "adp") {
        quitf(_fail, "Unknown --mode: %s", mode.c_str());
    }

    int seed = atoi(argv[1]);

    int n = nOpt;
    int t = tOpt;
    string s;

    if (seed == 1) {
        
        n = 1;
        t = 0;
        s = "0";
    } else if (seed == 2) {
        
        n = 300;
        t = 0;
        s.assign(n, '0');
    } else if (seed == 3) {
        
        n = 300;
        t = 150;
        s.clear();
        s.reserve(n);
        for (int i = 0; i < n; i++) s.push_back((i % 2 == 0) ? '0' : '1');
    } else {
        
        n = max(1, min(300, nOpt));
        if (t == -1) {
            int base = n / 2;
            int skew = rnd.next(-2, 2);
            t = base + skew;
            if (t < 0) t = 0;
            if (t > n) t = n;
        } else {
            t = max(0, min(n, t));
        }

        
        if (rnd.next(0, 9) <= 7) {
            int near = n / 2 + rnd.next(-1, 1);
            t = max(0, min(n, near));
        }

        s = makeBalancedBothEnds(n, t, max(0, min(12, Dopt)));

        
        int cur = countOnes(s);
        if (cur != t) {
            vector<char> a(s.begin(), s.end());
            if (cur < t) {
                int need = t - cur;
                for (int i = n / 2, step = 0; need > 0 && step < n; step++) {
                    int idx = (i + (step % 2 == 0 ? step / 2 : -(step / 2 + 1)) + n) % n;
                    if (a[idx] == '0') { a[idx] = '1'; need--; }
                }
            } else {
                int need = cur - t;
                for (int i = n / 2, step = 0; need > 0 && step < n; step++) {
                    int idx = (i + (step % 2 == 0 ? step / 2 : -(step / 2 + 1)) + n) % n;
                    if (a[idx] == '1') { a[idx] = '0'; need--; }
                }
            }
            s.assign(a.begin(), a.end());
        }
    }

    if (mode == "non") {
        
        cout << n << "\n" << s << "\n";
    } else {
        
        if (t == -1) t = countOnes(s);
        cout << n << " " << t << "\n";
    }

    return 0;
}