Raspad

Sum the number of connected components of 1-cells over every contiguous band of rows in an n by m grid, with m at most 50 and n up to 100000.

Hard8Dynamic programmingDivide and conquerUnion-findMatrixNo attempts yetTime limit6sMemory limit1024 MB

Problem

A nearby meadow is divided into square fields arranged in nn rows and mm columns. The rows are numbered 11 to nn from top to bottom, and the columns are numbered 11 to mm from left to right. Some fields are grass (marked "1"), and some are underwater because of the heavy spring rain (marked "0").

Two grass fields are connected if you can get from one to the other by a series of moves, where each move goes to an adjacent grass field up, down, left, or right. A component is a maximal set of mutually connected grass fields: if a field AA is in the component KK, then every grass field adjacent to AA is also in KK.

For a meadow PP and indices aa and bb (1abn1 \le a \le b \le n), PabP_a^b is the meadow made of rows aa through bb of the original meadow PP (both row aa and row bb included). The complexity of the meadow PabP_a^b is the number of components of grass fields in it. Find the sum of the complexities of all possible meadows PabP_a^b.

Input

The first line contains the positive integers nn and mm, the dimensions of the meadow (1n1000001 \le n \le 100\,000, 1m501 \le m \le 50).

Each of the next nn lines contains a string of exactly mm characters that describes one row of the meadow. Each character is either the digit "0" or the digit "1".

Output

Print the sum of all complexities.

Hint

Explanation of the first sample: if Pab|P_a^b| denotes the complexity of the meadow PabP_a^b, then P11=2|P_1^1| = 2, P12=1|P_1^2| = 1, P13=1|P_1^3| = 1, P14=1|P_1^4| = 1, P22=1|P_2^2| = 1, P23=1|P_2^3| = 1, P24=1|P_2^4| = 1, P33=2|P_3^3| = 2, P34=2|P_3^4| = 2, P44=2|P_4^4| = 2, and the sum of these numbers is 1414.