Problem: cf1028_g
Difficulty: medium
Categories: game, greedy
Time limit: 2000 ms, memory limit: 256 MB

This problem is interactive.

You should guess hidden number $x$ which is between $1$ and $M = 10004205361450474$, inclusive.

You could use up to $5$ queries.

In each query, you can output an increasing sequence of $k \leq x$ integers, each between $1$ and $M$, inclusive, and you will obtain one of the following as an answer:

* either the hidden number belongs to your query sequence, in this case you immediately win;
* or you will be given where the hidden number is located with respect to your query sequence, that is, either it is less than all numbers from the sequence, greater than all numbers from the sequence, or you will be given such an $i$ that the hidden number $x$ is between the $i$-th and the $(i+1)$-st numbers of your sequence.

See the interaction section for clarity.

Be aware that the interactor is adaptive, i.e. the hidden number can depend on queries the solution makes. However, it is guaranteed that for any solution the interactor works non-distinguishable from the situation when the hidden number is fixed beforehand.

Interaction

You can make up to $5$ queries. To make a query print a number $k$ ($1 \le k \le 10^4$) and then an increasing sequence $t_0 < t_1 < \ldots < t_{k-1}$ of $k$ numbers, each between $1$ and $M$, inclusive. If $k > x$, you lose.

You get one integer as a response.

* If it is $-2$, it means you made an invalid query or you lost. Exit immediately after receiving $-2$ 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.
* If it is $-1$, you guessed the number and should terminate too.
* Otherwise you get a number $i$ between $0$ and $k$, inclusive, denoting where the hidden number is, with respect to the printed numbers. If $i = 0$, then $x < t_0$. If $i = k$, then $t_{k-1} < x$. Otherwise $t_{i-1} < x < t_i$.

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

```
   
2  
  
0  
  
-1
```

Output

```
2 2 3  
  
2 20 30  
  
3 5 7 9
```

Note

In the first example the number $5$ is hidden.

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

using namespace std;


const long long M = 10004205361450474LL;

const int QUERY_LIMIT_VAL = 5;


static int queries = 0;
static int query_limit = QUERY_LIMIT_VAL;




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


template <typename... Args>
void die(TResult verdict, const char* fmt, Args... args) {
    log_metrics();
    quitf(verdict, fmt, args...);
}

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

    
    
    
    long long x = inf.readLong();

    
    log_metrics();

    
    if (x < 1) {
        die(_fail, "Invalid hidden number x=%lld (must be >= 1 for non-adaptive mode)", x);
    }

    
    string token;
    
    while (cin >> token) {
        
        if (token == "?") {
            if (!(cin >> token)) {
                die(_wa, "Unexpected EOF after '?'");
            }
        }

        
        long long k;
        try {
            size_t pos;
            k = stoll(token, &pos);
            if (pos != token.size()) {
                die(_wa, "Garbage in k token: %s", token.c_str());
            }
        } catch (...) {
            die(_wa, "Invalid format for k: %s", token.c_str());
        }

        
        
        
        if (queries >= query_limit) {
            cout << -2 << endl;
            die(_wa, "Query limit exceeded (attempted %d queries)", queries + 1);
        }

        
        if (k < 1 || k > 10000) {
            cout << -2 << endl;
            die(_wa, "k=%lld out of range [1, 10000]", k);
        }

        
        
        if (k > x) {
            cout << -2 << endl;
            die(_wa, "k=%lld > x=%lld (Constraint violation -> You lose)", k, x);
        }

        
        vector<long long> t(k);
        for (int i = 0; i < k; ++i) {
            string num_str;
            if (!(cin >> num_str)) {
                die(_wa, "Unexpected EOF while reading sequence number %d", i);
            }
            try {
                t[i] = stoll(num_str);
            } catch (...) {
                die(_wa, "Invalid number format in sequence: %s", num_str.c_str());
            }

            
            if (t[i] < 1 || t[i] > M) {
                cout << -2 << endl;
                die(_wa, "Number %lld out of range [1, M]", t[i]);
            }

            
            if (i > 0 && t[i] <= t[i-1]) {
                cout << -2 << endl;
                die(_wa, "Sequence not strictly increasing: %lld <= %lld", t[i], t[i-1]);
            }
        }

        
        queries++;
        log_metrics(); 

        
        int result_idx = -2; 
        bool won = false;

        if (x < t[0]) {
            result_idx = 0;
        } else if (x > t[k-1]) {
            result_idx = k;
        } else {
            
            for (int i = 0; i < k; ++i) {
                if (t[i] == x) {
                    won = true;
                    break;
                }
                
                if (i + 1 < k && t[i] < x && x < t[i+1]) {
                    result_idx = i + 1;
                    break;
                }
            }
        }

        
        if (won) {
            cout << -1 << endl;
            die(_ok, "Guessed hidden number %lld in %d queries", x, queries);
        } else {
            
            if (result_idx < 0) {
                
                die(_fail, "Logic error: could not classify x relative to sequence");
            }
            cout << result_idx << endl;
        }
    }

    
    die(_wa, "Solution exited without guessing x");
}


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


const long long M_MAX = 10004205361450474LL;
const int Q_LIMIT = 5;


int queries = 0;
int query_limit = Q_LIMIT;


long long L = 1, R = M_MAX;
long long secret_x = 0;
bool adaptive_mode = true;
map<int, long long> memo[Q_LIMIT + 1];


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

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




