Consider a rectangular grid of size N × M. Each cell is colored black or white.
If you touch a cell C of the grid, you change the color of all the cells that belong to same-colored connected component of C, including C itself. For connected components, two cells are neighbors if they share a side.
You know the current state of the grid, but you may have touched some cells an arbitrary number of times. Calculate the number of possible initial states of the grid. As the answer may be very large, calculate it modulo 1 000 000 007.
The first line contains two integers N and M, the dimensions of the grid (1 ≤ N, M ≤ 2000).
Each of the next N lines describes one row of the grid. Each of these lines contains M characters denoting the colors of cells in the row. Each character is either "B" for black or "W" for white.
Print the number of possible initial states of the grid modulo 1 000 000 007.
2 2 WW WB
2
| Название |
|---|


