#P5230. Counting Disjoint Subsnakes

    ID: 18466 Type: Default 1000ms 256MiB

Counting Disjoint Subsnakes

Counting Disjoint Subsnakes

One day, a cute snake transformed into a square! However, during the change something went awry so that some cells turned white. According to the original plan, the snake should have become an N×NN\times N fully black square, but some cells are white. A subsnake is defined as an all-black subrectangle with at least two cells. Your task is to count the number of pairs of non-intersecting subsnakes and output the answer modulo 10007.

qwq

inputFormat

The first line contains an integer NN.
Each of the next NN lines contains a string of NN characters. Each character is either '1' (representing a black cell) or '0' (representing a white cell), which together describe the grid.

outputFormat

Output one integer: the number of pairs of disjoint subsnakes modulo 10007.

sample

2
11
11
2