You are going to the farmers market to buy and sell fruit. There are farmers markets that each buy and sell types of fruit: Apples, and Bananas. Initially, each market will buy and sell each type of fruit at a fixed price decided by its farmer, who will keep these prices forever. Since the farmers are not sure about the prices of the other markets, they will pick a price uniformly at random for each type of fruit. Note that apples, and bananas may have different prices.
You want to try and figure out the prices of each of the fruits for each market. However, since you are lazy, you will ask your friend Beautiful_Times to help you. You have unlimited apples, and bananas. Each day, you will first decide how many of each type of fruit to buy and sell. Then, you will ask Beautiful_Times to go to each market to buy and sell that amount of each fruit and collect the profit that you will make. If the price of the apple at market is , then you will gain dollars for every apple you sell, and lose dollars for every apple you buy. The same goes for bananas (). The profit for that market is the total amount of money gained or lost for the types of fruit.
Unfortunately, Beautiful_Times has poor memory and he will only remember one value: whether there were more markets where you made a profit of strictly greater than dollars ( can be negative) than markets where you made a profit of strictly less than dollars.
On some days, instead of asking Beautiful_Times to go to all markets, you will ask him to compare the results of certain previous days. You will choose two days and , and he will give you one piece of information:
- Considering only the markets where you earned a profit of at least on day , and a profit of at least on day , choose two of the markets uniformly at random and output the price of the banana. If there is only one market, Beautiful_Times will output
-1
for the second value. If there are no such markets, he will output-1
twice.
However, Beautiful_Times does not allow you to choose any two days. He will only allow you to compare day with day if the result from day was that there were an equal number of markets with a profit greater than than there was with a profit less than .
Can you use this information to determine the prices of each of the fruits for all markets?
There will be test cases. You only need to output the correct answer for at least of the cases to be accepted.
Interaction
The first line for each case will be the integer , the number of markets.
Next, you must start interaction with Beautiful_Times.
Output ? A_b A_s B_b B_s P_j
to ask Beautiful_Times to buy apples, bananas, and sell apples, bananas, at each market. . If there were more markets where you made a profit of strictly greater than dollars than strictly less than dollars, then you will receive the integer 1
. If there were fewer markets, you will receive the integer -1
. If they are equal, you will receive the integer 0
.
Output C j k
to compare day and day . You may only do this if on day , you asked a question where the result was that there were an equal number of markets where the profit was greater than as there were less than . You will receive two integers x_1 x_2
, the prices of the banana at two markets chosen uniformly at random from the markets where you earned a profit of at least on day , and a profit of at least on day . If there is only one market, Beautiful_Times will output -1
for the second value. If there are no such markets, he will output -1
twice.
When you have determined the prices of each market, output !
. This should be followed by lines in the form a_i b_i
, meaning the market buys and sells apples at dollars, and bananas at dollars. The markets can be printed in any order.
You must then continue onto the next case. The interactor will not output anything to indicate the end of this case, or whether your answer is correct or not.
If at any point, you receive a -400
, this means Beautiful_Times could not parse your question/answer or the question was invalid, and you must exit your program immediately to ensure you receive WA
. Otherwise, your verdict could be undefined.
REMINDER: After each output, remember to flush. 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()
.
Note: The interactor may use up to 1 second of the time limit.
Constraints
For all subtasks:
will always be equal to . This means you only need to output the correct answer for at least cases to be accepted.
The number of markets will be between and . Each farmer will set the prices to be between and dollars. Formally, .
You must determine each market's prices in at most days. Each day, you may ask at most question. Outputting the answer does not count as a question. However, comparing 2 days or asking Beautiful_Times to go to the markets both count as a question.
Subtask 1 [5%]
Subtask 2 [10%]
Subtask 3 [10%]
Subtask 4 [25%]
Subtask 5 [50%]
No additional constraints.
Sample Interaction
Please note that the sample input does not satisfy all of the constraints for some of the subtasks. It will not appear in any of the test cases.
In this sample, . Remember that in the actual test cases.
There is market in the first test case.
Market buys and sells apples at , and bananas at .
There are markets in the first test cases.
Market buys and sells apples at , and bananas at .
Market buys and sells apples at , and bananas at .
Market buys and sells apples at , and bananas at .
>>>
denotes your output. Do not print this out.
1
>>> ? 6 3 4 9 30
-1
>>> !
>>> 3 7
3
>>> ? 1 2 5 3 -3
0
>>> ? 1 4 2 9 26
1
>>> C 1 2
4 -1
>>> !
>>> 5 4
>>> 2 3
>>> 6 1
Sample Explanation
In the first test case, Beautiful_Times collects a profit of at market on day . Since this is less than , he responds with -1
. An answer is then printed. Although it is incorrect, the judge will continue on with the next test cases.
In the second test case, Beautiful_Times collects profits of on day at markets respectively. Since there are an equal amount of markets that made a profit greater than and less than , he responds with 0
. On day , Beautiful_Times collects profits of . Since there are more markets that made a profit greater than than markets that made a profit of less than , he responds with 1
. On day , days and days are compared. This comparison is valid since on day ; Beautiful_Times responded with 0
. Since market made a profit of at least on day and on day , and no other markets fit this criteria, Beautiful_Times responds with 4 -1
. Finally, the correct answer is printed. Beautiful_Times will not respond after the last test case. Note that the markets may be printed in any order.
Sample Interactor
You are given two Python scripts to test your solution locally. You must have Python 3 installed in order to run the files. Please notes that the sample interactor may behave differently than the actual interactor.
There are 2 files: interactive_runner.py
and interactor.py
. To use the interactor, run the following command:
python3 interactive_runner.py python3 interactor.py SUBTASK_NUMBER -- CMD_LINE_SOLUTION
SUBTASK_NUMBER
is an integer between and corresponding to the subtask you would like to test.
CMD_LINE_SOLUTION
is the command required to run the solution. In C and C++, the command is ./binary_executable_name
. In Java, the command is java class_name
. In Python 3, the command is python3 file_name.py
.
The interactor will run test cases with random values of . The test cases may vary between runs. You are encouraged to test on your own, as well as modify the interactor if you wish.
Comments