#C10016. Minimal Toy Moves on Diagonal
Minimal Toy Moves on Diagonal
Minimal Toy Moves on Diagonal
You are given an n x m grid. Each cell of the grid can hold a toy. Initially, the toys are placed such that every cell on the main diagonal (from the top left to the bottom right) already has a toy when n = m. However, if the grid is rectangular (n ≠ m), some cells on the main diagonal will be missing a toy.
The task is to calculate the minimal number of moves required to place at least one toy on each cell of the main diagonal. A move consists of placing one toy into any cell. It turns out that the number of required moves is given by the absolute difference between n and m, that is,
\( |n - m| \)
For example, if the grid is 3 x 3, no moves are needed since every main diagonal cell already has a toy. However, for a 1 x 4 grid, three moves are necessary.
inputFormat
The input consists of a single line containing two integers, n and m (1 ≤ n, m ≤ 109), separated by space, representing the number of rows and columns of the grid, respectively.
outputFormat
Output a single integer — the minimal number of moves required to ensure that each cell on the main diagonal contains at least one toy.
## sample3 3
0
</p>