A nearby meadow consists of quadratic fields organized in
rows and
columns. The rows are denoted
with numbers from
to
from top to bottom, and the columns with numbers from
to
from left to
right. Some fields are grass fields (denoted with 1
), whereas some are underwater because of the heavy
spring rainfall (denoted with 0
). Two grass fields are connected if it is possible to get from one field to
another using a series of moves where, in each step, we move to the adjacent grass field located up, down,
left or right. A component is a set of mutually connected grass fields that is maximal in the sense that, if
is a field in the component
, then all the adjacent grass fields of
are also in the component
.
For a given meadow
and indices
and
,
is a meadow consisting of rows between the
and the
row of the original meadow
(including both
and
row). The complexity of meadow
is the number of components of the grass fields located on the meadow. Determine the sum of the complexities of all possible meadows
.
Input Specification
The first line of input contains the positive integers
and
— dimensions of the meadow. Each of the
following
lines contains a string of exactly
characters that denotes one row of the meadow. Each
character of the string is either the digit 0
or the digit 1
.
Output Specification
You must output the required sum of all complexities.
Constraints
Subtask |
Score |
Constraints |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
Sample Input 1
Copy
4 4
1101
1111
1010
1011
Sample Output 1
Copy
14
Explanation for Sample Output 1
If we denote the complexity of meadow
with
then it holds
that
, and
the sum of these numbers is
.
Sample Input 2
Copy
5 7
0100010
0111110
0101001
1111011
0100100
Sample Output 2
Copy
33
Sample Input 3
Copy
4 12
011111010111
110000101001
110111101111
111101111111
Sample Output 3
Copy
28
Comments