Problem: cf1466_i
Difficulty: easy
Categories: bit, greedy, data structures
Time limit: 1000 ms, memory limit: 256 MB

What walks on four feet in the morning, two in the afternoon, and three at night?

This is an interactive problem.

Sphinx's duty is to guard the city of Thebes by making sure that no unworthy traveler crosses its gates. Only the ones who answer her riddle timely and correctly (or get an acc for short) are allowed to pass. As of those who fail, no one heard of them ever again...

So you don't have a choice but to solve the riddle. Sphinx has an array $a_1, a_2, \ldots, a_n$ of nonnegative integers strictly smaller than $2^b$ and asked you to find the maximum value among its elements. Of course, she will not show you the array, but she will give you $n$ and $b$. As it is impossible to answer this riddle blindly, you can ask her some questions. For given $i, y$, she'll answer you whether $a_i$ is bigger than $y$. As sphinxes are not very patient, you can ask at most $3 \cdot (n + b) $ such questions.

Although cunning, sphinxes are honest. Even though the array can change between your queries, answers to the previously asked questions will remain valid.

Input

The first line contains two integers $n$ and $b$ ($1 \leq n, b \leq 200$). The remaining parts of the input will be given throughout the interaction process.

Interaction

In each round your program must output a single line with an integer $i$ ($0 \leq i \leq n$) and a binary string of length exactly $b$ denoting the binary representation of $y$ (most significant bit first).

If $i > 0$, this line encodes the question: Is $a_i$ bigger than $y$?. There should be at most $3 \cdot (n+b)$ such lines; after each of them, the interactor will print yes or no in a single line.

If $i = 0$, this is the last round of interaction, after which your program should terminate, and $y$ should be the maximal value among the elements of Sphinx's array. Note that this round does not count to the query limit.

Note that the interactor is adaptive.

After printing a query, do not forget to output the end of the 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 the documentation for other languages.

If your solution does not correctly follow the interaction guideline above, it may receive an arbitrary verdict. Otherwise, your program will receive the Wrong Answer judgment if it reports the wrong maximum.

Examples

Input

```
5 3

yes

no

no

no

no

yes
```

Output

```
5 101

5 110

4 100

3 101

2 001

1 000

0 110
```

Input

```
4 3

no

no

no

no
```

Output

```
1 000

2 000

3 000

4 000

0 000
```

Input

```
1 1
```

Output

```
0 0
```

Note

In all examples, the sequence is fixed beforehand.

In the first example, the sequence is $2, 1, 4, 0, 6$.

In the second example, the sequence is $0, 0, 0, 0$.

In the third example, the sequence is $0$.

Note that if the interactor was adaptive, then the interaction in the first and the third example would not be sufficient to return the correct value of maximum.

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 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) {
    log_metrics();
    finished = true;
    quitf(verdict, "%s", msg.c_str());
}


string div2(string s, int &rem) {
    string res = "";
    rem = 0;
    bool leading_zeros = true;
    for (char c : s) {
        int d = c - '0';
        int val = d + rem * 10;
        int q = val / 2;
        rem = val % 2;
        
        if (q != 0) leading_zeros = false;
        if (!leading_zeros) res += to_string(q);
    }
    if (res.empty()) return "0";
    return res;
}


