ALGOR Opening Contest: Round #1
Problem G · 300 points ·
ICPC rules
~/algor $ cat contests/round-1/G
G. XOR paths
2000 ms
256 MB
An $N * M$ grid is given: cell $(i, j)$ holds a non-negative integer $C_{i, j}$. A robot goes from cell $(1, 1)$ to cell $(N, M)$, and at every step it moves only right — to $(i, j + 1)$ — or down — to $(i + 1, j)$. A path is lucky if the bitwise XOR ($\oplus$) of the numbers of all cells on the path (including the first and the last) equals $X$. Find the number of different lucky paths.
Input
The first line contains three integers: $N$, $M$ and $X$. Each of the next $N$ lines contains $M$ integers $C_{i, j}$.
Output
One integer — the number of lucky paths.
Note
$1 \le N, M \le 20$
$N + M \le 22$
$0 \le X \le 10^{9}$
$0 \le C_{i, j} \le 10^{9}$
Examples
Input #1
3 3 11 2 1 5 7 10 0 12 6 4
Output #1
3
Input #2
1 1 5 5
Output #2
1