시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB132444054.795%

문제

You have an m-by-n grid of squares that you wish to color. You may color each square either red or blue, subject to the following constraints:

  • Every square must be colored.
  • Colors of some squares are already decided (red or blue), and cannot be changed.
  • For each blue square, all squares in the rectangle from the top left of the grid to that square must also be blue.

Given these constraints, how many distinct colorings of the grid are there? The grid cannot be rotated.

입력

The first line of input consists of two space-separated integers m and n (1 ≤ m, n ≤ 30).

Each of the next m lines contains n characters, representing the grid. Character ‘B’ indicates squares that are already colored blue. Similarly, ‘R’ indicates red squares. Character ‘.’ indicates squares that are not colored yet.

출력

Print, on a single line, the number of distinct colorings possible.

예제 입력 1

3 2
..
B.
.R

예제 출력 1

6

예제 입력 2

7 6
......
.....B
.B..R.
......
...B..
.R....
...R..

예제 출력 2

3

예제 입력 3

2 2
R.
.B

예제 출력 3

0

힌트

For the first sample, the 6 ways are:

BB   BB   BR   BR   BB   BB
BB   BR   BR   BR   BR   BB
BR   BR   BR   RR   RR   RR