AquaMoon and Wrong Coordinate
time limit per test: 2 seconds
memory limit per test: 256 megabytes
Articles
Cirno gives AquaMoon a problem. There are people numbered from to . They are standing on a coordinate axis in points with positive integer coordinates. They are facing right (i.e. in the direction of the coordinate increase). At this moment everyone will start running with the constant speed in the direction of coordinate increasing. The initial coordinate of the -th person on the line is , and the speed of the -th person is . So the coordinate of the -th person at the moment will be .
Cirno captured the coordinates of people in consecutive integer moments from 00 to . In every moment, the coordinates of people were recorded in arbitrary order.
To make the problem more funny, Cirno modified one coordinate at the moment to a different integer.
AquaMoon wants to find the moment and the original coordinate before the modification. Actually, she is not a programmer at all. So she wasn’t able to solve it. Can you help her?
Input
This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you won’t have any interaction process. The only thing you should not forget is to flush the output buffer, after printing the answer. Otherwise, you can get an “Idleness limit exceeded” verdict. Refer to the interactive problems guide for the detailed information about flushing the output buffer.
The first line contains two integers mm and (, ) — the number of people and the number of recorded moments.
The next lines contain captured positions. -th of these lines contains integers between and (inclusive), representing positions captured by Cirno at the moment .
The input is guaranteed to be valid (i.e. only one integer was modified to a different value according to the problem statement). Also, it is guaranteed, that for all .
Hack format:
The first line should contain two integers mm and (, ) — the number of people and the number of moments.
In the second line, there should be mm integers , where &xi& is the initial coordinate of the -th person.
In the third line, there should be mm integers , where is the speed of the -th person. It should be true that for each .
In the next lines, each line should contain integers. -th line should contain mm distinct integers . The meaning of these numbers: -th integer in the input in the -th moment is the coordinate of the -th person.
In the last line, there should be three integers , , . Cirno modified the coordinate of the -th person at the moment to .
Output
Print a single line with two integers , pp — the moment that contains the modified coordinate and the original coordinate.
Example
input
1 | 5 7 |
output
1 | 4 13 |
Note
In the first test the initial coordinates of people are 9, 6, 6, 9, 9 and their speeds are 1, 2, 1, 1, 1. So, it’s easy to see, that at the moment 4 one coordinate was modified from 13 to 12.
This is the first test in the hack format:
1 | 5 7 |
Tutorial
Let’s denote for sum[t]sum[t] the sum of all coordinates at the moment , and for the sum of all squared coordinates at the moment .
If there is no error, the sum of the coordinates of all moments will be an arithmetic series, and the difference is . It’s easy to find the moment that contains the modified coordinate.
Assuming that the moment that contains the modified coordinate is found, first use three consecutive moments without the modified coordinate. Suppose it is , , . Sum of squared coordinates of moment is . Sum of squared coordinates of moment is . Sum of squared coordinates of moment is . We could easy to get . In this way, we can know the value of .
Then we can enumerate which integer was modified at the moment . We could try to update the integer back to the original coordinate, so that it can meet both and . It would be easy to get the original coordinate.
Code
1 |
|