Problem E


Steve and Alex have a challenge for you. They are each thinking of an integer between $1$ and $500$, and your task is to guess their numbers. If you can guess both numbers in $10$ guesses, they’ll give you a rare prize: a Pigstep music disc. Are you up to the challenge?

To make it easier for you, Steve and Alex are letting you give an interval for each guess. They will then tell you if their numbers are within the intervals you guess.


This is an interactive problem. You will interact with Steve and Alex using standard input and output.

To make a guess of an (inclusive) interval $[a,b]$, write a line to standard output in the following format:

  • ASK a b” (where $1 \leq a \leq b \leq 500$ are the bounds of the interval)

Both Steve and Alex will then tell you if their numbers were within the interval, via a single line of input consisting of two space-separated strings. Each string will be either “yes” or “no”, representing whether or not Steve and Alex’s numbers were in your interval, respectively.

You may ask at most $10$ times, after which you must guess their numbers. When you are ready to guess, write a line to standard output in the format:

  • GUESS s a” (where $1 \leq s, a \leq 500$ are your guesses for Steve and Alex’s numbers, respectively)

Your program should terminate after making your guess.

After every ask/guess, make sure to output a newline character and flush the output stream. To do this, use:

  • fflush(stdout) in C;

  • cout.flush() in C++;

  • System.out.flush() in Java;

  • stdout.flush() in Python.

Read Sample Interaction 1 Write
ASK 10 20
yes no
ASK 15 25
no yes
ASK 14 24
yes yes
ASK 14 23
yes no
GUESS 14 24
Read Sample Interaction 2 Write
ASK 50 100
no yes
ASK 50 150
yes yes
ASK 90 110
yes yes
ASK 91 110
yes yes
ASK 92 110
yes yes
ASK 93 110
yes no
ASK 92 109
no yes
GUESS 110 92

Please log in to submit a solution to this problem

Log in