Yum Yum
Time limit2sMemory limit1024 MB
For each rook replaced by the Coach, find the fewest moves needed to eat the most rooks while stepping only on cells outside every rook's row and column.
Problem
On an infinite chessboard there are rooks. A rook can attack any piece in the same row or the same column. Initially, no rook can attack another rook. In other words, every rook is in a different row, and every rook is in a different column.
You replace one of these rooks with a Coach Gu piece. The Coach can move to an orthogonally adjacent cell (up, down, left, or right). It cannot move to a cell that a rook attacks, meaning a cell in the same row or column as any rook.
The Coach likes delicious food. If a rook is in one of the 8 cells around the Coach (orthogonal or diagonal), the Coach can move onto that rook's cell and eat it. Eating a rook takes priority over being attacked by a rook.
The Coach tries to eat as many rooks as possible. If several ways reach the maximum, it uses the one with the fewest moves.
For each rook, suppose that rook is replaced by the Coach. Output the minimum number of moves the Coach makes to eat the maximum number of rooks.
Input
The first line contains (). Each of the next lines contains the coordinates of a rook ().
All rooks are in different rows and different columns. In other words, and whenever .
Output
Print lines. The -th line contains the minimum number of moves the Coach makes to eat the maximum number of rooks when the -th rook is replaced by the Coach.