atcoder#ARC078C. [ARC078E] Awkward Response

[ARC078E] Awkward Response

Score : 800800 points

Problem Statement

This is an interactive task.

Snuke has a favorite positive integer, NN. You can ask him the following type of question at most 6464 times: "Is nn your favorite integer?" Identify NN.

Snuke is twisted, and when asked "Is nn your favorite integer?", he answers "Yes" if one of the two conditions below is satisfied, and answers "No" otherwise:

  • Both nNn \leq N and str(n)str(N)str(n) \leq str(N) hold.
  • Both n>Nn > N and str(n)>str(N)str(n) > str(N) hold.

Here, str(x)str(x) is the decimal representation of xx (without leading zeros) as a string. For example, str(123)=str(123) = 123 and str(2000)str(2000) = 2000. Strings are compared lexicographically. For example, 11111 << 123 and 123456789 << 9.

Constraints

  • 1N1091 \leq N \leq 10^{9}

Input and Output

Write your question to Standard Output in the following format:

? n

Here, nn must be an integer between 11 and 101810^{18} (inclusive).

Then, the response to the question shall be given from Standard Input in the following format:

ans

Here, ansans is either Y or N. Y represents "Yes"; N represents "No".

Finally, write your answer in the following format:

! n

Here, n=Nn=N must hold.

Judging

  • After each output, you must flush Standard Output. Otherwise you may get TLE.
  • After you print the answer, the program must be terminated immediately. Otherwise, the behavior of the judge is undefined.
  • When your output is invalid or incorrect, the behavior of the judge is undefined (it does not necessarily give WA).

Sample

Below is a sample communication for the case N=123N=123:

Input Output
? 1
Y
? 32
N
? 1010
N
? 999
Y
! 123
  • Since 11231 \leq 123 and str(1)str(123)str(1) \leq str(123), the first response is "Yes".
  • Since 3212332 \leq 123 but str(32)>str(123)str(32) > str(123), the second response is "No".
  • Since 1010>1231010 > 123 but str(1010)str(123)str(1010) \leq str(123), the third response is "No".
  • Since 999123999 \geq 123 and str(999)>str(123)str(999) > str(123), the fourth response is "Yes".
  • The program successfully identifies N=123N=123 in four questions, and thus passes the case.