Your friend Terry has beautiful buckets. Jealous, you ask to "borrow" them. Your friend Terry is skeptical of your intentions, however, and so has decided that you can borrow the buckets only if you can pass his test.
Terry wants to make sure you know enough about the buckets. To prove you know his buckets, you need to determine the capacities of each bucket, each of which is a positive integer not greater than .
You complain that you could never guess the capacities, and so he allows you operations, before he gets bored and goes home. Initially, all his buckets are full of water. You can ask Terry to empty the -th bucket, you can ask him to fill the -th bucket, or you can ask him to dump the -th bucket's contents into the -th bucket, discarding any overflow. In the last case, Terry will tell you the change in height of the -th bucket, that is, if the initial height before dumping is and after is , Terry will reply with .
Can you determine the capacities of Terrys' buckets?
Interaction
This is an interactive problem. The first line of input contains and .
You will then begin interaction with Terry, using up to operations. If you output E i
(followed by a \n
character), Terry will empty the -th bucket. If you output F i
(followed by a \n
character), Terry will fill the -th bucket. If you output D i j
(followed by a \n
character) with , Terry will dump the contents of the -th bucket into the -th bucket, ignoring overflow. He will then respond with the difference in heights.
If you believe you have the correct list of capacities you may output A
followed by a space-separated list of integers (followed by a \n
character), representing your guess of the list of capacities in order from the first bucket to the last. You must terminate your program immediately after performing this operation. Note that this operation does not count towards the limit of operations.
For all cases, it is guaranteed that all of the correct numbers in the list are integers in the range . Also, the bucket capacities are fixed before the interaction begins and will not depend on your operations.
For of available marks, and will hold.
If at any point your query is malformed or you exceed the number of available queries, your program will receive -1
and the interactor will terminate. Upon receiving -1
, your program should terminate to avoid an undefined verdict.
If you attempt an invalid operation (such as invalid output format), you will receive a Presentation Error
verdict.
If you exceed the available query limit, you query an invalid bucket, or you output an incorrect final array, you will receive a Wrong Answer
verdict.
Please note that you may need to flush stdout
after each operation, or interaction may halt. In C++, this can be done with fflush(stdout)
or cout << flush
(depending on whether you use printf
or cout
). In Java, this can be done with System.out.flush()
. In Python, you can use sys.stdout.flush()
.
Sample Interaction
>>>
denotes your output. Do not print this out.
The buckets have capacities .
3 10
>>> E 1
>>> E 3
>>> D 2 1
2
>>> D 1 2
2
>>> F 1
>>> D 1 3
1
>>> A 2 4 1
Sample Explanation
After our two empty operations, the water levels are . When we dump the contents of into , we get . The first bucket's water level has increased by units.
Then we dump from into , getting . Filling bucket , we get , and after dumping into , we get .
Finally, we output the correct array.
This interaction would receive an Accepted
verdict, since it correctly guessed the list of capacities and did not exceed the limit of operations.
Comments