string toBin(string s, int b) {
    string bin = "";
    if (s == "0") return string(b, '0');
    
    while (s != "0") {
        int rem;
        s = div2(s, rem);
        bin += (char)('0' + rem);
    }
    
    
    while ((int)bin.size() < b) bin += '0';
    
    
    reverse(bin.begin(), bin.end());
    
    
    if ((int)bin.size() > b) bin = bin.substr(bin.size() - b);
    
    return bin;
}

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

    
    int n = inf.readInt(1, 200, "n");
    int b = inf.readInt(1, 200, "b");
    
    
    query_limit = 3LL * (n + b);
    
    
    log_metrics();

    vector<string> A(n);
    string true_max = "";
    
    
    for (int i = 0; i < n; i++) {
        string dec = inf.readToken();
        A[i] = toBin(dec, b);
        
        if (true_max == "" || A[i] > true_max) {
            true_max = A[i];
        }
    }

    
    cout << n << " " << b << endl;
    
    
    
    long long hard_cap = max(200000LL, 10 * query_limit);
    
    while (true) {
        if (queries > hard_cap) {
            finish(_pe, "Hard query limit exceeded (potential infinite loop)");
        }

        
        string token;
        if (!(cin >> token)) {
            finish(_pe, "Unexpected EOF while reading query");
        }
        
        int idx = -1;
        string y_str = "";
        
        
        if (token == "?") {
            if (!(cin >> idx >> y_str)) finish(_pe, "Invalid query format after '?'");
        } else if (token == "!") {
            if (!(cin >> y_str)) finish(_pe, "Invalid answer format after '!'");
            idx = 0; 
        } else {
            
            try {
                size_t pos;
                idx = stoi(token, &pos);
                if (pos != token.size()) finish(_pe, "First token is not a valid integer");
            } catch (...) {
                finish(_pe, "First token is not a valid integer");
            }
            if (!(cin >> y_str)) finish(_pe, "Expected binary string as second parameter");
        }
        
        
        if (idx == 0) {
            
            if ((int)y_str.size() != b) {
                finish(_pe, format("Answer string length must be %d", b));
            }
            for (char c : y_str) {
                if (c != '0' && c != '1') finish(_pe, "Answer string must be binary");
            }
            
            if (y_str == true_max) {
                finish(_ok, "Correct maximum found");
            } else {
                finish(_wa, format("Incorrect maximum. Expected %s, got %s", true_max.c_str(), y_str.c_str()));
            }
        } else {
            
            if (idx < 1 || idx > n) {
                finish(_pe, format("Index %d out of range [1, %d]", idx, n));
            }
            if ((int)y_str.size() != b) {
                finish(_pe, format("Query string length must be %d", b));
            }
            for (char c : y_str) {
                if (c != '0' && c != '1') finish(_pe, "Query string must be binary");
            }
            
            queries++;
            
            if (queries % 10 == 0) log_metrics();
            
            
            bool result = (A[idx - 1] > y_str);
            cout << (result ? "yes" : "no") << endl;
        }
    }
    
    return 0;
}


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 << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {
        
    }
}


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



struct BigInt {
    vector<int> d; 

    BigInt() {}
    
    
    BigInt(string s) {
        for (int i = (int)s.size() - 1; i >= 0; i--) {
            if (s[i] == '1') d.push_back(1);
            else d.push_back(0);
        }
        trim();
    }
    
    
    BigInt(int v) {
        if (v > 0) d.push_back(1);
        else d.push_back(0); 
    }

    void trim() {
        while (d.size() > 1 && d.back() == 0) d.pop_back();
        if (d.empty()) d.push_back(0);
    }

    bool operator<(const BigInt& o) const {
        if (d.size() != o.d.size()) return d.size() < o.d.size();
        for (int i = (int)d.size() - 1; i >= 0; i--)
            if (d[i] != o.d[i]) return d[i] < o.d[i];
        return false;
    }
    bool operator<=(const BigInt& o) const { return !(o < *this); }
    bool operator>(const BigInt& o) const { return o < *this; }
    bool operator>=(const BigInt& o) const { return !(*this < o); }
    bool operator==(const BigInt& o) const { return d == o.d; }
    bool operator!=(const BigInt& o) const { return d != o.d; }

