Unit Placement at the Sinchon Defense Headquarters
Time limit2.4sMemory limit1024 MB
Place the most elephants on empty cells that no soldier attacks, so that no two elephants attack each other, and print one optimal layout.
- Level
Medium7 of 10
- Topics
- Graph, Matrix, Implementation
- Solved
- No attempts yet
Problem

On August 21, 2021, an unidentified organization attacked during the 2021 ICPC Sinchon Summer Algorithm Camp Contest. The Sinchon Defense Headquarters repelled the attack without any casualties and tracked down the organization's hideout.

The ICPC Sinchon Alliance decided to send countless elephants into a full assault on the hideout. Before the all-out attack, the alliance wants a stable unit formation made of elephants, soldiers, and alliance troops. There is no time to scrap the formation already built and start over. So the soldiers already placed stay where they are, and elephants go into the empty cells.

The formation is an grid. The bottom-left cell is , the top-left cell is , the bottom-right cell is , and the top-right cell is . As the figure shows, an elephant attacks the cell one step forward and the cells two steps away diagonally. A soldier attacks the cell one step up and the cells one step to the left and right. When an elephant attacks, it can hurt the soldiers and elephants on its attack cells, so no soldier or elephant can be placed on those cells. Likewise, an elephant standing on a cell attacked by a soldier can be hurt, so no elephant can be placed on such a cell.
The alliance treats elephants as its most important tactical weapon, so it wants to place as many as possible. Find the maximum number of elephants that can be placed and their positions.
Input
The first line contains and , the size of the grid, and , the number of soldiers already placed. (, )
Each of the next lines contains and , the position of a soldier. (, )
Output
Print the maximum number of elephants that can be placed. Then print their positions in the same way.
If there are several answers, print any of them.