403076: GYM100989 N Mixed Dimensions
Description
Mixed Dimensions is an innovative company that is specialized in 3D printing technologies. They are planning to 3D print decorative tiles to be used in the beautiful pavements of Amman.
After printing thousands of these decorative tiles, Mixed Dimensions washed the tiles with water to make them look fresh before they are delivered. Unfortunately, water gathered inside some places in the decorations. Observing the problem, they decided to fill any cavity (hole) in the decorations so that no water gathers after a rainy day.
Given a 3D printed tile that represents a grid of size R×C, and the height in unit cubes above each point in the grid, your task is to compute the volume of printing material needed to fill the cavities (holes).
Two units3 of printing material are needed to fill this tile.
InputThe first line of input contains two integers R and C (1 ≤ R, C ≤ 500), the number of rows and columns of the base grid, respectively.
Each of the following R lines contains C integers, each integer is between 1 and 109 and represents the height in unit cubes above one of the cells.
OutputPrint the volume of the printing material needed to fill the given tile so that no water gathers after a rainy day.
ExamplesInput4 3Output
2 3 3
2 1 2
3 1 3
3 2 1
2