Grid Game

Each cell becomes alive if it or an edge neighbor was alive, so the live region grows by repeated dilation; count live cells after K steps.

Medium6SimulationBFSMatrixImplementationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

An infinite grid is divided into unit square cells. Every cell is either alive or dead.

Every second all cells change state at the same time, by this rule.

  • Take the five cells made of CC itself and the four cells that share an edge with CC. If at least one of them is alive, then CC is alive one second later.
  • Otherwise CC is dead one second later.

Given the starting state of the grid, write a program that counts how many cells are alive after KK seconds.

Input

The first line contains the number of rows NN and the number of columns MM of the rectangular area whose starting state is given. (1N,M501 \le N, M \le 50)

Each of the next NN lines contains MM characters describing the starting state of that area. An alive cell is o and a dead cell is .. Every cell outside the area is dead at the start.

The last line contains KK. (1K15001 \le K \le 1500)

Output

Print the number of alive cells after KK seconds.

Note

Suppose the starting state is the one below and K=3K = 3.

oo
o.

After 3 seconds the grid looks like this.

...oo...
..oooo..
.oooooo.
oooooooo
ooooooo.
.ooooo..
..ooo...
...o....