C. Peaceful Rooks
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given a n×nn×n chessboard. Rows and columns of the board are numbered from 11 to nn. Cell (x,y)(x,y) lies on the intersection of column number xx and row number yy.
Rook is a chess piece, that can in one turn move any number of cells vertically or horizontally. There are mm rooks (m<nm<n) placed on the chessboard in such a way that no pair of rooks attack each other. I.e. there are no pair of rooks that share a row or a column.
In one turn you can move one of the rooks any number of cells vertically or horizontally. Additionally, it shouldn't be attacked by any other rook after movement. What is the minimum number of moves required to place all the rooks on the main diagonal?
The main diagonal of the chessboard is all the cells (i,i)(i,i), where