Honing In
Nice job with your cleaning duties at AUCPL.inc. We've decided to promote you to junior problemsetter, where you can begin contributing to our many high-quality programming contests.
To begin your new job, you need to find your desk. The office at AUCPL.inc is, depressingly, a grid with rows and
columns of desks. The top-left desk is at
, and the bottom-right desk is at
. Being surrounded by so many coworkers is already quite overwhelming.
Luckily, your coworkers are (mostly) helpful. If you ask the worker sitting at desk where your assigned desk is, they will respond with one of four cardinal directions:
U(up)D(down)L(left)R(right)
This direction is guaranteed to point towards your desk (decrease Manhattan distance), though it is not necessarily the shortest or most direct route.
- For example, if your desk is exactly
1unit above and100units to the right of the coworker, they might sayUorR. - For example, if your desk is exactly
50units below the coworker, they will always sayD.
There is one exception: the coworker currently sitting at your desk. They've been laid off, and are not feeling very cooperative. Instead of giving useful information, they will always respond with a random direction.
By querying coworkers strategically, can you determine the location of your assigned desk?
Interaction
This is an interactive problem. Your submission will be run against an interactor, which reads from the standard output of your program and writes to its standard input. The interaction must follow the format below.
The interactor first sends two integers and
, representing the dimensions of your office floor.
Your program may then send at most commands to determine the location of your desk. To query a coworker, print a line in the form
, where
and
, meaning you ask the coworker at desk
where your desk is.
The interactor will respond with a single character , where
, indicating the direction given by that coworker. If the coworker at
returns a direction
, then moving one step from
in direction
results in a position that is strictly closer (in Manhattan distance) to your desk.
The only exception is the coworker currently sitting at your desk, who gives a uniformly random direction instead, with each of U, D, L, and R chosen independently with probability for every query.
For any desk other than your own, repeated queries to the same will always return the same direction.
Once you know the location of your desk, print a line in the form where
and
, meaning you attempt to claim the desk at
.
You will receive a Wrong Answer if:
- You send more than 150
?commands, or - Your
!command is not the true location of your desk.
Example
Interaction 1
> 3 3
< 1 1 ?
> D
< 3 3 ?
> U
< 2 2 ?
> R
< 2 3 ?
> D
< 2 3 ?
> U
< 2 3 !
Explanation 1
Your desk is at . Here's a breakdown of the interaction:
- The employee at desk
says your desk is below them (
D). They could have saidDorR. - The employee at desk
says your desk is above them (
U). They could only have saidU, as your desk is in the same column. - The employee at desk
says your desk is to the right of them (
R). They could only have saidR, as your desk is on the same row. - The employee at desk
says your desk is below them (
D). They could have given any direction. - The employee at desk
says your desk is above them (
U). They could have given any direction. - You guess desk
, which is correct.
The directions the employees would give are visualised below:

Interaction 2
> 6 7
< 2 2 ?
> D
< 5 2 ?
> R
< 4 4 ?
> U
< 3 5 ?
> L
< 3 4 ?
> D
< 4 4 ?
> U
< 3 4 ?
> L
< 3 4 !
Explanation 2
The directions the employees would give are visualised below:

Comments