문제
Farmer John's pasture can be regarded as a large 2D grid of square "cells" (picture a huge chessboard) labeled by the ordered pairs
A nonempty subset of grid cells is called "balanced" if the following conditions hold:
All cells in the subset contain grass.
The subset is 4-connected. In other words, there exists a path from any cell in the subset to any other cell in the subset such that every two consecutive cells of the path are horizontally or vertically adjacent.
If cells
(x1,y) and(x2,y) (x1≤x2 ) are part of the subset, then all cells(x,y) withx1≤x≤x2 are also part of the subset.If cells
(x,y1) and(x,y2) (y1≤y2 ) are part of the subset, then all cells(x,y) withy1≤y≤y2 are also part of the subset.
Count the number of balanced subsets modulo
입력
The first line contains
The next
출력
The number of balanced subsets modulo
예제1
2
GG
GG
13
For this test case, all 4-connected subsets are balanced.
G. .G .. .. GG .G .. G. GG .G G. GG GG
.., .., G., .G, .., .G, GG, G., G., GG, GG, .G, GG
예제2
4
GGGG
GGGG
GG.G
GGGG
642
Here is an example of a subset that satisfies the second condition (it is 4-connected) but does not satisfy the third condition:
GG..
.G..
GG..
....