#ABC472G. 级联网格 / Cascading Grid

级联网格 / Cascading Grid

Problem Statement

There is a grid with HH rows and WW columns. Each cell has one of the characters +, -, # written on it. Let (i,j)(i,j) denote the cell at the ii-th row from the top and the jj-th column from the left. The grid is given by HH length-WW strings S1,S2,,SHS_1, S_2 , \dots ,S_H: the jj-th character of SiS_i is written on (i,j)(i,j).

You can perform the following operation zero or more times:

  • Choose one cell that is not #. Change to # all cells that are "reachable from the chosen cell only by moving to an adjacent cell in the left, right, or down direction without passing through a cell that is #." Here, the chosen cell itself is included among the reachable cells.

Find the maximum possible value of the following value in the grid after the operations: the number of + cells minus the number of - cells.

Constraints

  • 1H,W301 \le H,W \le 30
  • SiS_i is a string of length WW consisting of +, -, #.
  • HH and WW are integers.

Input

The input is given from Standard Input in the following format:

  • HH WW
  • S1S_1
  • S2S_2
  • \vdots
  • SHS_H

Output

Output the answer.

2 3
+-+
--+
1

If you choose (2,1)(2,1), all cells in row 22 change to # (note that you cannot move upward). The remaining row 11 has two cells of + and one cell of -, so the value is 21=12-1=1, and this is the maximum.

3 3
+--
-#-
#+#
1

If you choose (1,1)(1,1), all cells except (3,2)(3, 2) become #. Note that the chosen cell (1,1)(1, 1) itself is included among the reachable cells, and that you cannot pass through a cell that is #.

5 7
++#--++
-+---+#
##++-++
--#-++-
+---#++
5