luogu#P5230. [AHOI2013] 好方的蛇

[AHOI2013] 好方的蛇

Problem Description

One day, the cute snake was so happy that she turned herself into a square. But while transforming, she was induced, which caused some problems.

As planned, she should have become a completely black NNN*N square, but some white cells appeared in this square. Now her body unfortunately had some small reactions: define a subsnake as an all-black rectangle with at least two cells.

qwq

Now the snake wants you to help compute how many pairs of disjoint subsnakes there are. Output the answer modulo 10007.

Input Format

The first line contains an integer NN. Then follow NN lines, each a string of length NN. If a character is BB, the cell is black; if it is WW, the cell is white.

Output Format

Output one integer, the answer.

3 
BBW
BBW 
BWW 
5

Hint

1  N  10001~\leq~N~\leq~1000

Translated by ChatGPT 5