Following Jackson Pollock and Clyfford Still, Adam decided to create some abstract art. He decided to start simple: paint a picture consisting of three stars.
Adam bought a piece of exquisite paper, which can be viewed as a grid consisting of $n$ rows and $m$ columns. Adam has specified some cells that are suitable for painting stars.
Since the paper is large, Adam needs to first cut out the part needed for the painting. It can be any sub-rectangle of the grid. Formally, for integers $x_1, x_2, y_1, y_2$, if $0 \le x_1 \le x_2 < n$ and $0 \le y_1 \le y_2 < m$, the cells with row indices in $[x_1, x_2]$ and column indices in $[y_1, y_2]$ form a sub-rectangle. These are all the possible sub-rectangles. Then, Adam needs to find three distinct cells within the sub-rectangle to paint the stars. Of course, these cells must be specified as suitable for painting stars.
Adam wants to know how many ways he can create such an artwork. Since this number can be quite large, you only need to output the result modulo $10^9+7$.
Implementation Details
You should include art.h and implement the following procedure:
int count(bool[][] v)
- $v$: A 2D array of size $n \times m$. For each $i, j$ ($0 \le i \le n-1$, $0 \le j \le m-1$), $v[i][j]=1$ if the cell at row $i$ and column $j$ is suitable for painting a star, otherwise $v[i][j]=0$.
- The procedure you implement will be called exactly once.
- You should return the number of ways to create the artwork modulo $10^9+7$: an integer in the range $[0, 10^9+6]$.
Examples
Example 1
Consider the call: count([[1,1,0],[1,0,0]])
We can only paint stars in the three available cells, and there are two different sub-rectangles that contain these three stars. Therefore, there are two different ways to create the artwork, and a correct program should return $2$.
Constraints
$1 \le n, m \le 3000$
Subtasks
- (20 points) $n, m \le 80$
- (20 points) $n, m \le 300$
- (20 points) All cells are suitable for painting stars.
- (40 points) No special restrictions.
Sample Grader
The sample grader reads the input in the following format:
- First line: $n~m$
- Next $n$ lines, each containing $m$ characters (0 or 1), describing $v$
The sample grader prints your output in the following format:
- One line, your return value