Kaguya is trying to plan out a shopping trip with Kei Shirogane. As a result, she will build Kei a mall!
The mall takes the form of an
Kaguya will build shops in some empty cells. Cells that are empty or contain escalators are walkable. An empty cell is a hallway if it is reachable from both escalators via walkable cells. A shop directly adjacent to a hallway can install a window facing the hallway.
Kaguya wants to maximize the number of windows that the mall builds to maximize the amount of window shopping she does with Kei. Compute this number.
Constraints
In tests worth 1 mark,
In tests worth an additional 2 marks,
In tests worth an additional 2 marks,
In tests worth an additional 2 marks,
In tests worth an additional 2 marks,
In tests worth an additional 2 marks,
Input Specification
The first line contains two integers
Each of the next .#UD
, indicating an empty cell, pillar, up escalator, and down escalator, respectively.
Output Specification
Output the maximum number of windows that can be made in the mall.
Sample Input 1
4 5
.....
#U...
...#.
...D.
Sample Output 1
13
Sample Input 2
4 4
..#U
..#D
..#.
....
Sample Output 2
5
Sample Input 3
3 2
##
.D
U.
Sample Output 3
0
Comments