An -by- grid is good if every square is colored either red or blue, and if the square in row , column is blue, then every square in row , column that satisfies and must also be colored blue.
You are given a grid that is partially colored in. Count the number of ways to color the remaining squares of the grid such that the grid is good.
Constraints
At least one square in the grid will be .
.
Input Specification
The first line contains two space-separated integers and .
Each of the next lines contains characters representing the grid. Each character is either R
to represent a red square, B
to represent a blue square, or .
to indicate a square that has not been colored.
Output Specification
Print, on a single line, the number of distinct colorings possible.
Sample Input 1
3 2
..
B.
.R
Sample Output 1
6
Sample Input 2
7 6
......
.....B
.B..R.
......
...B..
.R....
...R..
Sample Output 2
3
Sample Input 3
2 2
R.
.B
Sample Output 3
0
Comments