Primonimo

No attempts yetTime limit2sMemory limit512 MB

Problem

Primonimo is a game played on an n×mn \times m board. Every square holds an integer between 11 and pp, where pp is a prime. One move picks a square, and every square in the same row or the same column as the picked square grows by 11. The picked square belongs to both that row and that column, but it still grows by only 11. A square that held pp goes back to 11.

You win when every square shows pp. Given the starting board, find a sequence of moves that wins the game.

Squares are numbered from 11 to nmnm in row-major order, so the square in row ii and column jj (both counted from 1) has number (i1)m+j(i-1)m + j.

Input

The input is one test case. The first line has three integers nn, mm, pp: the number of rows nn (1n201 \le n \le 20), the number of columns mm (1m201 \le m \le 20), and a prime pp (2p972 \le p \le 97). Each of the next nn lines has mm integers between 11 and pp.

Output

If no winning sequence exists, print 1-1.

Otherwise the answer is fixed by this rule. The order of the moves does not change the result, so only the number of times each square is picked matters. Let xtx_t be the number of times square tt is picked, and consider only the count vectors with 0xtp10 \le x_t \le p-1. When several count vectors win, take the lexicographically smallest (x1,x2,,xnm)(x_1, x_2, \ldots, x_{nm}): the smallest x1x_1, then among those the smallest x2x_2, and so on.

Print k=x1++xnmk = x_1 + \cdots + x_{nm} on the first line. On the second line print the kk chosen square numbers from the smallest number up, writing number tt exactly xtx_t times. When k=0k = 0 the second line is empty. This kk is always at most pnmp \cdot n \cdot m.