Travel of Alphabets

No attempts yetTime limit2sMemory limit256 MB

Problem

Each cell of an R×CR \times C grid holds one lowercase letter. Start on any cell and make L1L-1 moves, each one onto a cell that touches the current cell on the left, above, to the right, or below. The letters of the visited cells, read in visit order, spell a word of length LL.

Two rules govern a move. You cannot leave the grid. You may step onto a cell you have already visited, including the cell you just came from. When LL is 1 there is no move, so the letter in a single cell is already a word.

Build every word this way, over every starting cell and every sequence of moves. The letters a, c, and m are forbidden. Any word that contains at least one forbidden letter is thrown away. For example, ici, ahi, and mrk are all thrown away.

Count how many words survive, and how many distinct strings appear among them. A different starting cell or a different route counts as a separate word even when it spells the same string, but the distinct count charges that string only once.

Input

The first line contains the number of rows RR, the number of columns CC, and the word length LL, separated by spaces. (0<R<110 < R < 11, 0<C<110 < C < 11, 0<L<70 < L < 7)

Each of the next RR lines holds one row of the grid: CC lowercase letters with no spaces.

Output

Print the number of words of length LL on the first line. Print how many of them are distinct on the second line.