#K56527. Minimum Painted Cells
Minimum Painted Cells
Minimum Painted Cells
Given a grid with N rows and M columns, you want to paint some cells so that the painted region is contiguous and touches all four boundaries (top, bottom, left, and right) of the grid.
If the grid has only one row or one column, you must paint all the cells in that row or column. Otherwise, the optimal strategy is to paint all cells along the border. In this case, the minimum number of painted cells is given by the formula: \(2N + 2M - 4\).
Your task is to compute the minimum number of cells that need to be painted to achieve this configuration.
inputFormat
The input is given via standard input. The first line contains two space-separated integers \(N\) and \(M\) representing the number of rows and columns of the grid, respectively.
outputFormat
Output a single integer representing the minimum number of cells that need to be painted so that the painted region is contiguous and touches all four boundaries of the grid.
## sample3 3
8
</p>