Problems
Two players play the following game on an
Initially each cell of the grid is either empty or occupied.
Players take turns placing a stone on an empty cell, occupying the cell. Each new stone must be adjacent to the last placed stone, with the exception of the starting stone that can be placed on any empty cell. A stone is adjacent to another stone if they are located in two cells that share a side.
The game ends whenever a player cannot place a stone according to the above rules. In that case, the player who cannot place a stone loses the game, and the other player wins.
A winning starting cell is a cell such that the first player wins the game if they place their starting stone there, assuming both players play optimally. Given a description of the initial grid, you must tell how many winning starting cells it has.
Input
The first line contains two integers
Each of the next
Output
Output a single line with an integer indicating the number of winning starting cells.
Example #1
3 3
#.#
...
#.#
4
Example #2
3 3
..#
...
...
0
Example #3
1 4
...#
2