Jailing

아직 제출이 없습니다시간 제한10초메모리 제한512 MB

문제

Bobo has a matrix of size n×mn \times m filled with integers. It is guaranteed that all cells which contain the same value are 44-side connected.

Let's define a jailing J_xJ\_x of a connected component with value xx as minimum-area rectangle (with sides parallel to the matrix sides) that covers all cells of the component.

For each jailing B_xB\_x, Jessica would like to find the value of

s(B_x)=_B_yAxf(B_x,B_y)ys(B\_x)=\sum\_{B\_y \in A \setminus \\{x\\}} f(B\_x, B\_y) \cdot y

where AA is the set of all integers in the matrix and

f(B_x,B_y)={0 the area of intersection of B_x and B_y is 0 0B_x is completely inside B_y or vice versa 1Otherwisef(B\_x,B\_y)=\begin{cases} 0 & \text{ the area of intersection of } B\_x \text{ and } B\_y \text{ is } 0 \\\ 0 & B\_x \text{ is completely inside } B\_y \text{ or vice versa} \\\ 1 & \text{Otherwise} \end{cases}

입력

The input consists of several test cases terminated by end-of-file. For each test case:

The first line contains two integers nn and mm -- the size of the matrix.

The second line contains nmn \cdot m integers a_1,1,a_1,2,,a_1,ma\_{1,1}, a\_{1,2}, \ldots, a\_{1, m}, a_2,1,a_2,2,,a_2,ma\_{2,1}, a\_{2,2}, \ldots, a\_{2, m}, \ldots, a_n,1,a_n,2,,a_n,ma\_{n, 1}, a\_{n, 2}, \ldots, a\_{n,m}, where a_i,ja\_{i,j} is the value in the ii-th row and the jj-th column.

출력

For each test case, output an integer denoting the value of _xAs(x)x\sum\_{x \in A} s(x) \oplus x, where \oplus denotes the exclusive-or (XOR) operator.

제한

  • 1nm1061 \leq n \cdot m \leq 10^6
  • 1a_i,jnm1 \leq a\_{i,j} \leq nm
  • It is guaranteed that all cells which contain the same value are 44-side connected.
  • It is guaranteed that the sum of nmn \cdot m in all test cases does not exceed 10710^7.