long long get_capacity(int q, long long l) {
    if (q == 0) return 0;
    
    
    
    long long eff_l = (l >= 10000 ? 10000 : l);
    if (memo[q].count((int)eff_l)) return memo[q][(int)eff_l];
    
    long long current_val = l;
    int k = (int)eff_l;
    long long limit = M_MAX + 1000; 
    
    for (int i = 0; i <= k; i++) {
        
        if (current_val >= 10000) {
            long long step = get_capacity(q - 1, 10000);
            
            
            long long remaining_middle = k - i;
            if (remaining_middle > 0) {
                
                double check = (double)remaining_middle * (double)(step + 1);
                if (check > 2e18 || limit - current_val < (long long)check) {
                    current_val = limit;
                } else {
                    current_val += remaining_middle * (step + 1);
                }
            }
            
            
            if (current_val < limit) {
                if (limit - current_val < step) current_val = limit;
                else current_val += step;
            }
            break;
        }
        
        
        long long sub = get_capacity(q - 1, current_val);
        if (i < k) {
            
            if (limit - current_val < sub + 1) { current_val = limit; break; }
            current_val += sub + 1;
        } else {
            
            if (limit - current_val < sub) { current_val = limit; break; }
            current_val += sub;
        }
    }
    
    long long res = current_val - l;
    return memo[q][(int)eff_l] = res;
}

int main(int argc, char* argv[]) {
    registerInteraction(argc, argv);
    
    
    long long in_val = inf.readLong();
    if (in_val > 0) {
        adaptive_mode = false;
        secret_x = in_val;
    }
    
    
    log_metrics();
    
    
    
    while (true) {
        
        if (cin.eof()) break;
        long long k_long;
        
        if (!(cin >> k_long)) break;
        
        queries++;
        log_metrics();
        
        if (queries > Q_LIMIT) {
             finish(_pe, "Too many queries");
        }
        
        if (k_long < 1 || k_long > 10000) {
            cout << -2 << endl;
            finish(_wa, "k out of range [1, 10000]");
        }
        
        int k = (int)k_long;
        vector<long long> t(k);
        for (int i = 0; i < k; i++) {
            cin >> t[i];
        }
        
        
        for (int i = 0; i < k; i++) {
            if (t[i] < 1 || t[i] > M_MAX) {
                cout << -2 << endl;
                finish(_wa, "Value out of range [1, M]");
            }
            if (i > 0 && t[i] <= t[i-1]) {
                cout << -2 << endl;
                finish(_wa, "Sequence not strictly increasing");
            }
        }
        
        
        
        if (adaptive_mode) {
            if (L < k) {
                cout << -2 << endl;
                finish(_wa, "Query size k > x is possible (x could be L)");
            }
        } else {
            if (secret_x < k) {
                cout << -2 << endl;
                finish(_wa, "k > x");
            }
        }
        
        int response = -2;
        
        if (!adaptive_mode) {
            
            bool found = false;
            for (long long val : t) {
                if (val == secret_x) {
                    found = true;
                    break;
                }
            }
            if (found) {
                cout << -1 << endl;
                finish(_ok, "Guessed correct number");
            }
            
            
            if (secret_x < t[0]) response = 0;
            else if (secret_x > t[k-1]) response = k;
            else {
                
                for (int i = 0; i < k - 1; i++) {
                    if (t[i] < secret_x && secret_x < t[i+1]) {
                        response = i + 1;
                        break;
                    }
                }
            }
        } else {
            
            struct Candidate {
                int index;
                long long start, end;
                long long len;
                long long capacity;
                bool impossible; 
            };
            
            vector<Candidate> candidates;
            
            auto add_candidate = [&](int idx, long long low, long long high) {
                long long r_start = max(L, low);
                long long r_end = min(R, high);
                if (r_start <= r_end) {
                    long long len = r_end - r_start + 1;
                    long long cap = get_capacity(Q_LIMIT - queries, r_start);
                    candidates.push_back({idx, r_start, r_end, len, cap, len > cap});
                }
            };
            
            
            add_candidate(0, 1, t[0] - 1);
            
            for (int i = 0; i < k - 1; i++) {
                add_candidate(i + 1, t[i] + 1, t[i+1] - 1);
            }
            
            add_candidate(k, t[k-1] + 1, M_MAX);
            
            if (candidates.empty()) {
                
                
                bool possible = false;
                for (long long val : t) {
                    if (val >= L && val <= R) {
                        possible = true;
                        break;
                    }
                }
                if (possible) {
                    cout << -1 << endl;
                    finish(_ok, "Forced to concede (adaptive)");
                } else {
                    
                    finish(_wa, "Inconsistent state");
                }
            }
            
            
            
            
            sort(candidates.begin(), candidates.end(), [](const Candidate& a, const Candidate& b) {
                if (a.impossible != b.impossible) return a.impossible > b.impossible;
                return a.len > b.len;
            });
            
            const Candidate& best = candidates[0];
            L = best.start;
            R = best.end;
            response = best.index;
        }
        
        cout << response << endl;
        
    }
    
    finish(_wa, "Exited without guessing");
    return 0;
}


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

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

    
    long long M = 10004205361450474LL;

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

    if (mode == "adp") {
        
        
        
        cout << 0 << endl;
    } else {
        
        long long x;
        long long seed_val = -1;
        
        
        if (argc > 1) {
            try {
                seed_val = stoll(string(argv[1]));
            } catch (...) {
                
                seed_val = -1;
            }
        }

        
        if (seed_val == 1) {
            x = 1; 
        } else if (seed_val == 2) {
            x = M; 
        } else if (seed_val == 3) {
            x = 10000; 
        } else {
            
            int t = rnd.next(100);
            if (t < 15) {
                
                x = rnd.next(1LL, 20000LL);
            } else if (t < 30) {
                
                x = rnd.next(M - 20000LL, M);
            } else if (t < 45) {
                
                x = rnd.next(9000LL, 11000LL);
            } else {
                
                x = rnd.next(1LL, M);
            }
        }
        cout << x << endl;
    }

    return 0;
}