input
standard input
output
standard output
Suppose there is a h×wh×w grid consisting of empty or full cells. Let's make some definitions:
- riri is the number of consecutive full cells connected to the left side in the ii-th row (1≤i≤h1≤i≤h). In particular, ri=0ri=0 if the leftmost cell of the ii-th row is empty.
- cjcj is the number of consecutive full cells connected to the top end in the jj-th column (1≤j≤w1≤j≤w). In particular, cj=0cj=0 if the topmost cell of the jj-th column is empty.
In other words, the ii-th row starts exactly with riri full cells. Similarly, the jj-th column starts exactly with cjcj full cells.