A matrix consisting of natural numbers with rows and columns is given. Through a transformation, we can obtain another matrix of rows and columns as follows: each element at coordinates with , , in the newly obtained matrix will be equal to the xor sum of the values from the following four positions , , , in the initial matrix (if any of these positions are outside the matrix, the value at that position will be considered ).
Task
Given a matrix with rows and columns, answer queries of the form: what is the value at the first row and first column if we apply transformations to the initial matrix.
Interaction
You need to implement the following functions:
void initialize(int N, int M, int **matrix);
The function receives as parameters the dimensions of the matrix and the matrix itself. It does not need to return anything.
int query(int K);
The function receives as a parameter the value for a query, and it needs to return the answer to the query, as described in the statement.
The Interactor will read the data from the input file xortransform.in
and will display the answers to the query function in the output file xortransform.out
in the format described below.
Constraints and Restrictions
- , for any and .
- The
query
function will be called at most times during a test.
Example
xortransform.in
4 5 3
9 8 1 3 6
1 2 5 2 5
3 4 3 7 7
7 8 3 5 1
3
18
100
xortransform.out
13
8
15
Explanations
Input data format
N M Q
A0,0 A0,1 ... A0,M-1
A1,0 A1,1 ... A1,M-1
...
AN-1,0 AN-1,M-1
K1
K2
...
KQ