Your friend Lina invited you and a bunch of other friends to a costume party to celebrate her success in writing her first program, called "Hello World!". Since the party was boring, you decided to try and guess Lina's position before the celebration comes to an end.
Strangely enough, your friends were standing in a line numbered from $$$1$$$ to $$$N$$$, consecutively from left to right. Initially, no one knows where Lina is, other than her. You can perform the following action at most $$$10^5$$$ times (or the party will be over):
Select one person, ask them where Lina is. If they don't know the answer (or the person is Lina), they will answer with $$$0$$$. Otherwise, they will return:
After each query, everyone who knows Lina's position will spread this information to the people next to them (at most two new people will know Lina's position after each query).
Keep in mind that the program is designed to challenge you. Lina can be in any position that is consistent with the answers you receive, so be cautious with your queries.
Your goal is to find Lina's position using as few queries as possible.
The first line contains an integer $$$N (1\leq N\leq 10^5)$$$ – the number of people at the party.
To inquire about the position of friend number $$$i$$$ ($$$1 \leq i \leq N$$$), use the format: "? i". The interactor will respond with:
To make a guess about Lina's position, use the format: "! i" ($$$1 \leq i \leq N$$$). You can only make one guess. The interactor will not respond to the guess, and your program should terminate immediately after making the guess.
Keep in mind that the grader is adaptive, meaning it will adjust its behavior based on your queries. Therefore, your queries influence the responses.
After each query or guess, remember to output a newline and flush the output to avoid an idleness limit exceeded verdict. In C++, you can do this with: fflush(stdout) or cout.flush().
Your score will be calculated based on the maximal value of $$$Q$$$, the number of queries made.
5 0 -1 1 0
? 3 ? 2 ? 5 ? 3 ! 3
In the sample test, there are 5 people, and Lina is at position 3.