#P9355. Maximum Score in Sequential Chessboard Piece Placement
Maximum Score in Sequential Chessboard Piece Placement
Maximum Score in Sequential Chessboard Piece Placement
You are given a chessboard with \(n\) rows and \(m\) columns. You need to place a piece on every cell of the board one by one in some order. When you place a piece, you earn points equal to the number of adjacent cells (up, down, left, right) that do not yet contain a piece at the time of placement. Your task is to determine the maximum total score you can obtain if you choose the optimal order for placing the pieces.
Observation: For each pair of adjacent cells there is exactly one opportunity to count that edge if the cell placed first gains a point from its empty adjacent cell. Therefore, the optimal total score is equal to the total number of edges between adjacent cells in the board. In other words, the maximum score is given by:
[ \text{score} = (n-1) \times m + n \times (m-1)]
inputFormat
The input consists of a single line containing two integers \(n\) and \(m\) which represent the number of rows and columns of the chessboard, respectively.
outputFormat
Output a single integer, the maximum total score that can be obtained by placing pieces on the chessboard optimally as described above.
sample
2 2
4