    BigInt operator+(const BigInt& o) const {
        BigInt res; res.d.clear();
        int carry = 0;
        size_t n = max(d.size(), o.d.size());
        for (size_t i = 0; i < n || carry; i++) {
            int val = carry + (i < d.size() ? d[i] : 0) + (i < o.d.size() ? o.d[i] : 0);
            res.d.push_back(val % 2);
            carry = val / 2;
        }
        return res;
    }

    
    BigInt operator-(const BigInt& o) const {
        BigInt res; res.d.clear();
        int borrow = 0;
        for (size_t i = 0; i < d.size(); i++) {
            int val = d[i] - borrow - (i < o.d.size() ? o.d[i] : 0);
            if (val < 0) {
                val += 2;
                borrow = 1;
            } else {
                borrow = 0;
            }
            res.d.push_back(val);
        }
        res.trim();
        return res;
    }
};

BigInt one(1);

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

    
    int n = inf.readInt();
    int b = inf.readInt();
    query_limit = 3LL * (n + b);

    
    bool fixed_mode = false;
    vector<BigInt> fixed_arr;
    if (!inf.seekEof()) {
        fixed_mode = true;
        for(int i=0; i<n; i++) {
            string s = inf.readToken();
            fixed_arr.push_back(BigInt(s));
        }
    }

    
    
    string all_ones(b, '1');
    string all_zeros(b, '0');
    BigInt max_val(all_ones);
    BigInt min_val(all_zeros);

    vector<BigInt> L(n + 1, min_val);
    vector<BigInt> R(n + 1, max_val);

    
    cout << n << " " << b << endl; 

    
    while (true) {
        
        if (queries > max(20000LL, 10 * query_limit)) {
            finish(_pe, "Hard query limit exceeded");
        }

        int i;
        if (!(cin >> i)) break; 
        
        string y_str;
        cin >> y_str;
        
        
        if (i < 0 || i > n) finish(_pe, "Index i out of range");
        if (y_str.size() != (size_t)b) finish(_pe, "Binary string y wrong length");
        for(char c : y_str) if(c != '0' && c != '1') finish(_pe, "y not binary");

        BigInt y(y_str);

        if (i == 0) {
            
            if (fixed_mode) {
                BigInt true_max = fixed_arr[0];
                for(int k=1; k<n; k++) if(fixed_arr[k] > true_max) true_max = fixed_arr[k];
                if (y == true_max) finish(_ok, "Correct maximum (fixed)");
                else finish(_wa, "Wrong maximum (fixed)");
            } else {
                
                
                
                
                
                
                for(int k=1; k<=n; k++) {
                     if (R[k] > y) {
                         
                         finish(_wa, "Found feasible array with maximum > y");
                     }
                }
                
                
                
                
                
                
                
                bool forced_at_y = false;
                for(int k=1; k<=n; k++) {
                    if (L[k] == y) {
                        forced_at_y = true;
                        break;
                    }
                }
                
                if (!forced_at_y) {
                    
                    
                    finish(_wa, "Found feasible array with maximum < y");
                }
                
                finish(_ok, "Correct");
            }
        }
        
        
        queries++;
        log_metrics(); 
        
        bool ans_yes = false;
        
        if (fixed_mode) {
            if (fixed_arr[i-1] > y) ans_yes = true;
            else ans_yes = false;
        } else {
            
            
            bool yes_possible = (y < R[i]);
            
            bool no_possible = (L[i] <= y);
            
            if (!yes_possible && !no_possible) {
                finish(_pe, "Inconsistent state (interactor error)");
            } else if (!yes_possible) {
                ans_yes = false;
            } else if (!no_possible) {
                ans_yes = true;
            } else {
                
                
                
                BigInt size_yes = R[i] - y;
                BigInt size_no = (y - L[i]) + one;
                
                if (size_yes > size_no) ans_yes = true;
                else ans_yes = false;
            }
            
            
            if (ans_yes) {
                
                L[i] = y + one;
            } else {
                
                R[i] = y;
            }
        }
        
        
        if (ans_yes) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    
    finish(_pe, "Unexpected EOF from contestant");
    return 0;
}


Test generator (C++):








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

using namespace std;


