#include <cstdio> #include <iostream> #include <fstream> #include <vector> #include <list> #include <map> #include <set> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <sstream> #include <iomanip> #include <cmath> #include <cstdlib> #include <ctype.h> #include <cstring> #include <string> #include <ctime> #include <cassert> #include <utility> using namespace std; bool sureAboutAnswer; int main() { // freopen("date.in", "r", stdin); // freopen("date.out","w", stdout); int n, k, x, st, dr; cin >> n >> k; //read the number of stories and eggs string response; st = 0; dr = n; sureAboutAnswer = false; while(response != "exit") { x = (dr + st)/ 2; sureAboutAnswer = (st > dr) ? true : false; if(!sureAboutAnswer) { //perhaps you need more information cout << "query " << x << "\n"; cout.flush(); cin >> response; if(response == "broke") { k--; dr = x - 1; } else if(response == "survived") { st = x + 1; } } else { //in case you've found the answer cout << "answer " << st << "\n"; cout.flush(); cin >> response; //the response is going to be "exit" } } return 0; }