Guess the Number


You friend is thinking of a number between ll and rr, and you are trying to guess it in as few guesses as possible. In response to each of your guesses, they will respond "HIGHER", "LOWER", or "CORRECT". You are required to find the number with at most ⌈log⁡2(l−r+1)⌉\lceil \log_2{\left(l-r+1\right)} \rceil guesses.

Interaction

The first line of input contains integers ll and rr, the range of valid numbers. You may now make guesses by printing an integer. In response to each of your guesses, the judge will respond with a line containing HIGHER, LOWER or CORRECT which you can read as a line of input.

Example

The judge first inputs

Sample 1
1 10

Your program prints 5.

Sample 2
LOWER

Your program prints 4

Sample 3
CORRECT

Constraints

  • 1≤l≤r≤1091 \le l \le r \le 10^9

Template

Code 1
l,r = (int(x) for x in input().split())

while True:
    print(guess)
    response = input()

    # Process response

    if response == "CORRECT":
        break

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.