string bitsToDecimal(const vector<int>& bits) {
    if (bits.empty()) return "0";
    vector<int> digits;
    digits.push_back(0);
    
    for (int b : bits) {
        int carry = b;
        for (int &d : digits) {
            int val = d * 2 + carry;
            d = val % 10;
            carry = val / 10;
        }
        while (carry) {
            digits.push_back(carry % 10);
            carry /= 10;
        }
    }
    
    if (digits.empty()) return "0";
    string res = "";
    for (auto it = digits.rbegin(); it != digits.rend(); ++it) {
        res += to_string(*it);
    }
    return res;
}

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

    string mode = opt<string>("mode", "non");
    
    
    int n = opt<int>("n", -1);
    int b = opt<int>("b", -1);
    
    
    long long seedVal = 0;
    if (argc > 1) seedVal = atoll(argv[1]);

    
    if (n == -1 && b == -1) {
        if (seedVal == 1) { n = 5; b = 3; }
        else if (seedVal == 2) { n = 4; b = 3; }
        else if (seedVal == 3) { n = 1; b = 1; }
        else if (seedVal == 4) { n = 200; b = 200; }
        else if (seedVal == 5) { n = 200; b = 1; }
        else if (seedVal == 6) { n = 1; b = 200; }
    }

    
    if (n == -1) {
        int r = rnd.next(3);
        if (r == 0) n = rnd.next(1, 10);      
        else n = rnd.next(100, 200);          
    }
    if (b == -1) {
        int r = rnd.next(3);
        if (r == 0) b = rnd.next(1, 10);      
        else b = rnd.next(100, 200);          
    }

    cout << n << " " << b << endl;

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

    
    vector<string> a;
    
    
    int type = rnd.next(100);
    
    
    if (seedVal == 1) type = 0;  
    else if (seedVal == 2) type = 55; 
    else if (seedVal == 3) type = 0;
    
    if (type < 50) { 
        
        for(int i = 0; i < n; i++) {
            vector<int> bits(b);
            for(int j = 0; j < b; j++) bits[j] = rnd.next(0, 1);
            a.push_back(bitsToDecimal(bits));
        }
    } else if (type < 60) {
        
        for(int i = 0; i < n; i++) a.push_back("0");
    } else if (type < 70) {
        
        vector<int> bits(b, 1);
        string mx = bitsToDecimal(bits);
        for(int i = 0; i < n; i++) a.push_back(mx);
    } else if (type < 85) {
        
        int p = rnd.next(1, max(1, b - 1));
        vector<int> prefix(p);
        for(int j = 0; j < p; j++) prefix[j] = rnd.next(0, 1);
        for(int i = 0; i < n; i++) {
            vector<int> bits = prefix;
            for(int j = p; j < b; j++) bits.push_back(rnd.next(0, 1));
            a.push_back(bitsToDecimal(bits));
        }
    } else {
        
        
        vector<int> mx_bits(b);
        for(int j = 0; j < b; j++) mx_bits[j] = rnd.next(0, 1);
        string mx_s = bitsToDecimal(mx_bits);
        a.push_back(mx_s);
        
        for(int i = 1; i < n; i++) {
            if (rnd.next(2)) {
                
                vector<int> bits(b);
                for(int j = 0; j < b; j++) bits[j] = rnd.next(0, 1);
                a.push_back(bitsToDecimal(bits));
            } else {
                
                vector<int> sm = mx_bits;
                vector<int> ones;
                for(int k = 0; k < b; k++) if(sm[k]) ones.push_back(k);
                if(!ones.empty()) {
                    int idx = ones[rnd.next(ones.size())];
                    sm[idx] = 0;
                    for(int k = idx + 1; k < b; k++) sm[k] = rnd.next(0, 1);
                }
                a.push_back(bitsToDecimal(sm));
            }
        }
        shuffle(a.begin(), a.end());
    }

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

    return 0;
}