Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/xor-yollar

XOR paths

Hard 2000 ms 256 MB 76%
Share

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.

Right-and-down paths on the grid whose XOR equals X

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

Sign in to submit a solution

Signing up is free and takes a minute.