Skip to content

Hidden Integer

Problem code: myt0150 Group: Training Problem type: Interactive Interactive

Time limit
5.0 s
Memory limit
256 MB
Points
10partial
AC rate
100.0%
Solvers
1

Interactive problem

Your program talks to the interactor through standard input and output. Flush the output after every line you print, otherwise both programs wait for each other and you get Time Limit Exceeded.

  • C: fflush(stdout);
  • C++: cout << endl; or cout.flush(); (required with ios::sync_with_stdio(false) and cin.tie(0))
  • Python: print(..., flush=True)
  • Java: System.out.flush();
  • Pascal: flush(output);

Do not open files: read from standard input and write to standard output only. The interactor reads everything you print, so never print debug output there; keep standard error output small.

Exit as soon as the interactor reports an error (often by sending -1). If your program keeps running, the verdict can become Time Limit Exceeded or Runtime Error instead of Wrong Answer.

There is a hidden integer x. Your task is to find the value of x.

To do this, you can ask questions: you can choose an integer y and you will be told if y < x.

Interaction

This is an interactive problem. Your code will interact with the grader using standard input and output. You can start asking questions right away. On your turn, you can print one of the following:

"?\ y", where 1 \le y \le 10^9: ask if y < x. The grader will return YES if y < x and NO otherwise.

"!\ x": report that the hidden integer is x. Your program must terminate after this.

Each line should be followed by a line break. You must make sure the output gets flushed after printing each line.

Constraints

1 \le x \le 10^9

you can ask at most 30 questions of type ?

Example

? 3
YES
? 6
YES
? 7
NO
! 7

Comments