#P11086. Golf Ball Minimax Game on a Grid

    ID: 13143 Type: Default 1000ms 256MiB

Golf Ball Minimax Game on a Grid

Golf Ball Minimax Game on a Grid

Consider a game played on an n × m grid. For any cell (r, c) (1 ≤ r ≤ n, 1 ≤ c ≤ m), define its value as r + c and imagine that a golf ball is initially placed at that cell. Two players take turns moving the ball, with the robot (the first mover) trying to minimize the final score and the opponent trying to maximize it. In each move, the ball can only be moved either one cell to the right or one cell down. The game ends when the ball reaches the bottom‐right cell (n, m), at which point the value of that cell is added to the accumulated score.

If we denote by \(g(r, c)\) the final score when the ball starts at cell \((r, c)\) and both sides play optimally, your task is to calculate the sum

[ S = \sum_{r=1}^{n}\sum_{c=1}^{m} g(r,c). ]

Note: The robot always moves first from the starting cell. When a move is made, the new score becomes the sum of the current cell's value and the outcome from the subsequent moves. At each step, if it is the robot's turn, the move that minimizes the outcome is chosen; if it is the opponent's turn, the move that maximizes the outcome is chosen.

inputFormat

The input consists of a single line with two integers n and m (1 ≤ n, m ≤ 1000) representing the number of rows and columns of the grid, respectively. The value of each cell (r, c) is defined as r + c and is not given explicitly.

outputFormat

Output a single integer which is the sum \(S = \sum_{r=1}^{n}\sum_{c=1}^{m} g(r,c)\) computed over all starting positions assuming both players play optimally.

sample

1 1
2