#P1746E2. Joking (Hard Version)
Joking (Hard Version)
No submission language available for this problem.
Description
The only difference between this problem and the hard version is the maximum number of questions.
This is an interactive problem.
There is a hidden integer which you have to find. In order to find it you can ask at most questions.
In each question you can choose a non-empty integer set and ask if belongs to or not, after each question, if belongs to , you'll receive "YES", otherwise "NO".
But the problem is that not all answers are necessarily true (some of them are joking), it's just guaranteed that for each two consecutive questions, at least one of them is answered correctly.
Additionally to the questions, you can make at most guesses for the answer . Each time you make a guess, if you guess correctly, you receive ":)" and your program should terminate, otherwise you'll receive ":(".
As a part of the joking, we will not fix the value of in the beginning. Instead, it can change throughout the interaction as long as all the previous responses are valid as described above.
Note that your answer guesses are always answered correctly. If you ask a question before and after a guess, at least one of these two questions is answered correctly, as normal.
The only line of the input contains a single integer (), the maximum possible value of .
Interaction
For each question, if you want to ask about a set , first print the character '?', then print the size of and then print the elements of one by one. Each element should be an integer between and , the elements must be distinct. After each question, read a string "YES" or "NO", as explained in the statement. You can make at most such questions.
If you want to guess for , first print the character '!' and then print your guess. After each guess, read ":)" or ":(". If you guess correctly, the answer is ":)" and your program should terminate immediately, otherwise you'll receive ":(". You can make at most such guesses.
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.
Hacking is not allowed in this problem.
Input
The only line of the input contains a single integer (), the maximum possible value of .
Note
If the answer of the first question were correct, then would have been equal to , but as we can see in the first guess, is not the answer.
So the answer of the first question is joking. As we know, the answer of at least one of our two questions is correct, since the answer of the first question was joking, the answer of the second question should be correct.
So we will understand that is not equal to or , and we also knew that is not equal to either. Hence should be equal to .