0%

AquaMoon and Wrong Coordinate

AquaMoon and Wrong Coordinate

time limit per test: 2 seconds

memory limit per test: 256 megabytes

Articles

Cirno gives AquaMoon a problem. There are mm people numbered from 00 to m1m−1. 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 ii-th person on the line is xixi, and the speed of the ii-th person is vivi. So the coordinate of the ii-th person at the moment tt will be xi+tvixi+t⋅vi.

Cirno captured the coordinates of mm people in kk consecutive integer moments from 00 to k1k−1. In every moment, the coordinates of mm people were recorded in arbitrary order.

To make the problem more funny, Cirno modified one coordinate at the moment yy (0<y<k1)(0<y<k−1) to a different integer.

AquaMoon wants to find the moment yy and the original coordinate pp 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 kk (5m10005≤m≤1000, 7k10007≤k≤1000) — the number of people and the number of recorded moments.

The next kk lines contain captured positions. ii-th of these lines contains mm integers between 11 and 10610^6 (inclusive), representing positions captured by Cirno at the moment i1i−1.

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 1vi10001≤vi≤1000 for all 1im1≤i≤m.

Hack format:

The first line should contain two integers mm and kk (5m10005≤m≤1000, 7k10007≤k≤1000) — the number of people and the number of moments.

In the second line, there should be mm integers x0,x1,,xm1(1xi106)x_0,x_1,…,x_{m−1} (1≤xi≤10^6), where &xi& is the initial coordinate of the ii-th person.

In the third line, there should be mm integers v0,v1,,vm1(1vi1000)v0,v1,…,v_{m−1}(1≤vi≤1000), where vivi is the speed of the ii-th person. It should be true that xi+(k1)vi106xi+(k−1)vi≤10^6 for each 0i<m0≤i<m.

In the next kk lines, each line should contain mm integers. ii-th line should contain mm distinct integers p0,p1,,pm1(0pj<m)p0,p1,…,p_{m−1}(0≤pj<m). The meaning of these numbers: jj-th integer in the input in the ii-th moment is the coordinate of the pjpj-th person.

In the last line, there should be three integers yy, ii, cc. Cirno modified the coordinate of the ii-th person at the moment yy to cc (1yk2,0im1,1c106,cxi+yvi)(1≤y≤k−2, 0≤i≤m−1, 1≤c≤10^6, c≠xi+y⋅vi).

Output

Print a single line with two integers yy, pp — the moment that contains the modified coordinate and the original coordinate.

Example

input

1
2
3
4
5
6
7
8
5 7
6 9 9 6 9
10 7 10 8 10
11 11 11 10 8
12 12 12 12 9
14 13 12 10 13
11 14 16 14 14
12 15 18 15 15

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
2
3
4
5
6
7
8
9
10
11
5 7
9 6 6 9 9
1 2 1 1 1
2 3 4 1 0
0 2 3 1 4
4 3 0 1 2
1 3 4 0 2
1 4 0 2 3
2 4 1 3 0
2 4 1 3 0
4 0 12

Tutorial

Let’s denote for sum[t]sum[t] the sum of all coordinates at the moment tt, and for sum2[t]sum2[t] the sum of all squared coordinates at the moment tt.

If there is no error, the sum of the coordinates of all moments will be an arithmetic series, and the difference is i=1mvi\sum^m_{i=1}v_i. 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 tt, t+1t+1, t+2t+2. Sum of squared coordinates of moment tt is sum2[t]=i=1m(xi+tvi)2sum2[t]=\sum^m_{i=1}(xi+t∗vi)2. Sum of squared coordinates of moment t+1t+1 is sum2[t+1]=i=1m(xi+(t+1)vi)2sum2[t+1]=\sum_{i=1}^{m}(xi+(t+1)∗vi)^2. Sum of squared coordinates of moment t+2t+2 is sum2[t+2]=i=1n(xi+(t+2)vi)2sum2[t+2]=\sum^{n}_{i=1}(xi+(t+2)∗vi)^2. We could easy to get sum2[t]+sum2[t+2]2×sum2[t+1]=2×i=1mvi2sum2[t]+sum2[t+2]−2×sum2[t+1]=2×\sum_{i=1}^{m}v^2_i. In this way, we can know the value of 2×i=1mvi22×∑^{m}_{i=1}v^2_i.

Then we can enumerate which integer was modified at the moment yy. We could try to update the integer back to the original coordinate, so that it can meet both sum[y1]+sum[y+1]=2×sum[y]sum[y−1]+sum[y+1]=2×sum[y] and sum2[y1]+sum2[y+1]2×sum2[y]=2×i=1mvi2sum2[y−1]+sum2[y+1]−2×sum2[y]=2×\sum^m_{i=1}v^2_i. It would be easy to get the original coordinate.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e6+1;
long long a[1001][1001], sum[1001], sum2[1001];

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
while(T --) {
int m, k;
cin >> m >> k;
for(int i = 0; i < k; ++ i) {
for(int j = 1; j <= m; ++ j) {
cin >> a[i][j];
sum[i] += a[i][j];
sum2[i] += a[i][j] * a[i][j];
}
}
int cnt = 0, id = -1, val = 0, v = 0;
for(int i = 2; i < k; ++ i) {
if ((sum[1] - sum[0]) * i != sum[i] - sum[0]) {
cnt ++;
id = i;
val = (sum[1] - sum[0]) * i + sum[0] - sum[i];
}
}
if (cnt > 1) {
if ((sum[2] - sum[0]) * 3 == (sum[3] - sum[0]) * 2) {
id = 1;
val = (sum[3] - sum[2]) + sum[0] - sum[1];
}
else {
id = 0;
val = sum[1] - (sum[2] - sum[1]) - sum[0];
}
}
if (id >= 3) v = sum2[2] + sum2[0] - 2*sum2[1];
else v = sum2[5] + sum2[3] - 2*sum2[4];
for(int i = 1; i <= m; ++ i) {
if (id + 2 > k-1) {
int va = a[id][i] + val;
if (sum2[id] - a[id][i]*a[id][i] + va*va + sum2[id-2] - 2*sum2[id-1] == v) {
cout << id << " " << va << "\n";
}
}
else {
int va = a[id][i] + val;
if (sum2[id] - a[id][i] * a[id][i] + va*va + sum2[id+2] - 2*sum2[id+1] == v) {
cout << id << " " << va << "\n";
break;
}
}
}
}
return 0;
}
-------------本文结束感谢您的阅读-------------